Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: problem with NonlinearFit
Replies: 2   Last Post: Sep 16, 1996 10:15 PM

 Messages: [ Previous | Next ]
 Brian O'NEILL Posts: 1 Registered: 12/11/04
problem with NonlinearFit
Posted: Aug 31, 1996 2:47 AM

I am having the following problem with the NonlinearFit function, and would
appreciate any tips you might have. (I have appended sample Mathematica code
below.)

My goal is to fit a non-monotically decreasing time series with a
monotonically decreasing function (specifically, a sum of decaying
exponenitials plus a constant). I am approaching the problem by using
NonlinearFit and specifying a general functional form, then attempting to
constrain the search to non-negative coefficients and non-positive
exponents. However, in general I have run into the following problems:

(1) NonlinearFit will accept parameter specifications of the form {x,xo}, or
of the form {x,minx,maxx}, but not of the form {x,xo,xmin,xmax}. This means
I can constrain the variables, but I can't start from different points to
test robustness.

(2)The routine stops when it tries to search outside the constraints instead
of continuing the search in a different direction, so that it is important
to be able to specify different initial values to look elsewhere.

I have also tried using MultiplierMethod and posing the problem as a
minimization of least squares errors, but have had even less luck getting
that function to accept constraints (but if you have pointers I would be
happy to use anything that works).

The code is below; any help appreciated.
Thanks,

Brian O'Neill

(* define general functional form - sum of exponentials *)
(* plus a constant, such that all coefficients sum to 1 *)
fn[t_,a1_,a2_,a3_,tau1_,tau2_,tau3_] :=
(1.-a1-a2-a3)+a1*Exp[-t/tau1]+a2*Exp[-t/tau2]+
a3*Exp[-t/tau3];

(* generate data with one negative coefficient to *)
(* produce a bump in the data *)
data = Table[{t,fn[t,0.6,-0.4,0.1,15,30,300]},{t,0,300,10}];

(* take a look at data *)
ListPlot[data,PlotRange->All]

(* fit data with only positive coefficients allowed, *)
(* supplying no starting points. this gives a solution, *)
(* but I'd like to look for a better one (depending on the *)
(* data, it sometimes stops searching because it exits the *)
(* parameter bounds) *)
soln = NonlinearFit[data,fn[x,a1,a2,a3,tau1,tau2,tau3],
x,{{a1,0,1},{a2,0,1},{a3,0,1},
{tau1,0,Infinity},{tau2,0,Infinity},{tau3,0,Infinity}},
PrecisionGoal->5,
AccuracyGoal->5,
ShowProgress->True]

(* try the same fit again, with same constraints on *)
(* parameters but supplying starting points in order *)
(* to find a different solution - but the function won't *)
(* take both starting points and constraints....I can't *)
(* find a syntax that works (this is the syntax give in *)
(* the package documentation), nor can I figure out from *)
(* looking at the package what the problem is. *)
soln = NonlinearFit[data,fn[x,a1,a2,a3,tau1,tau2,tau3],
x,{{a1,0.2,0,1},{a2,0.2,0,1},{a3,0.2,0,1},
{tau1,5,0,Infinity},{tau2,50,0,Infinity},
{tau3,100,0,Infinity}},
PrecisionGoal->5,
AccuracyGoal->5,
ShowProgress->True]

(* take a look at the fit *)
Show[
ListPlot[data,PlotRange->All,DisplayFunction->Identity],
Plot[fn[t,a1,a2,a3,tau1,tau2,tau3]/.soln,{t,0,300},
DisplayFunction->Identity],
DisplayFunction->\$DisplayFunction];

Brian O'NEILL
International Institute for | Email: oneill@iiasa.ac.at
Applied Systems Analysis | Phone: +43 2236 807 0
A-2361 Laxenburg, Austria | Fax: +43 2236 71313

Date Subject Author
8/31/96 Brian O'NEILL
9/5/96 Skip Egley
9/16/96 Paul A. Rubin