Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 82586 invoked from network); 27 Dec 2009 17:34:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Dec 2009 17:34:07 -0000 Received: (qmail 3418 invoked by uid 500); 27 Dec 2009 17:34:06 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 3301 invoked by uid 500); 27 Dec 2009 17:34:05 -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 3292 invoked by uid 99); 27 Dec 2009 17:34:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Dec 2009 17:34:05 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 Dec 2009 17:33:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 48D3823889D5; Sun, 27 Dec 2009 17:33:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r894083 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java Date: Sun, 27 Dec 2009 17:33:38 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091227173338.48D3823889D5@eris.apache.org> Author: luc Date: Sun Dec 27 17:33:37 2009 New Revision: 894083 URL: http://svn.apache.org/viewvc?rev=894083&view=rev Log: added tests showing that issues MATH-303 and MATH-304 are both invalid. Jira: MATH-303, MATH-304 Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java (with props) Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java?rev=894083&view=auto ============================================================================== --- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java (added) +++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java Sun Dec 27 17:33:37 2009 @@ -0,0 +1,91 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.commons.math.optimization.fitting; + +import org.apache.commons.math.FunctionEvaluationException; +import org.apache.commons.math.optimization.OptimizationException; +import org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer; +import org.junit.Assert; +import org.junit.Test; + +public class CurveFitterTest { + + @Test + public void testMath303() + throws OptimizationException, FunctionEvaluationException { + + LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(); + CurveFitter fitter = new CurveFitter(optimizer); + fitter.addObservedPoint(2.805d, 0.6934785852953367d); + fitter.addObservedPoint(2.74333333333333d, 0.6306772025518496d); + fitter.addObservedPoint(1.655d, 0.9474675497289684); + fitter.addObservedPoint(1.725d, 0.9013594835804194d); + + ParametricRealFunction sif = new SimpleInverseFunction(); + + double[] initialguess1 = new double[1]; + initialguess1[0] = 1.0d; + Assert.assertEquals(1, fitter.fit(sif, initialguess1).length); + + double[] initialguess2 = new double[2]; + initialguess2[0] = 1.0d; + initialguess2[1] = .5d; + Assert.assertEquals(2, fitter.fit(sif, initialguess2).length); + + } + + @Test + public void testMath304() + throws OptimizationException, FunctionEvaluationException { + + LevenbergMarquardtOptimizer optimizer = new LevenbergMarquardtOptimizer(); + CurveFitter fitter = new CurveFitter(optimizer); + fitter.addObservedPoint(2.805d, 0.6934785852953367d); + fitter.addObservedPoint(2.74333333333333d, 0.6306772025518496d); + fitter.addObservedPoint(1.655d, 0.9474675497289684); + fitter.addObservedPoint(1.725d, 0.9013594835804194d); + + ParametricRealFunction sif = new SimpleInverseFunction(); + + double[] initialguess1 = new double[1]; + initialguess1[0] = 1.0d; + Assert.assertEquals(1.6357215104109237, fitter.fit(sif, initialguess1)[0], 1.0e-14); + + double[] initialguess2 = new double[1]; + initialguess2[0] = 10.0d; + Assert.assertEquals(1.6357215104109237, fitter.fit(sif, initialguess1)[0], 1.0e-14); + + } + + private static class SimpleInverseFunction implements ParametricRealFunction { + + public double value(double x, double[] parameters) { + return parameters[0] / x + (parameters.length < 2 ? 0 : parameters[1]); + } + + public double[] gradient(double x, double[] doubles) { + double[] gradientVector = new double[doubles.length]; + gradientVector[0] = 1 / x; + if (doubles.length >= 2) { + gradientVector[1] = 1; + } + return gradientVector; + } + } + +} Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/fitting/CurveFitterTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision