Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

FindFit and NormFunction

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64151] FindFit and NormFunction
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Thu, 2 Feb 2006 19:09:04 -0500 (EST)
  • Organization: The University of Western Australia
  • Sender: owner-wri-mathgroup at wolfram.com

I am having difficulty using the NormFunction option to FindFit. Let me 
give a concrete example. Abramowitz and Stegun Section 17.3.35 gives a 
nonlinear approximant to the complete elliptic integral. See

 www.convertit.com/Go/ConvertIt/Reference/AMS55.ASP?Res=150&Page=592

This approximant to EllipticE[1-m] can be implemented as

 f[a_, b_, c_, d_][m_] = a m + b m^2 - (c m + d m^2) Log[m] + 1; 

After sampling EllipticE[1-m],

 data = N[Table[{m, EllipticE[1-m]}, {m, 10^-8, 1 - 10^-8, 10^-3}]];

using FindFit gives quite a decent approximant:

 FindFit[data, f[a, b, c, d][m], {a,b,c,d}, m]

 best[m_] =f[a, b, c, d][m] /. %

The maximal absolute fractional error is ~6 x 10^-5 as seen from

 Plot[10^5 (1 - best[m]/EllipticE[1 - m]), {m, 0, 1}, PlotRange -> All]

However, the Abramowitz and Stegun approximant has error ~4 x 10^-5.

 AS[m_] =f[0.4630151, 0.1077812, 0.2452727, 0.0412496][m];

 Plot[10^5 (1 - AS[m]/EllipticE[1 - m]), {m, 0, 1}, PlotRange -> All]

Essentially, one needs to fit with respect to the L-Infinity-Norm, see

 http://mathworld.wolfram.com/L-Infinity-Norm.html

as the NormFunction in FindFit. However, when I try

  FindFit[data, f[a, b, c, d][m], {a,b,c,d}, m, 
     NormFunction :> (Norm[#, Infinity]&)]

I get a FindFit::"lmnl" message (which is reasonable and informative) 
and also a FindFit::"lstol" message:

 "The line search decreased the step size to within tolerance specified 
  by AccuracyGoal and PrecisionGoal but was unable to find a sufficient 
  decrease in the norm of the residual. You may need more than 
  MachinePrecision digits of working precision to meet these tolerances."

I can see (by monitoring the Norm of the residual) that the algorithm 
gets trapped a long way from the minimum -- but I don't see why more 
digits of working precision are required. 

As an aside, is there an easy way (a handle?) to monitor the norm of the 
residuals at each step? One way is to write a function to compute the 
residuals,

 r[a_, b_, c_, d_] = 
  Norm[(f[a, b, c, d] /@ data[[All,1]]) - data[[All,2]], Infinity];

and then track them using StepMonitor or EvaluationMonitor

  Reap[FindFit[data, f[a, b, c, d][m], {a,b,c,d}, m, 
    NormFunction :> (Norm[#,Infinity]&),
    EvaluationMonitor :> Sow[r[a,b,c,d]]]]

but is there a _direct_ way of accessing the residuals which are 
computed by FindFit anyway?

Cheers,
Paul

_______________________________________________________________________
Paul Abbott                                      Phone:  61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul

_______________________________________________________________________
Paul Abbott                                      Phone:  61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul


  • Prev by Date: Matrix decomposition with NullSpace and QRDecomposit
  • Next by Date: Re: Trigonometric form of complex numbers
  • Previous by thread: Re: Problem to evaluate a function inside a function
  • Next by thread: Re: FindFit and NormFunction