Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16030

Re: Weighting in simultaneous NonlinearModelFits

From sergisolis@gmail.com
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Weighting in simultaneous NonlinearModelFits
Date 2013-10-09 06:03 +0000
Message-ID <l32rir$542$1@smc.vnet.net> (permalink)
References <k3c1dd$ev5$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


El dimecres 19 de setembre de 2012 10:58:36 UTC+2, lukas....@gmail.com va escriure:
> 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!

Hi lukas,

I have exactly the same problem you had. What did you do to solve it? What is the best way to proceed?

Thank you so much in advance,

Regards,

Sergi

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Weighting in simultaneous NonlinearModelFits lukas.fricke@gmail.com - 2012-09-19 08:57 +0000
  Solved: Weighting in simultaneous NonlinearModelFits lukas.fricke@gmail.com - 2012-09-20 04:38 +0000
  Re: Weighting in simultaneous NonlinearModelFits sergisolis@gmail.com - 2013-10-09 06:03 +0000

csiph-web