Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BAD57D170 for ; Wed, 8 Aug 2012 12:24:36 +0000 (UTC) Received: (qmail 70717 invoked by uid 500); 8 Aug 2012 12:24:35 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 70347 invoked by uid 500); 8 Aug 2012 12:24:33 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 70332 invoked by uid 99); 8 Aug 2012 12:24:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Aug 2012 12:24:33 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FSL_RCVD_USER,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [193.74.71.28] (HELO sif.is.scarlet.be) (193.74.71.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Aug 2012 12:24:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scarlet.be; s=scarlet; t=1344428644; bh=4g+saBxF0nsKJLIazWNtXMUW1IgXbbxQGnzP2CuLog0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=YRBly9c5YDxYVaJ3W3qOD6/f3G24pfpkst2R5brGv/fh6XoeyzW3c6nfA/+qipAuY Ltb3Xg/enKI5Mc2pAVH/2ePrQKfmQ0qZ5EYNF09SJjN0ONytPqlkRx8o+s9ssPLf1c sw1nc34J1yYotXkCusEZ9HzxAVG/+r+EVv+rjN74= Received: from mail.harfang.homelinux.org (ip-62-235-229-12.dsl.scarlet.be [62.235.229.12]) by sif.is.scarlet.be (8.14.5/8.14.5) with ESMTP id q78CO41V029730 for ; Wed, 8 Aug 2012 14:24:04 +0200 X-Scarlet: d=1344428644 c=62.235.229.12 Received: from localhost (mail.harfang.homelinux.org [192.168.20.11]) by mail.harfang.homelinux.org (Postfix) with ESMTP id 07576617E1 for ; Wed, 8 Aug 2012 14:24:04 +0200 (CEST) Received: from mail.harfang.homelinux.org ([192.168.20.11]) by localhost (mail.harfang.homelinux.org [192.168.20.11]) (amavisd-new, port 10024) with ESMTP id 7C8B9z1+scPO for ; Wed, 8 Aug 2012 14:23:59 +0200 (CEST) Received: from dusk.harfang.homelinux.org (mail.harfang.homelinux.org [192.168.20.11]) by mail.harfang.homelinux.org (Postfix) with ESMTP id 2118C617A5 for ; Wed, 8 Aug 2012 14:23:58 +0200 (CEST) Received: from eran by dusk.harfang.homelinux.org with local (Exim 4.77) (envelope-from ) id 1Sz5Is-0004OA-Kf for user@commons.apache.org; Wed, 08 Aug 2012 14:23:58 +0200 Date: Wed, 8 Aug 2012 14:23:57 +0200 From: Gilles Sadowski To: user@commons.apache.org Subject: Re: [Math] Unable to fit a polynomial to data points correctly. Message-ID: <20120808122357.GL20488@dusk.harfang.homelinux.org> Mail-Followup-To: user@commons.apache.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: Tiny Tux X-PGP-Key-Fingerprint: 53B9 972E C2E6 B93C BEAD 7092 09E6 AF46 51D0 5641 User-Agent: Mutt/1.5.21 (2010-09-15) X-DCC-scarlet.be-Metrics: sif 20001; Body=1 Fuz1=1 Fuz2=1 X-Virus-Scanned: clamav-milter 0.97.1-exp at sif X-Virus-Status: Clean X-Virus-Checked: Checked by ClamAV on apache.org On Tue, Aug 07, 2012 at 11:59:09PM +0100, Mat Jaggard wrote: > I have tried to create a polynomial that fits some data using the > following code: > > PolynomialFitter fitter = new PolynomialFitter(14, new > GaussNewtonOptimizer()); > for (int i = 0; i < numValues; i++) > { > fitter.addObservedPoint(xValues[i], yValues[i]); > } > return new PolynomialFunction(fitter.fit()); > > I've also tried using a degree of 4. In both cases and using both a > GaussNewtonOptimizer and a LevenbergMarquardtOptimizer, I'm able to > get a straight line to be fitted correctly, but the following data > results with a constant value but very small multipliers for x, and > higher orders. > > Is anyone able to let me know why this is happening and what I can do about > it? > > Many thanks, > Mat. > > The result I get is... > y = 110.281064 + 0.002316943x - 3.86E-09x^2 + 4.01E-15x^3 - 1.58E-21x^4 > > From this data: > > [...] Plotting those data, and the above polynomial shows that Commons Math did a decent job. What led you to think that the fit is not correct? [Maybe the data could be better fitted with another function...] Regards, Gilles --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org