Re: Use of ShowProgress Option output
- To: mathgroup at smc.vnet.net
- Subject: [mg34805] Re: Use of ShowProgress Option output
- From: "Carl K. Woll" <carlw at u.washington.edu>
- Date: Sat, 8 Jun 2002 05:21:11 -0400 (EDT)
- References: <admu5q$emo$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Andre,
Here is a perhaps frowned on possibility. Add a new definition to Print,
such as
In[4]:=
Unprotect[Print];
Print[a__/;printflag]:=
Module[{},
printflag=False;
If[ValueQ[iterlist],iterlist={iterlist,{a}},iterlist={a}];
Print[a];
printflag=True;]
Protect[Print];
Now, load the nonlinearfit package and run it:
In[7]:=
<< Statistics`NonlinearFit`
In[8]:=
data = {{1.0, 1.0, .126}, {2.0, 1.0, .219},
{1.0, 2.0, .076}, {2.0, 2.0, .126}, {.1, .0, .186}};
In[9]:=
printflag=True;
Clear[iterlist]
NonlinearFit[data,
theta1 theta3 x1 / (1 + theta1 x1 + theta2 x2),
{x1, x2}, {theta1, theta2,
theta3},RegressionReport->BestFitParameters,ShowProgress->True
]
printflag=False;
Iteration:1 ChiSquared:0.236342 Parameters:{1., 1., 1.}
Iteration:2 ChiSquared:0.0448893 Parameters:{2.69113, 3.34008, 0.173414}
Iteration:3 ChiSquared:0.00265359 Parameters:{5.00694, 9.2595, 0.425435}
Iteration:4 ChiSquared:0.000156222 Parameters:{4.45296, 15.2544, 0.588897}
Iteration:5 ChiSquared:0.0000809401 Parameters:{4.27179, 15.2961, 0.620383}
Iteration:6 ChiSquared:0.0000647486 Parameters:{3.88567, 15.3226, 0.662373}
Iteration:7 ChiSquared:0.0000553597 Parameters:{3.76195, 15.3201, 0.681971}
Iteration:8 ChiSquared:0.0000493747 Parameters:{3.51402, 15.2834, 0.715091}
Iteration:9 ChiSquared:0.0000454058 Parameters:{3.33655, 15.2364, 0.743497}
Iteration:10 ChiSquared:0.0000444845 Parameters:{3.13323, 15.1582, 0.777529}
Iteration:11 ChiSquared:0.0000435527 Parameters:{3.13156, 15.1594, 0.780051}
Out[11]=
2.44277 x1
---------------------------
1 + 3.13151 x1 + 15.1594 x2
Now, let's check to see if iterlist has the list you want:
In[13]:=
iterlist
Out[13]=
{{{{{{{{{{{Iteration:1 ChiSquared:0.236342 Parameters:{1., 1., 1.}},
{Iteration:2 ChiSquared:0.0448893 Parameters:{2.69113, 3.34008,
0.173414}}},
{Iteration:3 ChiSquared:0.00265359 Parameters:{5.00694, 9.2595,
0.425435}}},
{Iteration:4 ChiSquared:0.000156222 Parameters:{4.45296, 15.2544,
0.588897}}},
{Iteration:5 ChiSquared:0.0000809401 Parameters:{4.27179, 15.2961,
0.620383}}},
{Iteration:6 ChiSquared:0.0000647486 Parameters:{3.88567, 15.3226,
0.662373}}},
{Iteration:7 ChiSquared:0.0000553597 Parameters:{3.76195, 15.3201,
0.681971}}},
{Iteration:8 ChiSquared:0.0000493747 Parameters:{3.51402, 15.2834,
0.715091}}},
{Iteration:9 ChiSquared:0.0000454058 Parameters:{3.33655, 15.2364,
0.743497}}},
{Iteration:10 ChiSquared:0.0000444845 Parameters:{3.13323, 15.1582,
0.777529}}},
{Iteration:11 ChiSquared:0.0000435527 Parameters:{3.13156, 15.1594,
0.780051}}}
Yup, there it is. If you are worried about changing Print, you could write a
function (AndreFit?) which takes care of changing the Print definition,
setting printflag and clearing iterlist, and then running NonlinearFit, and
then restoring everything back to normal.
Carl Woll
Physics Dept
U of Washington
----- Original Message -----
From: "Andre Heinemann" <heinemann at hmi.de>
To: mathgroup at smc.vnet.net
Subject: [mg34805] Use of ShowProgress Option output
> Hi,
>
> ... may be my question was not clear in detail, but I realy can't find a
> solution.
> I will show you an example from the help browswer to ilustrate my problem.
>
>
> data={{1.0,1.0,.126},{2.0,1.0,.219},{1.0,2.0,.076},{2.0,
> 2.0,.126},{.1,.0,.186}};
>
> NonlinearRegress[data,
> theta1 theta3 x1/(1+theta1 x1+theta2 x2),{x1,x2},{theta1,theta2,theta3},
> RegressionReport->BestFitParameters,ShowProgress->True]
>
> I get:
>
> From In[396]:=
> Iteration:1 ChiSquared:0.23634239210284666` Parameters:{1.,1.,1.}
> .
> .(snip snap) 8><
> .
> From In[396]:=
> Iteration:11 ChiSquared:0.000043552662305849804` \
> Parameters:{3.13156,15.1594,0.780051}
>
> Out[396]=
> {BestFitParameters\[Rule]{theta1\[Rule]3.13151,theta2\[Rule]15.1594,
> theta3\[Rule]0.780062}}
>
> My aim is to get !automaticaly! a list like this:
>
>
{{Iteration:1,{1.,1.,1.}},...,{Iteration:11,{3.13156,15.1594,0.780051}},...,
}
>
> May be this problem is very easy to solve, but I found only the "Hand
> made solution"
> of copy and paste - this is not the way I want to use a computer (-;
>
> So if you have any idea how to solve this problem, please give me a hint.
>
> Thanks,
> Andre
>
>