02-12-2010 04:57 PM
Done! It works! That saved me sooo much work! I love NI!
Quite sensitive to initial conditions...
Errors include: 1. Singularity errors.. 2. No solution..
Any suggestions for dealing with these errors at run-time? What other possible error conditions are there?
02-12-2010 05:02 PM
Darin, what do you mean you'll "let the partial derivatives slide"?
The partial derivatives for this function are available.
The problem is I have no idea about optimisation Theory..
The results attained from L-M are close to the results attained using Gradient Descent method (implemented by others for same test measurements).
Results from Gradient Descent method:
p1 = 383.4982
k = 0.4440
h = 2.5626
02-12-2010 05:06 PM
Gradient descent method:
k = -0.4440 (correction)
BTW thanks Darin.
02-12-2010 05:11 PM
Almost any time that I have the partial derivatives available I use them in the LM curve fit instead of letting the VI do the numerical approximation. In this case I was not in the mood to calculate them.
When I was young and learning to ski my model was to point my skies down the hill, and let 'er rip. This works when you are low to the ground and stick to easier ski slopes. Eventually you learn to traverse and then find that you can ski down much more difficult slopes. My point? The Gradient descent method is just "letting er rip", works for some problems, but not entirely robust. The LM method controls the descent in an intelligent way and let's you tackle more complex problems in a robust fashion.
02-12-2010 05:21 PM
I have the partial derivatives.
Will that lead to a more accurate solution? If so, why?
How would I implement the (3?) partial derivatives? Any differently? I will try to post them.
02-12-2010 05:25 PM
"Almost any time that I have the partial derivatives available I use them in the LM curve fit instead of letting the VI do the numerical approximation."
Is that what the LM algorithm does; numerically estimate the partial derivatives of the equation?
If I implement partial derivatives then how do I get the real quantities from the output?..
02-12-2010 05:38 PM
I have:
dp/dp1
dp/dp2
dp/dh
note: k = (p2 - p1)/(p2 + p1) //main equation changed to use p2 instead of k (easier to estimate initial value)
Basic Question:
I place the partial derivative functions into template. I only have measured values in terms of original equation. How to convert partial derivative solutions into pa (from original equation)??
02-12-2010 05:38 PM - edited 02-12-2010 05:43 PM
battler. wrote:"Almost any time that I have the partial derivatives available I use them in the LM curve fit instead of letting the VI do the numerical approximation."
Is that what the LM algorithm does; numerically estimate the partial derivatives of the equation?
If I implement partial derivatives then how do I get the real quantities from the output?..
The LM (or any fitting) routine needs the partial derivatives, it is only a matter of how they are calculated. In the LV implemenation, if you do not supply the partial derivatives, the VI uses a numerical estimate. This estimate requires two function evaluations (potentially time-consuming), and also involves subtraction of two potentially similar numbers giving rise to the potential of round-off error.
It seems to be working with the numerical estimatation, I'd suggest waiting for a real problem to arise before tackling this. I just like to point out that personally I am holding my nose every time I use the LM VI and don't supply the derivatives. If you do implement the partial derivatives, nothing else will change, the quantities you get back will be the same as before.
Edit: No need to "convert partial derivative solution". These partial derivates are used by the LM algorithm to find the direction of steepest descent. You don't need to worry about them. Check out the fitting chapter in "Numerical Recipes" for more details.
02-12-2010 05:47 PM
02-12-2010 05:53 PM
In your VI that calculates the f(x,a) you have a for loop which loops over the points (x). At each point x you find f(x,a) and build an array. So far so good. Now, inside this same for loop you build an array [df/da0,df/da1,df/da2..]. In this case you should calculate dpa/dp1, dpa/dk (or whatever you use now), and dpa/dh. Wire this array to the for loop so you build a 2D array and wire this to f'(x,a). That is all there is to it, the LM VI will detect that you have supplied the derivatives and use them instead of the numerical approximation.
If you want to get fancier (and it is a good habit to get into), use the output control and a case statement to only calculate the derivatives when the control is true. Saves some time, especially in your case where finding f'(x,a) is a bit more expensive than usual.