Hi All,
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). Thanks! --db Daniel Barboriak, MD Duke University Medical Center |
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_Weaver Ciao, Johannes |
In reply to this post by Barboriak, Daniel
Actually this reminds me about the early days of JSP.
The idea is simple: you write some java code implementing a specific interface (possibly inlined in the macro code) and then the Editor should compile and load the class and do the fitting. Best regards, Dimiter Prodanov |
In reply to this post by Barboriak, Daniel
Hi All,
Thanks to Johannes, Dimiter and Michael Schmid (who replied to me off list) for their thoughts. You are thinking several moves ahead, which is the right way to do it. My thought in using a user-defined equation in Fit.doFit was to demonstrate a proof of concept for a later plugin. This would certainly not be efficient. No question that for a truly useful tool that would tackle complex curve fitting problems, efficiency of the function evaluation is key. I think whether this more efficient code was in the form of a Java plugin / Java code, Javascript and/or Jython, we could work with that. My understanding is that at the moment there is no way to interface any efficient code solution so that it can be used by Fit.doFit in a macro script (correct me if I'm wrong). Assuming we were able to write an efficient code for function evaluation, would writing a plugin that would include this code and call the existing curve fitting code be easy / practical, or are there better ways to interface the function evaluation code with the curve fitting code? Thanks again for your useful comments. --db |
Free forum by Nabble | Edit this page |