Prev: Occurrences in Mathematica
Next: ODE Stiff Systems
From: Ktota on 10 Jan 2010 03:30 mtest1[t_,ltime_]:=If [var1*(t+var2-qtime)>8000,Sum[If [var1*(tsum +var2-qtime)>8000,8000*(1-P),var1*(tsum+var2- qtime)*(1-P)],{tsum,t- ltime+1, t,1}],Max[{Sum[{var1*(tsum+var2- qtime)*(1-P)},{tsum,t-ltime +1, t,1}]},0]]/156000 i optimize the model above with: parameter2= NonlinearModelFit[ExpData, mtest1[t, ltime], {ltime}, t] which is perfectly fine... but as soon i want to see the ParameterTable or the ConfidenceIntervals by doing this: parameter2["ParameterTable"] I get the following error message: and this only happens if i want to fit for ltime.. parameters P and var1 are perfectly fine.... In[374]:= parameter2["ParameterTable"] During evaluation of In[374]:= General::ivar: 9.125191604503259` is not a valid variable. >> During evaluation of In[374]:= General::ivar: 9.125191604503259` is not a valid variable. >> During evaluation of In[374]:= General::ivar: 9.125191604503259` is not a valid variable. >> During evaluation of In[374]:= General::stop: Further output of General::ivar will be suppressed during this calculation. >> Out[374]= $Aborted if i only want to see the result it gives me no error: In[370]:= parameter2["BestFitParameters"] Out[370]= {ltime->9.12519} hope somebody can help...as this drives me mad... thank you very much NuKtoBi
From: dh on 11 Jan 2010 05:29 Hi, it looks like ltime already has a value. Try clearing ltime. Anyway, you should give a simple working example. Daniel Ktota wrote: > mtest1[t_,ltime_]:=If [var1*(t+var2-qtime)>8000,Sum[If [var1*(tsum > +var2-qtime)>8000,8000*(1-P),var1*(tsum+var2- qtime)*(1-P)],{tsum,t- > ltime+1, t,1}],Max[{Sum[{var1*(tsum+var2- qtime)*(1-P)},{tsum,t-ltime > +1, t,1}]},0]]/156000 > > > i optimize the model above with: > > parameter2= > NonlinearModelFit[ExpData, mtest1[t, ltime], {ltime}, > t] > > > which is perfectly fine... > > but as soon i want to see the ParameterTable or the > ConfidenceIntervals by doing this: > > parameter2["ParameterTable"] > > I get the following error message: > > and this only happens if i want to fit for ltime.. parameters P and > var1 are perfectly fine.... > > In[374]:= parameter2["ParameterTable"] > During evaluation of In[374]:= General::ivar: 9.125191604503259` is > not a valid variable. >> > During evaluation of In[374]:= General::ivar: 9.125191604503259` is > not a valid variable. >> > During evaluation of In[374]:= General::ivar: 9.125191604503259` is > not a valid variable. >> > During evaluation of In[374]:= General::stop: Further output of > General::ivar will be suppressed during this calculation. >> > Out[374]= $Aborted > > if i only want to see the result it gives me no error: > In[370]:= parameter2["BestFitParameters"] > Out[370]= {ltime->9.12519} > > hope somebody can help...as this drives me mad... > > thank you very much > > NuKtoBi >
From: Bob Hanlon on 11 Jan 2010 05:32 For the following, eliminate the extraneous list brackets and use the symbolic Sum {Sum[{var1*(tsum + var2 - qtime)*(1 - P)}, {tsum, t - ltime + 1, t, 1}]} // FullSimplify {{(1/2)*ltime*(P - 1)*var1*(ltime + 2*qtime - 2*t - 2*var2 - 1)}} Instead of If[var1*(tsum + var2 - qtime) > 8000, 8000*(1 - P), var1*(tsum + var2 - qtime)*(1 - P)] Use Min[8000*(1 - P), var1*(tsum + var2 - qtime)*(1 - P)] Then use Piecewise instead of the outer If. If is primarily a programming construct; whereas, Piecewise is intended as a mathematical construct. mtest1[t_, ltime_] := Piecewise[{{ Sum[ Min[ 8000*(1 - P), var1*(tsum + var2 - qtime)*(1 - P)], {tsum, t - ltime + 1, t, 1}], var1*(t + var2 - qtime) > 8000}}, Max[ ltime*(P - 1)*var1* (ltime + 2*(qtime - t - var2) - 1)/2, 0]]/156000 Without realistic test data and knowing the values of the constants that are not parameters, I will not go further. Also, if you look at the symbolic output expression for mtest1[t, ltime] you will see that it might simplify considerably if you include any known constraints on the constants and/or parameters. Bob Hanlon ---- Ktota <nuktobi(a)gmail.com> wrote: ============= mtest1[t_,ltime_]:=If [var1*(t+var2-qtime)>8000,Sum[If [var1*(tsum +var2-qtime)>8000,8000*(1-P),var1*(tsum+var2- qtime)*(1-P)],{tsum,t- ltime+1, t,1}],Max[{Sum[{var1*(tsum+var2- qtime)*(1-P)},{tsum,t-ltime +1, t,1}]},0]]/156000 i optimize the model above with: parameter2= NonlinearModelFit[ExpData, mtest1[t, ltime], {ltime}, t] which is perfectly fine... but as soon i want to see the ParameterTable or the ConfidenceIntervals by doing this: parameter2["ParameterTable"] I get the following error message: and this only happens if i want to fit for ltime.. parameters P and var1 are perfectly fine.... In[374]:= parameter2["ParameterTable"] During evaluation of In[374]:= General::ivar: 9.125191604503259` is not a valid variable. >> During evaluation of In[374]:= General::ivar: 9.125191604503259` is not a valid variable. >> During evaluation of In[374]:= General::ivar: 9.125191604503259` is not a valid variable. >> During evaluation of In[374]:= General::stop: Further output of General::ivar will be suppressed during this calculation. >> Out[374]= $Aborted if i only want to see the result it gives me no error: In[370]:= parameter2["BestFitParameters"] Out[370]= {ltime->9.12519} hope somebody can help...as this drives me mad... thank you very much NuKtoBi
From: Darren Glosemeyer on 11 Jan 2010 18:54 Ktota wrote: > mtest1[t_,ltime_]:=If [var1*(t+var2-qtime)>8000,Sum[If [var1*(tsum > +var2-qtime)>8000,8000*(1-P),var1*(tsum+var2- qtime)*(1-P)],{tsum,t- > ltime+1, t,1}],Max[{Sum[{var1*(tsum+var2- qtime)*(1-P)},{tsum,t-ltime > +1, t,1}]},0]]/156000 > > > i optimize the model above with: > > parameter2= > NonlinearModelFit[ExpData, mtest1[t, ltime], {ltime}, > t] > > > which is perfectly fine... > > but as soon i want to see the ParameterTable or the > ConfidenceIntervals by doing this: > > parameter2["ParameterTable"] > > I get the following error message: > > and this only happens if i want to fit for ltime.. parameters P and > var1 are perfectly fine.... > > In[374]:= parameter2["ParameterTable"] > During evaluation of In[374]:= General::ivar: 9.125191604503259` is > not a valid variable. >> > During evaluation of In[374]:= General::ivar: 9.125191604503259` is > not a valid variable. >> > During evaluation of In[374]:= General::ivar: 9.125191604503259` is > not a valid variable. >> > During evaluation of In[374]:= General::stop: Further output of > General::ivar will be suppressed during this calculation. >> > Out[374]= $Aborted > > if i only want to see the result it gives me no error: > In[370]:= parameter2["BestFitParameters"] > Out[370]= {ltime->9.12519} > > hope somebody can help...as this drives me mad... > > thank you very much > > NuKtoBi > A working example would be needed to figure out what is happening. My best guess is that there is a problem with the model specification (Daniel and Bob mentioned a couple possible issues) or that this example runs into trouble computing derivatives of the model which are needed for standard errors and such. If it is trouble with derivatives, it may be a bug in need of fixing, but a full working example would be needed. Darren Glosemeyer Wolfram Research
From: Ktota on 13 Jan 2010 06:01
On 11 Jan, 23:54, Darren Glosemeyer <darr...(a)wolfram.com> wrote: > Ktota wrote: > > mtest1[t_,ltime_]:=If [var1*(t+var2-qtime)>8000,Sum[If [var1*(tsum > > +var2-qtime)>8000,8000*(1-P),var1*(tsum+var2- qtime)*(1-P)],{tsum,t- > > ltime+1, t,1}],Max[{Sum[{var1*(tsum+var2- qtime)*(1-P)},{tsum,t-ltime > > +1, t,1}]},0]]/156000 > > > i optimize the model above with: > > > parameter2= > > NonlinearModelFit[ExpData, mtest1[t, ltime], {ltime}, > > t] > > > which is perfectly fine... > > > but as soon i want to see the ParameterTable or the > > ConfidenceIntervals by doing this: > > > parameter2["ParameterTable"] > > > I get the following error message: > > > and this only happens if i want to fit for ltime.. parameters P and > > var1 are perfectly fine.... > > > In[374]:= parameter2["ParameterTable"] > > During evaluation of In[374]:= General::ivar: 9.125191604503259` is > > not a valid variable. >> > > During evaluation of In[374]:= General::ivar: 9.125191604503259` is > > not a valid variable. >> > > During evaluation of In[374]:= General::ivar: 9.125191604503259` is > > not a valid variable. >> > > During evaluation of In[374]:= General::stop: Further output of > > General::ivar will be suppressed during this calculation. >> > > Out[374]= $Aborted > > > if i only want to see the result it gives me no error: > > In[370]:= parameter2["BestFitParameters"] > > Out[370]= {ltime->9.12519} > > > hope somebody can help...as this drives me mad... > > > thank you very much > > > NuKtoBi > > A working example would be needed to figure out what is happening. My > best guess is that there is a problem with the model specification > (Daniel and Bob mentioned a couple possible issues) or that this example > runs into trouble computing derivatives of the model which are needed > for standard errors and such. If it is trouble with derivatives, it may > be a bug in need of fixing, but a full working example would be needed. > > Darren Glosemeyer > Wolfram Research Dear All, thank you for your replies. I try to post a working example again... i though i send it yesterday. I guess I didn't actually press the send button as my message still doesn't appear. Even with the nice changes suggested by bob it didn't work (Daniel: clearing didn't help :( ), it made the code certainly more elegant. Nevertheless this is what happened when I introduced the changes: Mathematica got stuck, till I was forced to abort the evaluation with no result (mathematica prompted me several times to abort the evaluation... if i don't do that the mathematica crashes after a time). When I tried to see what happens if I use StepMonitor or EvaluationMonitor I could see that Mathematica didn't even try to give my parameters a value... so it must have got stuck at the very beginning. again: Using my code I get the same error messages as described in my previous post. Ok, I want to provide yo with an working example: This are the optimum parameter sets: 1.Please replace the 8000 with 6600, it should not matter to much at the end... but well, this would be the optimum number to set. 2.Here are the constant values: ltime = 10 var1=40 qtime=40 var2=10 P=0.7 suitable ranges for t <360 (but you can see that from the example data provided) Right now i proceed the following way: I clear the parameter i'm looking for and set the rest (and update replace the corresponding line of code). So if you fitting for ltime or P you need to set the values above correspondingly. Usually what i get if i fit for P is approx. 0.7, if i fit for ltime approx. 9.5. 3. A working dataset for tests: {{10, 0}, {20, 0}, {30, 0}, {40, 0}, {50, 0}, {60, 0.00585596}, {70, 0.00978394}, {80, 0.014027}, {90, 0.0193965}, {100, 0.033127}, {110, 0.0229201}, {120, 0.0342658}, {130, 0.038038}, {140, 0.0467315}, {150, 0.0599289}, {160, 0.0843373}, {170, 0.0933467}, {180, 0.0972515}, {200, 0.124476}, {220, 0.126171}, {240, 0.149213}, {260, 0.125667}, {280, 0.131284}, {300, 0.111403}, {20, 0}, {30, 0}, {40, 0}, {50, 0}, {60, 0.00504185}, {70, 0.00105643}, {80, 0.00476066}, {90, 0.0199289}, {100, 0.0278976}, {110, 0.0363378}, {120, 0.0487953}, {130, 0.0592385}, {140, 0.0586732}, {150, 0.0720589}, {160, 0.0790288}, {170, 0.0908122}, {180, 0.098357}, {200, 0.120454}, {220, 0.133432}, {240, 0.137956}, {270, 0.159881}, {300, 0.152705}, {330, 0.170188}, {360, 0.125013}, {20, 0}, {30, 0}, {40, 0}, {50, 0.0057359}, {60, 0.00883602}, {70, 0.0155384}, {80, 0.0219417}, {90, 0.0356022}, {100, 0.0309318}, {110, 0.0378177}, {120, 0.0602476}, {130, 0.0657433}, {140, 0.0676202}, {150, 0.0840599}, {160, 0.100496}, {170, 0.0842674}, {180, 0.113089}, {200, 0.0969867}, {220, 0.123612}, {240, 0.119192}, {270, 0.115528}, {300, 0.129542}, {330, 0.119207}, {360, 0.124696}} 3. For convinience here also an updated model: mtest1[t_,ltime_]:=If [var1*(t+var2-qtime)>6600,Sum[If [var1*(tsum +var2-qtime)>6600,6600*(1-P),var1*(tsum+var2- qtime)*(1-P)],{tsum,t- ltime+1, t,1}],Max[{Sum[{var1*(tsum+var2- qtime)*(1-P)},{tsum,t-ltime +1, t,1}]},0]]/156000 This is how i do the fitting: parameterWT2 = NonlinearModelFit[ExperimentalData, mtest1[t, ltime], {ltime}, t] I hope i didn't miss out anything. Best Wishes |