Re: Extending user-defined equations in Fit.doFit
Posted by
dscho on
Apr 18, 2011; 8:43am
URL: http://imagej.273.s1.nabble.com/Extending-user-defined-equations-in-Fit-doFit-tp3684931p3684934.html
Dear Daniel,
On Sun, 17 Apr 2011, Barboriak, Daniel wrote:
> Adding the capability to fit user-defined equations to the macro
> functions is great.
>
> One thing that would allow this to be extended further would be if the
> user-defined equations would recognized user-defined functions. For
> example:
>
>
> x=newArray (0.8,0.82,0.84);
> y=newArray (14.8393,14.7143,14.7356);
>
> function tqrt(xx) {
> yy = sqrt(xx);
> return yy;
> }
>
> guessArray = newArray(3,5);
>
> Fit.logResults;
> Fit.doFit("y=a*tqrt(x)+b", x, y, guessArray);
>
>
> does not work because tqrt is not recognized in the Fit.doFit line. Is
> there a workaround for this?
>
> My plan would be to use the user-defined function to process arrays (for
> example, integrating a trimmed array, multiplying elements by
> exponentials, etc).
I fear that macros are the wrong language for the job. It is quite
expensive to evaluate them, and a fit requires quite a number of
evaluations.
So even if it would be possible to support the operation you asked for, it
might still not solve your issue to your satisfaction.
A better method, if you ask me, is to use a powerful scripting language
such as Javascript or Jython in conjunction with Commons Math to calculate
the fit, possibly using Albert Cardona's fantastic Weaver for tremendous
speed-up:
http://pacific.mpi-cbg.de/Jython_Scripting#Inline_java_code_inside_jython:_the_WeaverCiao,
Johannes