Igor built in function
mssmtrainee
I'm encountering a problem where I have to fit one set of data (image attached) with two different fittings: first part with linear fitting, the other part with polynomial. The problem here is that I have to FIND the BEST transition point where I can switch from the linear fitting to the polynomial fitting.
I wonder if Igor has a sort of built-in functions that deal with that kind of problems. Any Igor-suggestions or general suggestions regarding solutions to the problems will be appreciated. Thanks!
DisplayHelpTopic "User-Defined Fitting Function: Detailed Description[Conditionals]"
Substitute a polynomial for the second line fit expression. The tricky part is that it is very likely that you will need to use an epsilon wave with fairly large value for the break X value coefficient. Here is a description of what an epsilon wave does:
-------------------
Curve fitting uses partial derivatives of your fit function with respect to the fit coefficients in order to find the gradient of the chi-square surface. It then solves a linearized estimate of the chi-square surface to find the next estimate of the solution (the minimum in the chi-square surface).
Since Igor doesn't know anything about your fit function, it (he?) must use a numerical approximation of the derivatives, which are calculated by finite differences. That is, a model value is calculated at the present estimate of the fit coefficients, then each coefficient is perturbed by a small amount and the derivative is calculated from the difference.
The epsilon wave sets the size of the perturbation used to calculate the derivative. If you don't use an epsilon wave, Igor sets epsilon to:
if your coefficient wave is single precision,
eps[i] = 1e-4*coef[i], unless coef[i] is zero, in which case eps[i] = 1e-4
if your coefficient wave is double precision,
eps[i] = 1e-10*coef[i], unless coef[i] is zero, in which case eps[i] = 1e-10
There are a couple of reasons you might need to explicitly set the epsilon. One is if your fit function is insensitive to a coefficient. That is, perturbing the coefficient makes a very small change in the model value. You can get a situation where the dependence of the model is so small that floating-point truncation results in no change in the model. You have to set epsilon to a sufficiently large value that the model actually changes when the perturbation is applied.
Another case where you need to set epsilon is where the model is discrete or noisy. This can happen if the model involves a table look-up or a series solution of some sort. In the case of table look-up, epsilon needs to be large enough to make sure you get two different values out of the table.
In the case of a series solution, you have to stop summing terms in the series at some point. If the truncation of the series results in less than full floating-point resolution of the series, you need to make sure epsilon is large enough that the change in the model is larger than the resolution of the series. A series might include something like a numerical solution of an ODE (using IntegrateODE). It could also involve FindRoots or Optimize, each of which gives you an approximate result, and run faster if you don't demand high precision.
-------------------
You need an epsilon wave in this case because the chi-square value only makes big changes when the breaking point crosses a data point. So my recommendation is to make the epsilon for that coefficient be about the same size as the X spacing between data points.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
March 16, 2012 at 02:22 pm - Permalink
* Differentiate the data to find the transition point.
* Fit the linear part over a short range where you know the polynomial absolutely does not apply. Extend the linear fit line and subtract it from all the data to find the transition point.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
March 17, 2012 at 06:46 am - Permalink