LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Non-linear curve fiutting help needed

Solved!
Go to solution

You forgot to wire the variant to the fit VI! 😉

 

Here's a quick modification that seems to work just fine. Note: you don't need a temperature control in the model subVI. Just use a diagram constant, the value is irrelevant. Also "index array is resizeable, so you can get both slices at once.

 

Message Edited by altenbach on 06-01-2009 09:44 PM
Download All
0 Kudos
Message 11 of 17
(1,886 Views)
I think it is another oops moment for me.  For some reason I was only thinking of connecting it to the data input on the call by reference node (becuase it had the data input) and I didn't even think to check the actual non-linear fitting vi.

Thanks so much for the help here, it is much appreciated.

Now I need to work out why the weighting vi doesn't want to work for me! 🙂

Thanks again.
0 Kudos
Message 12 of 17
(1,875 Views)

So I thought I had sorted out my fitting algorithm problem, and to some extent I have.  I can now put data in and get it to fit (I was able to do this after that last message).  My problem now, however, is that I finally have some real data (although it isn't particularly great) and I was just tryings to fit it to my theory just to have a play around with things.  What I have realised is that one of my fitting parameters doesn't not appear to be acting as a variable most of time.  I have 3 variables, these are G, kappa (I acutally use the symbol) and hm and in the fit function these are a1, a2 and a3, respectively.  My problem is typcially when I put in a value for kappa in the initiall fitting parameters, it remains the same after the fit.  So effectively, the other two variables are actually varying but kappa is not.  It is important for my work that kappa be allowed to vary vary whilst the data is being fitted.  I have looked through the code and I can't seem to find any reason as to why I am having this trouble.

 

I am using LV 8.6.1 and I have included my vis and my data in a zip file.

 

Thanks again for any help that you can give.

0 Kudos
Message 13 of 17
(1,825 Views)

I have not fully inverstigated this, but my best guess is that your matrices become ill conditioned because some of your parameters differ by a factor of 10e20.

 

For example if you would multiply G with 1e-12 and kappa with 1e8 inside the model and use initial paramters of 1,1,0 (~within a factor of 10), everything works perfectly. So maybe try some better scaling. Just scale the result back after the fit.

 

On a side note, long ago I wrote a drop-in replacement for the nonlinear curve fit that uses Nelder-Mead (simplex) instead (no matrices and no partial derivatives!) and it works perfectly with your data if the initial simplex is scaled properly (see image below). It gives the same result and same residual as the scaled workaround.

I will probably release it to the public sometime after NI week, so stay tuned. 

 

 

Note that the fit is not great near the edges, because you are downweighting these parts significantly. I guess that's want you want.

 

 

 

 

Message Edited by altenbach on 07-27-2009 01:26 AM
0 Kudos
Message 14 of 17
(1,820 Views)
So rather than have the multiplication factors (ie the 1e-12 for the PE data and kappa with 1e8) as inputs in the variables, actually place them (maybe as control inputs so that I can vary the multiplication factor if required) within the model itself?
0 Kudos
Message 15 of 17
(1,815 Views)

Here's one possibility to stabilize the fitting. The factors can easily be wrong by a few orders of magnitude, so you can probably keep them as diagram constants as shown here. I use the data variant to tell the model what the factors are.

 

 

I also cleaned up some of the code. Do you really need four (!) diagram comments to label what (X) and (Y) are? One is enough (see image above). I also placed the parameter names into the captions so they stay with the controls and indictators.

 

See if this makes sense.

Message Edited by altenbach on 07-27-2009 08:49 AM
Download All
0 Kudos
Message 16 of 17
(1,806 Views)
Thanks for that altenbach.  I had been thinking of using data variants as well (this was after you initial message yesterday and just before I was heading home).  But the approach I was thinking of was a bit more cumbersome than the more elegant approach you have used.  The reason I had been thinking of using controls is that the factors do seem to change on occaison by a couple orders of magnitude and was trying to avoid that.  But if I don't need to worry so much about that, then that is good.  And I just realised that if I do need to convert these constants to controls that is easy enough to do (will keep it as it is at the moment though) 🙂

Also I would like to thank you for cleaning up the code, it is much appreciated and the only excuse I have for
using four diagram comments to label what (X) and (Y) is oops!! 🙂

Also I forgot to mention yesterday, thanks for the heads up on your code replacement of for the non-linear curve fit.  I will keep an eye out for it.  Thanks.
0 Kudos
Message 17 of 17
(1,785 Views)