View Javadoc

1   /*
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
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
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.
16   */
17  
18  package org.apache.commons.math.estimation;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  /**
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>
37  
38   * @version $Revision: 762116 $ $Date: 2009-04-05 12:48:53 -0400 (Sun, 05 Apr 2009) $
39   * @since 1.2
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
42  
43   */
44  @Deprecated
45  public class SimpleEstimationProblem implements EstimationProblem {
46  
47      /**
48       * Build an empty instance without parameters nor measurements.
49       */
50      public SimpleEstimationProblem() {
51          parameters   = new ArrayList<EstimatedParameter>();
52          measurements = new ArrayList<WeightedMeasurement>();
53      }
54  
55      /** 
56       * Get all the parameters of the problem.
57       * @return parameters
58       */
59      public EstimatedParameter[] getAllParameters() {
60          return parameters.toArray(new EstimatedParameter[parameters.size()]);
61      }
62  
63      /** 
64       * Get the unbound parameters of the problem.
65       * @return unbound parameters
66       */
67      public EstimatedParameter[] getUnboundParameters() {
68  
69          // filter the unbound parameters
70          List<EstimatedParameter> unbound = new ArrayList<EstimatedParameter>(parameters.size());
71          for (EstimatedParameter p : parameters) {
72              if (! p.isBound()) {
73                  unbound.add(p);
74              }
75          }
76  
77          // convert to an array
78          return unbound.toArray(new EstimatedParameter[unbound.size()]);
79          
80      }
81  
82      /** 
83       * Get the measurements of an estimation problem.
84       * @return measurements
85       */
86      public WeightedMeasurement[] getMeasurements() {
87          return measurements.toArray(new WeightedMeasurement[measurements.size()]);
88      }
89  
90      /** Add a parameter to the problem.
91       * @param p parameter to add
92       */
93      protected void addParameter(EstimatedParameter p) {
94          parameters.add(p);
95      }
96  
97      /**
98       * Add a new measurement to the set.
99       * @param m measurement to add
100      */
101     protected void addMeasurement(WeightedMeasurement m) {
102         measurements.add(m);
103     }
104 
105     /** Estimated parameters. */
106     private final List<EstimatedParameter> parameters;
107 
108     /** Measurements. */
109     private final List<WeightedMeasurement> measurements;
110 
111 }