From: Dan O'Brien on 10 Apr 2010 06:53 Hello everyone, A small statement of my problem: I have 4 data sets consisting of spectroscopic data (intensity vs frequency data). The data contain resonant peaks that are fit with the modulus squared of a sum of complex functions (one for each peak for a total of 6 peaks) and is such that I must use nonlinear fitting algorithms. Within the four data sets there are peaks that should be fit to the same parameters and then there are peaks that vary slightly from data set to data set. The bottom line is this: I am looking for a solution of the form of a nonlinear fitting function that is capable of simultaneously fitting multiple data sets where some parameters apply to all the data sets and others are specific to only one of the data sets. I have tried fitting each data set independently using the mathematica function NonlinearModelFit but the model is such that the bestfitparameters can vary wildly from data set to data set. Using the option to constrain leads to computations that never end. It would be best, in my mind, if Mathematica's fitting algorithm was constrained by having to minimize the function of the residuals when forced to consider all data sets at once. I am relatively new to mathematica (I have been hacking at it for about a year or so) and appreciate any help this group can offer. Thanks, -DanO
From: dh on 12 Apr 2010 06:50 On 10.04.2010 12:53, Dan O'Brien wrote: > Hello everyone, > > A small statement of my problem: I have 4 data sets consisting of > spectroscopic data (intensity vs frequency data). The data contain > resonant peaks that are fit with the modulus squared of a sum of complex > functions (one for each peak for a total of 6 peaks) and is such that I > must use nonlinear fitting algorithms. Within the four data sets there > are peaks that should be fit to the same parameters and then there are > peaks that vary slightly from data set to data set. > > The bottom line is this: I am looking for a solution of the form of a > nonlinear fitting function that is capable of simultaneously fitting > multiple data sets where some parameters apply to all the data sets and > others are specific to only one of the data sets. > > I have tried fitting each data set independently using the mathematica > function NonlinearModelFit but the model is such that the > bestfitparameters can vary wildly from data set to data set. Using the > option to constrain leads to computations that never end. It would be > best, in my mind, if Mathematica's fitting algorithm was constrained by > having to minimize the function of the residuals when forced to consider > all data sets at once. > > I am relatively new to mathematica (I have been hacking at it for about > a year or so) and appreciate any help this group can offer. > > Thanks, > > -DanO > Hi Dan, you must merge all the different data sets into one. There are different possibilities for this, you may e.g. shift the sets that they do not overlap or you may introduce an additional dimension. Here is an example where I fit 2 spectra containing one independent and one common Gaussian peak. Note that you need reasonable starting values for the fit to succeed. d1 = Table[Exp[- 0.02 (x - 30)^2], {x, 100}]; d2 = Table[Exp[- 0.02 (x - 70)^2], {x, 100}]; d3 = Table[Exp[- 0.02 (x - 50)^2], {x, 100}]; ones = Table[1, {100}]; xs = Range[100]; data = Join[Transpose[{xs, -ones, d1}], Transpose[{xs, ones, d2}], Transpose[{xs, 0 ones, d3}]]; mod1[x_, z_, x0_] := If[z <= 0, Exp[-0.02 (x - x0)^2], 0]; mod2[x_, z_, x0_] := If[z >= 0, Exp[-0.02 (x - x0)^2], 0]; mod3[x_, z_, x0_] := Exp[-0.02 (x - x0)^2]; sol = FindFit[data, mod1[x, z, x1] + mod2[x, z, x2] + mod3[x, z, x3], {{x1, 50}, {x2, 50}, {x3, 50}}, {x, z}] cheers, Daniel -- Daniel Huber Metrohm Ltd. Oberdorfstr. 68 CH-9100 Herisau Tel. +41 71 353 8585, Fax +41 71 353 8907 E-Mail:<mailto:dh(a)metrohm.com> Internet:<http://www.metrohm.com>
From: danl on 12 Apr 2010 06:51 > Hello everyone, > > A small statement of my problem: I have 4 data sets consisting of > spectroscopic data (intensity vs frequency data). The data contain > resonant peaks that are fit with the modulus squared of a sum of complex > functions (one for each peak for a total of 6 peaks) and is such that I > must use nonlinear fitting algorithms. Within the four data sets there > are peaks that should be fit to the same parameters and then there are > peaks that vary slightly from data set to data set. > > The bottom line is this: I am looking for a solution of the form of a > nonlinear fitting function that is capable of simultaneously fitting > multiple data sets where some parameters apply to all the data sets and > others are specific to only one of the data sets. > > I have tried fitting each data set independently using the mathematica > function NonlinearModelFit but the model is such that the > bestfitparameters can vary wildly from data set to data set. Using the > option to constrain leads to computations that never end. It would be > best, in my mind, if Mathematica's fitting algorithm was constrained by > having to minimize the function of the residuals when forced to consider > all data sets at once. > > I am relatively new to mathematica (I have been hacking at it for about > a year or so) and appreciate any help this group can offer. > > Thanks, > > -DanO This came up in house several weeks ago. A way to go about this, suggested to me by Darren Glosemeyer, is as follows. (1) Prepend integer indices to your data, so e.g. elements from the third set of the form {x,y} would become {3,x,y}. (2) Join the data sets. Call resulting list "alldata", say. (3) Define the function of the parameters you want to find. Call it myPeak, say. (4) Define your several parameter sets. Those that are to be common values across several sets will simply appear in each of those sets. Take a simple example of multiple Gaussians with a common variance. Would be specified as params1 = {m1,var}; params2 = {m2,var}; .... so they use the same variance parameter "var" but separate mean parameters "m1", "m2", etc. (5) Now you can invoke e.g. NonlinearModelFit as fitall = NonlinearModelFit[alldata, KroneckerDelta[index-1]*myPeak[params1] + KroneckerDelta[index-2]*myPeak[params2] + ..., <list of union of all parameters perhaps with starting values>, ...] Daniel Lichtblau Wolfram Research
From: TheBalrog on 20 Apr 2010 05:50 I am trying to do something similar but I'm afraid I don't understand all of the syntax or the expressions in either example. I'd like to post a notebook, but I'm not sure that it's possible on this forum. In Daniel's example, I cannot identify the expression, and thus cannot replace it with my own. It seems as though there are three expressions depending on the value of z (although I don't know what the zero means at the end of the If statement). Also in the FindFit[data,expr,pars,vars] command I do not know what x1,x2 and x3 refer to (are they related to x0?), nor do I understand how this expression relates to the previous one. In DanO's example I don't understand step 5. If the expression is myPeak, then why multiply it by KroneckerDelta[index-1]? Sorry for my ignorance but I'm not a mathematician. I enclose a function I am familiar with and two datasets I would like to fit; I have also written a Manipulate command so that anyone who would like to help can understand the expression. The independent variables are "S" and "Inh" and I would like to get a global solution for Vmax, Km and Ki. Naturally any help is greatly appreciated. data2D = {{0, 0}, {1, 2.5`}, {2, 3.5`}, {3, 3.8`}, {4, 4}, {0, 0}, {1, 1}, {2, 1.6`}, {3, 2.1`}, {4, 2.5`}}; data3D = {{0, 0, 0}, {0, 1, 2.5`}, {0, 2, 3.5`}, {0, 3, 3.8`}, {0, 4, 4}, {1, 0, 0}, {1, 1, 1.5`}, {1, 2, 2}, {1, 3, 2.3`}, {1, 4, 2.5`}}; expr = (Vmax (S))/((1 + Inh/Ki) Km + S); Manipulate[ Show[{Plot[(Vmax (S))/(Km (1 + (Inh/Ki)) + S), {S, 0, 4}, PlotRange -> {{0, 5}, {0, 5}}], ListPlot[data2D, PlotMarkers -> {\[FilledCircle], 10}]}], {Vmax, 0, 5}, {Km, 0, 5}, {Inh, 0, 1}, {Ki, 0.1, 1}]
|
Pages: 1 Prev: Symplify Table Next: List Manipulation: Conditionally changing y value |