LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

levenberg Marquardt: how to use a decimal as an exponent? it only works with integers!

Hi,
 
I use LV 6.1 and I want to use the Levenberg-Marquardt algorithm to extract the best fit coefficients for the following equation:
 
Y =A*(X-B)^(1.7)
 
The data I input are X and Y (that I know)  and I expect the vi to display A and B. I also input approximate values of A and B. It works perfectly well for Y=A*(X-B)^2 or for any integer but neither for (1,7), nor for  1.7 or (17/10).
Has anyone an idea how to use a decimal number as an exponent? Is there another vi I can us?

 
Any help appreciated,
 
Nicooo
0 Kudos
Message 1 of 12
(3,956 Views)

You need to ensure that (x-b) is positive.

 

Quote from the help:

 

If x is not complex, it must be greater than zero unless y is an integer value. Otherwise, the result is NaN.

Message Edited by altenbach on 01-08-2009 09:56 AM
Message 2 of 12
(3,951 Views)

Glups! I didn't see that. Thanks a lot

 

0 Kudos
Message 3 of 12
(3,914 Views)

Now I'm sure that (x-b) is positive. However I get another problem: if it works when I input a decimal number as an exponent, the fitting coefficients I get are now automatically equal to zero.
The good point is that I no longer get NaN but I'm not really satisfied with these new fitting coefficients. Do you have an idea?

 

0 Kudos
Message 4 of 12
(3,893 Views)

nicoooooo wrote:

if it works when I input a decimal number as an exponent, the fitting coefficients I get are now automatically equal to zero.


Well, if the fit with all zero parameters is the best possible solution you're fine. 🙂 I suspect that your initial parameter estimates are way off. You should always calculate and display the curve as calculated with the initial estimates. Does it look anything like the data? Does it have similar features?

 

Does the VI say it's coverged? Is there an error? How many iterations did it do?

 

If you don't mind, attach your VI and some typical data and I'll have a look. 

Message 5 of 12
(3,884 Views)

Well, I don't think my initial parameters are the problem, because it works perfectly with a value of the exponent equal to 2 for example, but not for 2.1.

the vi computes 1000 iterations. Concerning the errors,for example  if I input 1.7 I will get  NaN for the coefficients and 0 for the error
If I input 1,7 as an exponent I get 0 for the coefficients but 23001 for the error.

I've attached two vis and somme typical data. I hope you will have a better idea than me
Thank you for your help

0 Kudos
Message 6 of 12
(3,845 Views)

Ouch!

 

(Doing a simple fit should not requre a 10-frame stacked sequence, 20+ property nodes and local variables, 20+ sequence locals, and at least three greedy loops. All you probably need is a flat diagram the size of a postcard.)

 

Have you tried a decimal point instead of a comma in the model description?

 

Even with an exponent of 2, the fit is very poor. maybe you need to use better initial estimates?

Message 7 of 12
(3,824 Views)

I admit that a simple fit like this one should not require such a big machine. In fact I cut the sequel of the vi in order to make it a little bit more understandable (I know, I'a a beginner with Labview :). I'm sure it's possible to simplify it later.
Otherwise I've tried to use a decimal point or a comma in the model description and neither one nor the other works. It's true that even with an exponent of 2 the fit is poor but simply moving the cursor to a better place allows to better it.
I'll have a look on these greedy loops and on different guess coefficients.

Thanks

 

 

0 Kudos
Message 8 of 12
(3,803 Views)

Sorry, I haven't had time to investigate further.

 

One of the probems is your ancient LabVIEW version. Starting with LabVIEW 8.0, the fitting tools have received significant improvements. Personally, I would always prefer the VI model, but that's not available pre-8.0 (at least not in an easy to use form). You only have very few parameters, so it should be easy to write a small program that interactively simulates the model curve so you can simply look at it while playing with the paramters. This should give you strong clues on what initial parameters to use.

 

Maybe I have time to look into this later this week.

Message 9 of 12
(3,788 Views)

Well I finally solved my problem. Instead of fitting a*(x-b)^1.7 to my data y, I've fitted 1.7*X+B to Ln(y), where X is equal to Ln(x-b) and B is equal to Ln(a).

The problem was that with this solution at the end I could only get B, i.e a. Unfortunately, the data I really wanted was b. So I integrated to the vi a for loop which made vary b between two acceptable limits. Then for each value of b I actualised the table of data (x-b) and I performed the levenberg-Marquardt vi following the equation 1.7*X+B. To finish, the best b coefficient was determined by finding the least mean square error performed in the loop and by taking the corresponding best fit coefficient.
I hope I'm clear enough but I'm neither a regular english speaker nor an experienced programmer.

Thanks for the help
0 Kudos
Message 10 of 12
(3,751 Views)