    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: 811827 $ $Date: 2009-09-06 17:32:50 +0200 (dim. 06 sept. 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        /** Estimated parameters. */
    048        private final List<EstimatedParameter> parameters;
    049
    050        /** Measurements. */
    051        private final List<WeightedMeasurement> measurements;
    052
    053        /**
    054         * Build an empty instance without parameters nor measurements.
    055         */
    056        public SimpleEstimationProblem() {
    057            parameters   = new ArrayList<EstimatedParameter>();
    058            measurements = new ArrayList<WeightedMeasurement>();
    059        }
    060
    061        /**
    062         * Get all the parameters of the problem.
    063         * @return parameters
    064         */
    065        public EstimatedParameter[] getAllParameters() {
    066            return parameters.toArray(new EstimatedParameter[parameters.size()]);
    067        }
    068
    069        /**
    070         * Get the unbound parameters of the problem.
    071         * @return unbound parameters
    072         */
    073        public EstimatedParameter[] getUnboundParameters() {
    074
    075            // filter the unbound parameters
    076            List<EstimatedParameter> unbound = new ArrayList<EstimatedParameter>(parameters.size());
    077            for (EstimatedParameter p : parameters) {
    078                if (! p.isBound()) {
    079                    unbound.add(p);
    080                }
    081            }
    082
    083            // convert to an array
    084            return unbound.toArray(new EstimatedParameter[unbound.size()]);
    085
    086        }
    087
    088        /**
    089         * Get the measurements of an estimation problem.
    090         * @return measurements
    091         */
    092        public WeightedMeasurement[] getMeasurements() {
    093            return measurements.toArray(new WeightedMeasurement[measurements.size()]);
    094        }
    095
    096        /** Add a parameter to the problem.
    097         * @param p parameter to add
    098         */
    099        protected void addParameter(EstimatedParameter p) {
    100            parameters.add(p);
    101        }
    102
    103        /**
    104         * Add a new measurement to the set.
    105         * @param m measurement to add
    106         */
    107        protected void addMeasurement(WeightedMeasurement m) {
    108            measurements.add(m);
    109        }
    110
    111    }