LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

levenberg marquardt sub VI - LM abx vi

Hi all -


When using the Nonlinear Curve Fit VI, I was getting the same error that a lot of people in the forum seem to be getting, namely that the optimization won't work because there is at least one Inf / NaN / etc.

 

I tried finding out where that was coming from and found that the LM abx sub-VI gives me zeroes for alpha, beta, and chisqr matrix (see probes 315-317), but once the values come out of that subVI they report as NaN (see probes 303-306)... somehow they seem to switch values which ruins everything past that point.  (I apologize if the picture is confusing but I was trying to show several things at once.)


So I have two questions - 1) Does anyone have any idea why this is happening or have any suggestions?


2)  What do alpha and beta correspond to in LM calculations?  (I have looked at how LM works but I'm not sure what they represent.  Inside the abx sub-vi are some other VIs but you can't probe / highlight, so it's hard to gauge what they're doing.)

 

 

Thanks for any help.

 

 

problem3.JPG

0 Kudos
Message 1 of 20
(4,153 Views)
ABX is reentrant, meaning each diagram instance is unique. You are looking at a clone. Are you sure you are looking at the correct instance?
0 Kudos
Message 2 of 20
(4,142 Views)

Dan K wrote: 

When using the Nonlinear Curve Fit VI, I was getting the same error that a lot of people in the forum seem to be getting, namely that the optimization won't work because there is at least one Inf / NaN / etc.


 

I virtually never get this problem.
 
Most likely, the problem is in your data and not in the system VIs. Can you attach your VI and some typical data?
 
What kind of model are you trying to fit?
Check for illegal operations (1/0, log or sqrt of a negative number, etc.) an make sure they don't occur.
Have you graphed the model with the guesses? Does it look anything like your data?
Does the array size of the parameter estimates correspond exactly to the number of parameters in the model (remember, array size is independent of the number of elements displayed. Resizing the container does not change the number of elements.)
0 Kudos
Message 3 of 20
(4,135 Views)

Thanks for your questions and help so far.  I know what you mean about the clone issue and I'm 99% sure that's not the problem.

 

If you'd like to play around with it, I attached a typical way to fill in the values on the FP (second image).  (If you are in this window and scroll down just a bit that's where I hide the outputs from the LM VI).  It's based on something called prism coupling, where you use a prism with a known refractive index and known prism angle to determine the refractive index of the unknown material.  (You rotate the prism thru an angle until the internal reflected light intensity increases to 100%, and then you've reached the critical angle which gives you the refractive index of the material.)

 

Initially, when I only had access to the most basic LabView package, what I did was put in a range of prism indices and unknown material indices and then plot those (tab 1) and they are listed left-to-right below the plot.  Then I wrote a chisquared calculation and on tab 2 you can find the 10 best (lowest chi squared) plots, so you can sort of see which prism and unknown material values match your plot the best.  This worked fine.

 

THEN I got access to professional development version, and tried implementing L-M per my boss' recommendation.  The problem with software for this is that the function curves up to y=1 and then above that it blows up to infinity (because of sine terms etc).  So what I tried to do was cut off values above 1 (hence the array being called "thetabelow1"). 

 

SOOOO there is a good chance it's my data and I understand that, but I don't understand why abx is shooting out NaN when I am watching the values inside abx report as zeroes.  (If you change the 1.69 and 1.49 values in the first image to something like 1.701 and 1.51 it does a better job, because it approaches from the other direction).

 

(Note, when I attached the VI the L-M didn't work because the computer I attached it from doesn't have the professional version (that's a laptop which will run the experiment and isn't online).  Simply replace the broken L-M VI when you download it and the broken arrow should go away.)

 

 Let me know if you have any thoughts on how to work with the data to get it into a format which the L-M can use, or if you know how I can find out what the sub-VIs do (still trying to figure out alpha and beta).  Thanks a lot!

 

 

screenshot2.JPG

 

 

 

screenshot.JPG

 

 

 

 

 

Download All
0 Kudos
Message 4 of 20
(4,124 Views)

Sorry, but I'm not going to wade through a VI with sequences stacked 22 deep swarming with local variables.

 

Can you reduce it to "outer frame 10", "inner frame 2" and replace the inputs with diagram constants or controls containing typical data. Thanks!

 

 

0 Kudos
Message 5 of 20
(4,115 Views)

Hah... I completely understand and would never ask that of anyone!  You only had to look at that frame.  But I extracted that frame and put it into this VI.  The problem is that the function is discontinuous at the critical angle, and so I don't think L-M can approach from above the angle, only from below.  I'm thinking of modifying inside of the L-M VI to somehow discern this.  But I need to know that abx is passing the right values, and I'm trying to figure out what alpha and beta are.

 

 

0 Kudos
Message 6 of 20
(4,100 Views)
oops... give me 5 minutes to give you the proper arrays, filled this time.
0 Kudos
Message 7 of 20
(4,094 Views)

Your controls (input indicators acting as controls via local variables in your case) are empty.

 

Turn them into controls (right-click...change to control) and get rid of the locals.

 

Make sure to make current values default before saving.

0 Kudos
Message 8 of 20
(4,091 Views)

here you go.  very typical values.  remember that the function is discontinuous past the last data point which is why the data set is chopped off there.  but it is continuous up to that point, and should be able to be matched by the function.  the right answers in this case are 1.5 and 1.7.

 

 

thanks again!

0 Kudos
Message 9 of 20
(4,086 Views)
ahh i see what you mean.  but the one i just sent will work because i made the values default.  (sorry, didn't see your last message until after i posted the second "abcd")
0 Kudos
Message 10 of 20
(4,084 Views)