1dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/* 2dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Licensed to the Apache Software Foundation (ASF) under one or more 3dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * contributor license agreements. See the NOTICE file distributed with 4dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * this work for additional information regarding copyright ownership. 5dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * The ASF licenses this file to You under the Apache License, Version 2.0 6dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * (the "License"); you may not use this file except in compliance with 7dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the License. You may obtain a copy of the License at 8dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 9dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * http://www.apache.org/licenses/LICENSE-2.0 10dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * 11dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Unless required by applicable law or agreed to in writing, software 12dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * distributed under the License is distributed on an "AS IS" BASIS, 13dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * See the License for the specific language governing permissions and 15dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * limitations under the License. 16dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 17dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 18dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpackage org.apache.commons.math.estimation; 19dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 20dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport java.util.ArrayList; 21dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondimport java.util.List; 22dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 23dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond/** 24dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Simple implementation of the {@link EstimationProblem 25dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * EstimationProblem} interface for boilerplate data handling. 26dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * <p>This class <em>only</em> handles parameters and measurements 27dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * storage and unbound parameters filtering. It does not compute 28dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * anything by itself. It should either be used with measurements 29dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * implementation that are smart enough to know about the 30dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * various parameters in order to compute the partial derivatives 31dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * appropriately. Since the problem-specific logic is mainly related to 32dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * the various measurements models, the simplest way to use this class 33dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * is by extending it and using one internal class extending 34dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * {@link WeightedMeasurement WeightedMeasurement} for each measurement 35dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * type. The instances of the internal classes would have access to the 36dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * various parameters and their current estimate.</p> 37dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 38dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @version $Revision: 811827 $ $Date: 2009-09-06 17:32:50 +0200 (dim. 06 sept. 2009) $ 39dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @since 1.2 40dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @deprecated as of 2.0, everything in package org.apache.commons.math.estimation has 41dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * been deprecated and replaced by package org.apache.commons.math.optimization.general 42dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 43dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 44dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond@Deprecated 45dee0849a9704d532af0b550146cbafbaa6ee1d19Raymondpublic class SimpleEstimationProblem implements EstimationProblem { 46dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 47dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** Estimated parameters. */ 48dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond private final List<EstimatedParameter> parameters; 49dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 50dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** Measurements. */ 51dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond private final List<WeightedMeasurement> measurements; 52dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 53dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 54dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Build an empty instance without parameters nor measurements. 55dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 56dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public SimpleEstimationProblem() { 57dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond parameters = new ArrayList<EstimatedParameter>(); 58dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond measurements = new ArrayList<WeightedMeasurement>(); 59dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 60dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 61dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 62dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Get all the parameters of the problem. 63dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return parameters 64dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 65dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public EstimatedParameter[] getAllParameters() { 66dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond return parameters.toArray(new EstimatedParameter[parameters.size()]); 67dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 68dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 69dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 70dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Get the unbound parameters of the problem. 71dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return unbound parameters 72dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 73dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public EstimatedParameter[] getUnboundParameters() { 74dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 75dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond // filter the unbound parameters 76dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond List<EstimatedParameter> unbound = new ArrayList<EstimatedParameter>(parameters.size()); 77dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond for (EstimatedParameter p : parameters) { 78dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond if (! p.isBound()) { 79dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond unbound.add(p); 80dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 81dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 82dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 83dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond // convert to an array 84dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond return unbound.toArray(new EstimatedParameter[unbound.size()]); 85dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 86dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 87dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 88dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 89dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Get the measurements of an estimation problem. 90dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @return measurements 91dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 92dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond public WeightedMeasurement[] getMeasurements() { 93dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond return measurements.toArray(new WeightedMeasurement[measurements.size()]); 94dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 95dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 96dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** Add a parameter to the problem. 97dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param p parameter to add 98dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 99dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond protected void addParameter(EstimatedParameter p) { 100dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond parameters.add(p); 101dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 102dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 103dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond /** 104dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * Add a new measurement to the set. 105dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond * @param m measurement to add 106dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond */ 107dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond protected void addMeasurement(WeightedMeasurement m) { 108dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond measurements.add(m); 109dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond } 110dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond 111dee0849a9704d532af0b550146cbafbaa6ee1d19Raymond} 112