I have been experiencing very slow performance of NonlinearModelFit
. The code that in my case causes that is below. The first part gets the data, the model and constraints and initial values. This is because, I have huge amount of functions combined.
ClearAll[cdata, fmodel, fitparmsconstr, fitparmsinit];
{cdata, fmodel, fitparmsconstr, fitparmsinit} =
CloudGet[
"https://www.wolframcloud.com/obj/923620ca-ec70-43e3-b0f2-\
5f9311e14625"]
And now this takes insane amount of time, note that even with a single iteration, which should be immediate, it takes about two minutes.
NonlinearModelFit[cdata, {fmodel, fitparmsconstr}, fitparmsinit, x,
MaxIterations -> 1]
I realise that I have large amount of parameters, but when I did this model in FiTyk, it take 2 seconds to converge. I suspect there is some detail mathematica that i am missing. I cannot believe that with a single iteration it would be this bad.
(I am on Ma Linux 13.3.1.0)
Update on the purpose.
The data come from coupled mass spectroscopy (MS) with thermogravometric analysis (TGA). The problem with TGA is that when you compute the mass loss derivative (DTG curve), it has many peaks which are superimposed onto each other and impossible to resolve which peak is from what species or in other words how much of what species was lost. However, I do have data from mass spectroscopy for each chemical species so I know for say water, the peaks, where they occur and how wide they are. Those I fitted in FiTyk. And so for water, i have a sum of n1 gaussians, for CO2 I have sum of n2 gaussians etc.
Now come some assumptions (don't stone me for them). Basic assumption is that the peaks on MS are also gaussians. Next, I assume that when peak is observed in MS data, there should be a peak in the DTG (this is quite valid as the molecules in the system travel fast compared to the measure time), nevertheless there might be a bit of an offset between the peaks from MS to DTG data but this offset should be the same for each species (thus the first set of free parameters called \[Delta]c
with number denoting a specific species). Second assumption is that I do not know the peak heights in DTG data but the peaks should keep proportional, that is if peak 1 was twice as high as peak 2 for a particular specie, this relationship should be preserved, that gives another set of free parameters \[Delta]h
. Finally, the assumption is that the peaks should be more or less the same width, there can be some dispersion and the freedom for that constitutes the last set of parameters \[Delta]w
.
Now constraints are formed because even Fityk tends to fit the data with negative peaks or because the peaks tend to shift unreasonably too much.