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.List;
24
* Simple implementation of the {@link EstimationProblem
25
* EstimationProblem} interface for boilerplate data handling.
26
* <p>This class <em>only</em> handles parameters and measurements
27
* storage and unbound parameters filtering. It does not compute
28
* anything by itself. It should either be used with measurements
29
* implementation that are smart enough to know about the
30
* various parameters in order to compute the partial derivatives
31
* appropriately. Since the problem-specific logic is mainly related to
32
* the various measurements models, the simplest way to use this class
33
* is by extending it and using one internal class extending
34
* {@link WeightedMeasurement WeightedMeasurement} for each measurement
35
* type. The instances of the internal classes would have access to the
36
* various parameters and their current estimate.</p>
38
* @version $Revision: 762116 $ $Date: 2009-04-05 12:48:53 -0400 (Sun, 05 Apr 2009) $
40
* @deprecated as of 2.0, everything in package org.apache.commons.math.estimation has
41
* been deprecated and replaced by package org.apache.commons.math.optimization.general
45
public class SimpleEstimationProblem implements EstimationProblem {
48
* Build an empty instance without parameters nor measurements.
50
public SimpleEstimationProblem() {
51
parameters = new ArrayList<EstimatedParameter>();
52
measurements = new ArrayList<WeightedMeasurement>();
56
* Get all the parameters of the problem.
59
public EstimatedParameter[] getAllParameters() {
60
return parameters.toArray(new EstimatedParameter[parameters.size()]);
64
* Get the unbound parameters of the problem.
65
* @return unbound parameters
67
public EstimatedParameter[] getUnboundParameters() {
69
// filter the unbound parameters
70
List<EstimatedParameter> unbound = new ArrayList<EstimatedParameter>(parameters.size());
71
for (EstimatedParameter p : parameters) {
77
// convert to an array
78
return unbound.toArray(new EstimatedParameter[unbound.size()]);
83
* Get the measurements of an estimation problem.
84
* @return measurements
86
public WeightedMeasurement[] getMeasurements() {
87
return measurements.toArray(new WeightedMeasurement[measurements.size()]);
90
/** Add a parameter to the problem.
91
* @param p parameter to add
93
protected void addParameter(EstimatedParameter p) {
98
* Add a new measurement to the set.
99
* @param m measurement to add
101
protected void addMeasurement(WeightedMeasurement m) {
105
/** Estimated parameters. */
106
private final List<EstimatedParameter> parameters;
109
private final List<WeightedMeasurement> measurements;