Hi Niels,

for constraining, you need a UserFunction, then you don't need to modify

the CurveFitter. Here is an example for a linear fit, where you restrict

the slope

Class ... implements UserFunction

public double userFunction(double[] params, double x) {

if (params[1] > 5 || params[1] < -5) return Double.NaN;

else return params[0] + x*params[1]; //usual linear function

}

CurveFitter cv = new CurveFitter(xData, yData);

cv.doCustomFit(this, /*numParams=*/2, "y=a+b*x constrained",

/*initialParams=*/ null, /*initialParamVariations=*/null,

/*showSettings=*/false);

For best convergence, specify the setOffsetMultiplySlopeParams if

possible, but not for parameters with restricted range.

Michael

________________________________________________________________

On 04.02.21 16:02, NielsMimetas wrote:

> Hi all,

>

> I'm using the curve fitting plugin and want to add constraints to my

> variables.

> For example, lets say that the a-variable can only go from -5 to +5. How

> would I do this?

> I already have the source code of the Curve fitting open, so I can make

> adjustments to the code, I'm just not sure where.

>

> I read a comment from Michael Schmid, who said the following:

> /concerning (1), restricting parameter ranges:

> You can have a function that returns NaN if the parameter enters an

> invalid range. Then the CurveFitter will avoid this range.

> Convergence will be rather bad if the best fit lies very close to a 'NaN

> boundary', however./

> Link:

>

http://imagej.1557.x6.nabble.com/fitting-y-f-x-data-to-arbitrary-functions-in-ImageJ-tp5020273p5020312.html>

> Can someone explain how I would go about this? Where would this function be

> called from? Where in the original code are these parameters requested and

> thus need the NaN be returned?

>

> Thanks in advance,

>

> Niels

>

>

>

> --

> Sent from:

http://imagej.1557.x6.nabble.com/>

> --

> ImageJ mailing list:

http://imagej.nih.gov/ij/list.html>

--

ImageJ mailing list:

http://imagej.nih.gov/ij/list.html