Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 63958 invoked from network); 17 Aug 2007 16:27:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 17 Aug 2007 16:27:22 -0000 Received: (qmail 52829 invoked by uid 500); 17 Aug 2007 16:27:17 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 52757 invoked by uid 500); 17 Aug 2007 16:27:16 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 52748 invoked by uid 99); 17 Aug 2007 16:27:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Aug 2007 09:27:16 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Aug 2007 16:27:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 62D861A981A; Fri, 17 Aug 2007 09:26:55 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r567080 - /commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java Date: Fri, 17 Aug 2007 16:26:54 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070817162655.62D861A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: luc Date: Fri Aug 17 09:26:45 2007 New Revision: 567080 URL: http://svn.apache.org/viewvc?view=rev&rev=567080 Log: [MATH-165] basic implementation of a SimpleEstimationProblem Added: commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java (with props) Added: commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java?view=auto&rev=567080 ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java (added) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java Fri Aug 17 09:26:45 2007 @@ -0,0 +1,72 @@ +package org.apache.commons.math.estimation; + +import java.util.ArrayList; +import java.util.Iterator; + +/** + * Simple implementation of the {@link EstimationProblem + * EstimationProblem} interface for boilerplate data handling. + *

This class only 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.

+ */ +public class SimpleEstimationProblem implements EstimationProblem { + + /** + * Build an empty instance without parameters nor measurements. + */ + public SimpleEstimationProblem() { + parameters = new ArrayList(); + } + + public EstimatedParameter[] getAllParameters() { + return (EstimatedParameter[]) parameters.toArray(new EstimatedParameter[parameters.size()]); + } + + public EstimatedParameter[] getUnboundParameters() { + + // filter the unbound parameters + ArrayList unbound = new ArrayList(parameters.size()); + for (Iterator iterator = parameters.iterator(); iterator.hasNext();) { + EstimatedParameter p = (EstimatedParameter) iterator.next(); + if (! p.isBound()) { + unbound.add(p); + } + } + + // convert to an array + return (EstimatedParameter[]) unbound.toArray(new EstimatedParameter[unbound.size()]); + + } + + public WeightedMeasurement[] getMeasurements() { + return (WeightedMeasurement[]) measurements.toArray(new WeightedMeasurement[measurements.size()]); + } + + 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); + } + + /** Estimated parameters. */ + private ArrayList parameters; + + /** Measurements. */ + private ArrayList measurements; + +} Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java ------------------------------------------------------------------------------ svn:eol-style = native