001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.commons.math.estimation;
019
020 import java.util.ArrayList;
021 import java.util.List;
022
023 /**
024 * Simple implementation of the {@link EstimationProblem
025 * EstimationProblem} interface for boilerplate data handling.
026 * <p>This class <em>only</em> handles parameters and measurements
027 * storage and unbound parameters filtering. It does not compute
028 * anything by itself. It should either be used with measurements
029 * implementation that are smart enough to know about the
030 * various parameters in order to compute the partial derivatives
031 * appropriately. Since the problem-specific logic is mainly related to
032 * the various measurements models, the simplest way to use this class
033 * is by extending it and using one internal class extending
034 * {@link WeightedMeasurement WeightedMeasurement} for each measurement
035 * type. The instances of the internal classes would have access to the
036 * various parameters and their current estimate.</p>
037
038 * @version $Revision: 762116 $ $Date: 2009-04-05 12:48:53 -0400 (Sun, 05 Apr 2009) $
039 * @since 1.2
040 * @deprecated as of 2.0, everything in package org.apache.commons.math.estimation has
041 * been deprecated and replaced by package org.apache.commons.math.optimization.general
042
043 */
044 @Deprecated
045 public class SimpleEstimationProblem implements EstimationProblem {
046
047 /**
048 * Build an empty instance without parameters nor measurements.
049 */
050 public SimpleEstimationProblem() {
051 parameters = new ArrayList<EstimatedParameter>();
052 measurements = new ArrayList<WeightedMeasurement>();
053 }
054
055 /**
056 * Get all the parameters of the problem.
057 * @return parameters
058 */
059 public EstimatedParameter[] getAllParameters() {
060 return parameters.toArray(new EstimatedParameter[parameters.size()]);
061 }
062
063 /**
064 * Get the unbound parameters of the problem.
065 * @return unbound parameters
066 */
067 public EstimatedParameter[] getUnboundParameters() {
068
069 // filter the unbound parameters
070 List<EstimatedParameter> unbound = new ArrayList<EstimatedParameter>(parameters.size());
071 for (EstimatedParameter p : parameters) {
072 if (! p.isBound()) {
073 unbound.add(p);
074 }
075 }
076
077 // convert to an array
078 return unbound.toArray(new EstimatedParameter[unbound.size()]);
079
080 }
081
082 /**
083 * Get the measurements of an estimation problem.
084 * @return measurements
085 */
086 public WeightedMeasurement[] getMeasurements() {
087 return measurements.toArray(new WeightedMeasurement[measurements.size()]);
088 }
089
090 /** Add a parameter to the problem.
091 * @param p parameter to add
092 */
093 protected void addParameter(EstimatedParameter p) {
094 parameters.add(p);
095 }
096
097 /**
098 * Add a new measurement to the set.
099 * @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 }