forum.alglib.net
http://forum.alglib.net/

setting constraints in polynomial fit
http://forum.alglib.net/viewtopic.php?f=2&t=606
Page 1 of 1

Author:  actionbrandon [ Mon Aug 13, 2012 6:36 pm ]
Post subject:  setting constraints in polynomial fit

I'm sure there's a simple answer to this, but I'm stuck. I have a small set of that data that I am doing a polynomial fit on (data below). When I run (m=4):

Code:
alglib.polynomialfit(x, y, m, out info, out p, out rep);
alglib.polynomialbar2pow(p, out coeffs);


I get the results I am anticipating: {25.426138,0.092663,-0.000658,0.000001}

I would like to be able to weight this data, but when I run the polynomialfitwc function, I get different results. I set all w=1 (an array of equal length to x where all elements =1), and:

Code:
double[] xc = new double[] { 0 }; //constraints = 0
double[] yc = new double[] { 0 };
int[] dc = new int[] { 0 };


These settings give me the following coefficients: {0.000000,1.116681,-0.011579,0.000035}

What am I doing wrong? I'd like to set up the wc function so it returns that same as polynomialfit() if the weights are 1.

Thanks in advance. This package is really impressive.

Data:

X_1 Y_1
6 26
28 27.5
50 28.4
69 29.35
93 29.4
116 29.35
137 29.15
158 28.82
180 28.5

Author:  actionbrandon [ Fri Aug 17, 2012 2:48 pm ]
Post subject:  Re: setting constraints in polynomial fit

Came back to this and realized this is (as I figured) a simple syntax error. I'll post here in case this saves anybody some time in the future:

empty constraints should be set as:
Code:
            double[] xc = new double[0]; //constraints = 0
            double[] yc = new double[0];
            int[] dc = new int[0];

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/