04-28-2009 04:30 PM
Hello,
I have the 8.6 developer package and am relatively new to labview. First time post, but these boards have solved many of my problems already. Thanks! My luck ran out though...
I had been working on a recursive function to fit to a set of non linear data, when I stumbled upon the lev-mar function. What a great find...it works very well. However I was trying to determine what the criteria was for the output named "f'(X,a)" from the reference to the static VI that holds the function for the lev-mar to fit to. The function performs well without it as it will calculate the slopes on its own if the gradient array is empty, but it takes a little more time and I'm trying to speed it up a bit.
The example "Fit gaussian surface with offset.vi" is the only example I could find where the f'(X,a) output from the reference to the function VI was populated, but I'm a bit rusty with my math and wasn't able to reverse engineer exactly what values they had going into that array should be.
I would like to be able to fill the f'(X,a) array with data for a 2d curve, as opposed to the 3d surface found in the example "Fit gaussian surface with offset.vi". Attached is a screenshot from the example showing the output to the f'(X,a) example.
Thank you very much!
-Bill
Solved! Go to Solution.
04-28-2009 05:33 PM - edited 04-28-2009 05:34 PM
If you don't provide the analytical partial derivatives, LabVIEW will automatically use numerical partial derivates. You can look at the labview code in detail to see how it does it, just open the VI and look for "LM numeric gradient.vi"
I don't know what a "recursive function" is in this context, but do have an analytical expression for the partial derivatives?
Even if analytical partial derivatives are not possible, it may be of advantage to do your own partial derivatives inside the model. It seems to be significanlty faster.
What you would basically do is calculate the function several times, each time with one of the parameters incremented by a small delta and subtract the function calculated with the plain current parameters from each and devide the result by the delta. Make all into a 2D array for the f'(X,a) output.
The image shows one way to do all this inside the model. The black square is a dummy where you would substitute you own function (f(x,a)).
Let me know if you have any questions.
04-29-2009 09:56 AM
Here is a small project that might help. It fits a simple exponential with offset, and the model function computes the partial derivatives explicitly.
-Jim
04-29-2009 02:06 PM
Thank you both for the fast responses and examples. I've implemented the method shown in Altenbach's screenshot and I think I have to do some more experimenting to get it to perform as quickly as the operation without f'(a,x).
I'm working on implementing the analytical partial derivates and expect that should work better (less number crunching!).
Thanks again!
-Bill
04-29-2009 04:52 PM
If you can do analytical derivatives, that would of course be best.
BillView wrote:Thank you both for the fast responses and examples. I've implemented the method shown in Altenbach's screenshot and I think I have to do some more experimenting to get it to perform as quickly as the operation without f'(a,x).
This is somewhat surprising and should not be the case, because the built-in algorithm uses a fancier derivative calculation that requires more function calls per iteration. When testing speed, make sure that the model subVI is saved and closed. How do you measure speed? How many parameters do you have? How complicated is your model?
Usually the built-in numerical derivatives are OK, but I have a very complicated model that requires fine-tuning of the derivative calculation, because the delta must be different for different parameters and cannot be a function of the parameter value. In my case, I actually provide an array of deltas via the variant input, one for each parameter and also autoindex it on the first and last small FOR loop.
05-14-2014 02:18 PM - edited 05-14-2014 03:16 PM
Just as a followup:
note that the central FOR loop that does all the heavy lifting can be parallelized for a N-time speedup. See here for an example application.