Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Solved: Weighting in simultaneous NonlinearModelFits

  • To: mathgroup at smc.vnet.net
  • Subject: [mg128165] Solved: Weighting in simultaneous NonlinearModelFits
  • From: lukas.fricke at gmail.com
  • Date: Thu, 20 Sep 2012 00:24:06 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <k3c1dd$ev5$1@smc.vnet.net>

Am Mittwoch, 19. September 2012 10:58:36 UTC+2 schrieb lukas.... at gmail.com:
> I would like to add weights from a list to the problem of solving nonlinearmodelfits for different datasets / different models with equal parameters. I tried to add another counter for the weight-array index but somehow this did not work.
> 
> 
> 
> Code up to now:
> 
> gdata0sm = Table[gdata0[[y]], {y, startind, stopind}];
> 
> gdata1sm = Table[gdata1[[y]], {y, startind, stopind}];
> 
> gdata2sm = Table[gdata2[[y]], {y, startind, stopind}]; 
> 
> wdata0sm = Table[wdata0[[y]], {y, startind, stopind}];
> 
> wdata1sm = Table[wdata1[[y]], {y, startind, stopind}];
> 
> wdata2sm = Table[wdata2[[y]], {y, startind, stopind}];
> 
> gdata3sm = Table[gdata3[[y]], {y, startind, stopind}];
> 
> alldata = Join[gdata0sm, gdata1sm, gdata2sm];
> 
> 
> 
> gdata0sm looks like:
> 
> {{-206.5, 1, 1., 0.403875}, {-206., 2, 1., 0.385625}, {-205.5, 3, 1., 
> 
>   0.354828}, {-205., 4, 1., 0.287206}, {-204.5, 5, 1., 
> 
>   0.278158}, {-204., 6, 1., 0.218795}, {-203.5, 7, 1., 
> 
>   0.205412}, {-203., 8, 1., 0.181136}, {-202.5, 9, 1., 
> 
>   0.163026}, {-202., 10, 1., 0.141125}, {-201.5, 11, 1., 
> 
>   0.130676}, {-201., 12, 1., 0.12194}, {-200.5, 13, 1., 
> 
>   0.101519}, {-200., 14, 1., 0.0910204}, {-199.5, 15, 1., 
> 
>   0.0834921}, {-199., 16, 1., 0.075974}, {-198.5, 17, 1., 
> 
>   0.0714118}, {-198., 18, 1., 0.0564474}, {-197.5, 19, 1., 
> 
>   0.0507692}, {-197., 20, 1., 0.0459155}, {-196.5, 21, 1., 
> 
>   0.0403896}, {-196., 22, 1., 0.0396364}, {-195.5, 23, 1., 
> 
>   0.0328571}, {-195., 24, 1., 0.0237143}, {-194.5, 25, 1., 
> 
>   0.0294737}, {-194., 26, 1., 0.0225373}, {-193.5, 27, 1., 
> 
>   0.018375}, {-193., 28, 1., 0.0139773}, {-192.5, 29, 1., 
> 
>   0.00969231}, {-192., 30, 1., 0.0126563}, {-191.5, 31, 1., 
> 
>   0.01}, {-191., 32, 1., 0.0114706}, {-190.5, 33, 1., 
> 
>   0.00744186}, {-190., 34, 1., 0.0048}, {-189.5, 35, 1., 
> 
>   0.0059375}, {-189., 36, 1., 0.00575758}, {-188.5, 37, 1., 
> 
>   0.00901961}, {-188., 38, 1., 0.00403226}, {-187.5, 39, 1., 
> 
>   0.00454545}, {-187., 40, 1., 0.00307692}, {-186.5, 41, 1., 
> 
>   0.00357143}, {-186., 42, 1., 0.00223684}, {-185.5, 43, 1., 
> 
>   0.002}, {-185., 44, 1., 0.000806452}, {-184.5, 45, 1., 0.000769231}}
> 
> 
> 
> Then I define the different models with Kronecker-delta:
> 
> bfun0[a_, b_] := 1/(1 + Exp[-a*x - b]);
> 
> bfun1[a_, b_, c_, d_] := 
> 
>   Exp[c*x + d]/(1 + Exp[a*x + b])/(1 + Exp[c*x + d]);
> 
> bfun2[a_, b_, c_, d_] := 
> 
>   1 - 1/(1 + Exp[-a*x - b]) - 
> 
>    Exp[c*x + d]/(1 + Exp[a*x + b])/(1 + Exp[c*x + d]);
> 
> modtotal[index_, counter_, a_, b_, c_, d_] := 
> 
>   KroneckerDelta[index - 1]*bfun0[a, b] + 
> 
>    KroneckerDelta[index - 2]*bfun1[a, b, c, d] + 
> 
>    KroneckerDelta[index - 3]*bfun2[a, b, c, d];
> 
> 
> 
> and tried this expression:
> 
> thermresult = 
> 
>   NonlinearModelFit[alldata, 
> 
>    modtotal[index, counter, a, b, c, 
> 
>     d], {{a, -.28}, {b, -58}, {c, -.82}, {d, -150}}, {x, counter, 
> 
>     index}, Weights -> (If[#3 == 1, 1/(wdata0sm[[#2]])^2, 
> 
>        If[#3 == 2, 1/(wdata1sm[[#2]])^2, 1/(wdata2sm[[#2]])^2]] &)];
> 
> 
> 
> This works fine with constant weights (replace each reference to an array by a fixed number), but not in the way I tried it...
> 
> 
> 
> Thanks a lot for any advice!

I found a solution for this after a while:
added
allweights = Join[wdata0sm, wdata1sm, wdata2sm] /. (0. -> 1);
modweight[index_, x_] := 
  1/First[allweights[[(index - 1)*Length[gdata0sm] + 
       1 + (Abs[vgate[[startind]]] - Abs[x])*2]]^2];
thermresultw = 
  NonlinearModelFit[alldata, 
   modtotal[index, a, b, c, 
    d], {{a, -.28}, {b, -58}, {c, -.82}, {d, -150}}, {x, index}, 
   Weights -> (modweight[#2, #1] &)];

and it worked like this... Maybe in my previous post, only the "First" command was missing... :-(



  • Prev by Date: Re: while loop through a list
  • Next by Date: Re: Changing typeface using the find and replace dialog
  • Previous by thread: Copying Text From CDF Output Cells
  • Next by thread: NIntegrate within NDSolve-optimization?