LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

non-linear sigmoid curve fitting

I'm trying to do some non-linear curve fitting to a sigmoid equation using the Curve Fitting Express vi but I can't seem to get it working.  I'm a novice to curve fitting, but I was able to get a nice fit using the graphing program SigmaPlot and I'm trying to copy that in Labview.  The Curve Fitting Express vi seems to parse the equation from SigmaPlot ok but I can't get it to do a fit.  I've tried varying the inital parameter values a lot - including those found by SigmaPlot - but it won't do the fit.  I've attached screen caps of the Labview vi as well as the SigmaPlot output.  Any suggestions appreciated.

 

The sample data set:

X Y

1 66
2 76
3 80
4 82
5 102
6 101
7 31
8 48
9 0
10 0
11 1
12 1
13 1
14 1
15 1
16 13

 

SigmaPlot Report:

 

Nonlinear Regression   

Data Source: Data 1 in Notebook1
Equation: Sigmoidal, Sigmoid, 3 Parameter
f= a/(1+exp(-(x-x0)/b))

R  Rsqr  Adj Rsqr  Standard Error of Estimate

0.9415 0.8865 0.8690  14.6281 

  Coefficient Std. Error t P 

a 83.2690 6.7702 12.2993 <0.0001 
b -0.6582 0.3302 -1.9935 0.0676 
x0 7.5787 0.3848 19.6954 <0.0001 

Analysis of Variance:

Analysis of Variance:
  DF SS MS 
Regression 3 44518.2282 14839.4094 
Residual 13 2781.7718 213.9824 
Total 16 47300.0000 2956.2500 

Corrected for the mean of the observations:
  DF SS MS F P 
Regression 2 21717.2282 10858.6141 50.7453 <0.0001 
Residual 13 2781.7718 213.9824 
Total 15 24499.0000 1633.2667 

Statistical Tests:

Normality Test (Shapiro-Wilk)   Passed (P = 0.3040)

W Statistic= 0.9361 Significance Level = 0.0500

Constant Variance Test  Passed (P = 0.1360)

Fit Equation Description:
[Variables]
x = data(1,size(col(1)))
y = col(1)
reciprocal_y = 1/abs(y)
reciprocal_ysquare = 1/y^2
'Automatic Initial Parameter Estimate Functions
sup(q)=if(mean(q)>=0, max(q), min(q))
b1(q,r)=if(sup(r)>0, xwtr(q,r,.5)/4, -xwtr(q,r,.5)/4)
[Parameters]
a = sup(y) ''Auto {{previous: 83.269}}
b = if(b1(x,y)=0, 1, b1(x,y)) ''Auto {{previous: -0.658229}}
x0 = x50(x,y,.5) ''Auto {{previous: 7.57868}}
[Equation]
f= a/(1+exp(-(x-x0)/b))
fit f to y
''fit f to y with weight reciprocal_y
''fit f to y with weight reciprocal_ysquare
[Constraints]
[Options]
tolerance=1e-10
stepsize=1
iterations=20

Number of Iterations Performed = 15

 

 

Download All
0 Kudos
Message 1 of 5
(5,668 Views)

I forgot to attach the block diagram...

0 Kudos
Message 2 of 5
(5,658 Views)

Hi,

 

I've set up the vi using your data, and it seems to me that the trick to getting LabVIEW to do the fit correctly is having the signs of the guesses correct. I was able to get the fit you had in your other code using the guesses of a=0, b=-1, x0=0. I noticed in the screen shot you posted that you were using a positive b guess. If you are still having trouble getting it to do the fit, you might also try rewriting your equation so that all of the variables are positive in the correct fit.

 

I hope this helps,

 

Regards,

Luke B.

0 Kudos
Message 3 of 5
(5,617 Views)

Thanks for your help.  I didn't notice the sign of b.  How can I get the resulting values out?  The "non-linear coefficients" output only give X0 but not the others.  I want to be able to get a corresponding X value on the curve from putting in a Y value.  I was thinking of solving the model formula with the resulting values from the curve fit in order to do this.  Is there an easier way?

 

Thanks again.

0 Kudos
Message 4 of 5
(5,590 Views)

Connect a numeric array instead of a scalar to the output. 😉

0 Kudos
Message 5 of 5
(5,586 Views)