Warm tip: This article is reproduced from serverfault.com, please click

Putting constraints on parameters of a parametric function in GNUPLOT

发布于 2016-04-12 07:28:27

I am trying to fit a model to some data. everything is OK so far. However I would like to apply some constraints on the parameters of my equation. For example suppose the following function: f(x)=a*sin(x)+b*cos(x*a/b). Suppose "a" and "b" are parameters; and suppose that you wanna fit this equation to some data and that the estimated value of "a" and "b" has to fall in specific different intervals. For example suppose the constraints: a >= 2.0 and 0.1 < b <= 1.0 So how can I tell to gnuplot to fit by taking into account the above constraints on the parameters "a" and "b"?

Since I wanna execute the fitting for thousands of curves. I would like to know if there is such a thing similar to an implicit do loop in Fortran; meaning execute the fitting on the data file containing all the curves one after the other?

Your help will be so much appreciated.

Questioner
Fill Ross
Viewed
0
Karl 2016-04-13 03:56:11

Limiting the fit range is not possible. You could modify the function using the ternary operator (e.g. 'a>2?a:1e300'), but there is a high possibility that your fit becomes unstable, and it is really bad style. ;)

Try to predict your parameters as well as possible to keep them from straying in forbidden regions. Fit the parameters seperately in the beginning, e.g. introduce one of them in a simpler function, only use a small part of the data where part of the parameters is irrelevant, etc. Only in the last step fit your full function with all parameters and the whole dataset.

And gnuplot does have do for [] {} and while () {} loops that you can use to iterate over your dataset. Before you ask: Array variables to save the fit parameters were only recently intruduced in the development version 5.1.