LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic constrains in non-linear curve fit

Solved!
Go to solution

I understand that we can provide hard boundary conditions as min and max values of the fit variables in the non-linear curve fit VI; Say I have a model as the sum of 3 Gaussians, and I want to know how to give constraints like a1>a2>a3, where a1,a2,a3 are amplitudes of each Gaussian (also the fit variables).
I wanted to ensure that my 2nd gaussian will be of lower amplitude that first, similarly between 3rd and 2nd.

0 Kudos
Message 1 of 3
(1,388 Views)

Am I correct that when you say "1st, 2nd, 3rd", you are referring to the X position of the peaks of these Gaussians?

 

One way that many non-linear fitting algorithms work is to compute a "Goodness-of-Fit" (which is often "Mean-Square Error") measure on a set of Parameters, and then try to converge the Parameter set to the region with lowest MSE.  With the "added constraints" you are imposing, it gets a little messy, but I'd try something like the following:

  1. Look at your data.  Is it clear that you have three peaks, with the second and third diminished in size relative to the first?  If not, then no amount of clever curve fitting is going to be helpful in proving that "Black is White".
  2. Fit a single Gaussian.  Verify that it seems to be near what you call the First Peak.
  3. Try to fit two Peaks.  Many algorithms work by "moving" one or more Peaks based on which fits the "best" or the "worst", done by comparing their MSEs.  If you find the right peak has a higher amplitude than the left peak (and hence is in the wrong place), "inflate" its MSE by multiplying it by, say, 100.
  4. Once you've got two Peaks, add the third, using the same "inflation" rule.

You can also attempt to do all three peaks at once, starting with your three initial "guesses".  The trick is to adjust the MSEs based on your constraints (1 < 2 < 3) before deciding which point is the "worst" (and/or the "best").

 

I learned (and used) this technique a few (oh, my goodness --) decades ago when I was coding up the Nelder-Mead Simplex algorithm (in Pascal!), where "constraints" were discussed.  You might look up "Constraints in non-linear fitting algorithms" or something like that on the Web for a more authoritative suggestion.

 

Bob Schor

0 Kudos
Message 2 of 3
(1,349 Views)
Solution
Accepted by topic author rahul_manoj

@rahul_manoj wrote:

... give constraints like a1>a2>a3


 

You can re-parameterize your model and fit for transformed parameters, e.g. aa1, aa2, aa3 where:

 

aa1=a2-a1

aa2=a2

aa3=a3-a2

 

Now you can constrain aa1 and aa3 to be positive and your conditions are always fulfilled, independent of a2.

Message 3 of 3
(1,340 Views)