summaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java
blob: d9449d027a5a4e4ac839c7913cf28b305e0a78df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.commons.math.estimation;

import java.util.ArrayList;
import java.util.List;

/**
 * Simple implementation of the {@link EstimationProblem
 * EstimationProblem} interface for boilerplate data handling.
 * <p>This class <em>only</em> handles parameters and measurements
 * storage and unbound parameters filtering. It does not compute
 * anything by itself. It should either be used with measurements
 * implementation that are smart enough to know about the
 * various parameters in order to compute the partial derivatives
 * appropriately. Since the problem-specific logic is mainly related to
 * the various measurements models, the simplest way to use this class
 * is by extending it and using one internal class extending
 * {@link WeightedMeasurement WeightedMeasurement} for each measurement
 * type. The instances of the internal classes would have access to the
 * various parameters and their current estimate.</p>

 * @version $Revision: 811827 $ $Date: 2009-09-06 17:32:50 +0200 (dim. 06 sept. 2009) $
 * @since 1.2
 * @deprecated as of 2.0, everything in package org.apache.commons.math.estimation has
 * been deprecated and replaced by package org.apache.commons.math.optimization.general

 */
@Deprecated
public class SimpleEstimationProblem implements EstimationProblem {

    /** Estimated parameters. */
    private final List<EstimatedParameter> parameters;

    /** Measurements. */
    private final List<WeightedMeasurement> measurements;

    /**
     * Build an empty instance without parameters nor measurements.
     */
    public SimpleEstimationProblem() {
        parameters   = new ArrayList<EstimatedParameter>();
        measurements = new ArrayList<WeightedMeasurement>();
    }

    /**
     * Get all the parameters of the problem.
     * @return parameters
     */
    public EstimatedParameter[] getAllParameters() {
        return parameters.toArray(new EstimatedParameter[parameters.size()]);
    }

    /**
     * Get the unbound parameters of the problem.
     * @return unbound parameters
     */
    public EstimatedParameter[] getUnboundParameters() {

        // filter the unbound parameters
        List<EstimatedParameter> unbound = new ArrayList<EstimatedParameter>(parameters.size());
        for (EstimatedParameter p : parameters) {
            if (! p.isBound()) {
                unbound.add(p);
            }
        }

        // convert to an array
        return unbound.toArray(new EstimatedParameter[unbound.size()]);

    }

    /**
     * Get the measurements of an estimation problem.
     * @return measurements
     */
    public WeightedMeasurement[] getMeasurements() {
        return measurements.toArray(new WeightedMeasurement[measurements.size()]);
    }

    /** Add a parameter to the problem.
     * @param p parameter to add
     */
    protected void addParameter(EstimatedParameter p) {
        parameters.add(p);
    }

    /**
     * Add a new measurement to the set.
     * @param m measurement to add
     */
    protected void addMeasurement(WeightedMeasurement m) {
        measurements.add(m);
    }

}