2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.commons.math.estimation;
20
import java.util.ArrayList;
21
import java.util.Iterator;
22
import java.util.List;
25
* Simple implementation of the {@link EstimationProblem
26
* EstimationProblem} interface for boilerplate data handling.
27
* <p>This class <em>only</em> handles parameters and measurements
28
* storage and unbound parameters filtering. It does not compute
29
* anything by itself. It should either be used with measurements
30
* implementation that are smart enough to know about the
31
* various parameters in order to compute the partial derivatives
32
* appropriately. Since the problem-specific logic is mainly related to
33
* the various measurements models, the simplest way to use this class
34
* is by extending it and using one internal class extending
35
* {@link WeightedMeasurement WeightedMeasurement} for each measurement
36
* type. The instances of the internal classes would have access to the
37
* various parameters and their current estimate.</p>
39
* @version $Revision: 627989 $ $Date: 2008-02-15 03:04:02 -0700 (Fri, 15 Feb 2008) $
43
public class SimpleEstimationProblem implements EstimationProblem {
46
* Build an empty instance without parameters nor measurements.
48
public SimpleEstimationProblem() {
49
parameters = new ArrayList();
50
measurements = new ArrayList();
54
* Get all the parameters of the problem.
57
public EstimatedParameter[] getAllParameters() {
58
return (EstimatedParameter[]) parameters.toArray(new EstimatedParameter[parameters.size()]);
62
* Get the unbound parameters of the problem.
63
* @return unbound parameters
65
public EstimatedParameter[] getUnboundParameters() {
67
// filter the unbound parameters
68
List unbound = new ArrayList(parameters.size());
69
for (Iterator iterator = parameters.iterator(); iterator.hasNext();) {
70
EstimatedParameter p = (EstimatedParameter) iterator.next();
76
// convert to an array
77
return (EstimatedParameter[]) unbound.toArray(new EstimatedParameter[unbound.size()]);
82
* Get the measurements of an estimation problem.
83
* @return measurements
85
public WeightedMeasurement[] getMeasurements() {
86
return (WeightedMeasurement[]) measurements.toArray(new WeightedMeasurement[measurements.size()]);
89
/** Add a parameter to the problem.
90
* @param p parameter to add
92
protected void addParameter(EstimatedParameter p) {
97
* Add a new measurement to the set.
98
* @param m measurement to add
100
protected void addMeasurement(WeightedMeasurement m) {
104
/** Estimated parameters. */
105
private final List parameters;
108
private final List measurements;