LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

complicated curve fitting

Thanks for the help.

 

Kas

0 Kudos
Message 11 of 24
(1,654 Views)

Found the Attached solution. I made it much easier to follow and run the attached VI. However, this simplex method keeps giving me the "maximum Iteration exeeded" error. I choose the initial values quite close to the original.

One main thing that I am not sure about this algorithm is that how would the algorithm know if the 2 variables are the correct values. On the Lev-Mar algorithm, you have a dependant input of "Y" at which the 2 variables are compared against the f(x) which is Y. but I don't see this input in Simplex algorithm.

 

Kas

0 Kudos
Message 12 of 24
(1,633 Views)

The Transmition and Reflection... subVI you included has a datatype conflict with the Nelder-Mead Modle Function VI.  It requires an array input but you have it wired to a scalar.

 

Please post the correction.

 

Lynn

0 Kudos
Message 13 of 24
(1,624 Views)

Apologies. I forgot to attach the the other version of "Transmition and Reflection... subVI". The array version of this VI is used to plot the results of the simulation at the end, and the scalar version is used within the model function. Attached is the VI for the model function.

 

Kas

0 Kudos
Message 14 of 24
(1,618 Views)

Attached is the UPDATED zip where it contains the jurnal paper where this algorithm comes from, as well as some comments on the "Main.vi", and hopefully it makes alittle more sence.I'm usually neet when it comes to programming, but I gues I'm getting abit restless since I've been on this issue for a while now.

 

Thanks

 

Kas

0 Kudos
Message 15 of 24
(1,610 Views)

It looks like the model function passed to the simplex algorithm is the same as the one passed to the Lev-Mar algorithm.  This is a problem.  Lev-Mar is structured for curve fitting.  The model that you pass to Lev-Mar is evaluated at the 'X' data points, and compared to the 'Y' data points.  Lev-Mar computes the distance between your model function and the 'Y' data points as:

DIST=SUM[(Model(i)-Y(i))^2

Lev-Mar is minimizing the sum of the squared errors between your model and the Y data. 

The simplex algorithm attempts to minimize the function you pass to it and does not construct this distance function for you.  You have to code this yourself in the model function you pass to the Simplex VI.  You can pass the X and Y data using the data variant, and subtract your current model function output(s) from the Y value(s), square, and then sum if you have more than one Y data value. 

 

-Jim

0 Kudos
Message 16 of 24
(1,592 Views)

Would you happen to have a simple example that demonstrate your point? i.e. a set of data that you fit using Lev-Mar, and the same but with this constrained difference that you mentioned using the Simplex method. This way, I can hopefully make the necessary changes to my model much easier.

 

Thank you

 

Kas

0 Kudos
Message 17 of 24
(1,588 Views)

Here is a simple exponential fit, done using Lev-Mar and NM Simplex.

 

-Jim

0 Kudos
Message 18 of 24
(1,574 Views)

Thanks for for the example. I now modified my Transfer function and the simulation seems to work. But, it keeps gicing out the "maximum iteration exceeded" error. No matter what numbers I put on the "stopping criteria", which is why perhaps I don't get a good fit. It starts of very well, but then it drops.

 

Is there a way of improving this? perhaps if there is a different optimization technique?

 

Thanks

 

Kas

0 Kudos
Message 19 of 24
(1,549 Views)

Kas,

 

One problem is a mismatch in the variant data.  Your model function is always generating numbers like 1E-86 for f(x) and the values coming from the data variant are always zero.  The clusters called Data in the Main VI and in the Nelder-Mead Model Function Vi are different.  I think this results in the data values being fed to Simlex by Main being converted to zeros in the Model Function VI.

 

The Mani VI cluster has {Echo Number, Sample Thickness, Frequency, Num} while the Model Function cluster has {Echo Number, Sample Thickness, Frequency, Sample Module, Sample Argument}.  Try making them the same!

 

Also, several of the calculations done inside the for loop in the model are done on values which do not change while the loop is running.  Move them outside the loop and only calulate them once.

 

Lynn

0 Kudos
Message 20 of 24
(1,541 Views)