LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Non Linear Lev-Mar Function - Gradient Array Output of Function Reference?

Solved!
Go to solution

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 

0 Kudos
Message 1 of 6
(3,772 Views)
Solution
Accepted by topic author BillView

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.

Message Edited by altenbach on 04-28-2009 03:34 PM
Message 2 of 6
(3,760 Views)

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

 

 

Message 3 of 6
(3,725 Views)

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

0 Kudos
Message 4 of 6
(3,705 Views)

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.

Message 5 of 6
(3,688 Views)

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.

0 Kudos
Message 6 of 6
(2,634 Views)