Fit a 5d hyperplane by n points, using the linear fitter directly
This macro shows some features of the TLinearFitter class A 5-d hyperplane is fit, a constant term is assumed in the hyperplane equation (y = a0 + a1*x0 + a2*x1 + a3*x2 + a4*x3 + a5*x4)
0.0198590755463
3.7181520462
Processing /mnt/build/workspace/root-makedoc-v614/rootspi/rdoc/src/v6-14-00-patches/tutorials/fit/fitLinear2.C...
par[0]=0.000069+-0.001011
par[1]=3.999934+-0.000164
par[2]=0.999835+-0.000172
par[3]=1.999892+-0.000178
par[4]=2.999967+-0.000185
par[5]=0.199823+-0.000174
chisquare=70.148012
More Points:
par[0]=0.000551+-0.000712
par[1]=3.999910+-0.000121
par[2]=0.999886+-0.000125
par[3]=2.000067+-0.000123
par[4]=2.999915+-0.000127
par[5]=0.199918+-0.000130
chisquare=145.050322490891915
Without Constant
par[0]=3.999913+-0.000121
par[1]=0.999890+-0.000125
par[2]=2.000057+-0.000123
par[3]=2.999919+-0.000127
par[4]=0.199918+-0.000130
chisquare=145.649621
Fixed Constant:
par[0]=0.000536+-0.000712
par[1]=4.000000+-1.000000
par[2]=0.999884+-0.000125
par[3]=2.000070+-0.000123
par[4]=2.999910+-0.000127
par[5]=0.199920+-0.000130
chisquare=145.602523231222818
void fitLinear2()
{
x[0 + i*5] = randNum.
Uniform(-10, 10);
x[1 + i*5] = randNum.
Uniform(-10, 10);
x[2 + i*5] = randNum.
Uniform(-10, 10);
x[3 + i*5] = randNum.
Uniform(-10, 10);
x[4 + i*5] = randNum.
Uniform(-10, 10);
e[i] = 0.01;
y[i] = 4*x[0+i*5] + x[1+i*5] + 2*x[2+i*5] + 3*x[3+i*5] + 0.2*x[4+i*5] + randNum.
Gaus()*e[i];
}
for (
Int_t i=0; i<6; i++)
printf("par[%d]=%f+-%f\n", i, params(i), errors(i));
printf("chisquare=%f\n", chisquare);
for (i=n; i<n*2; i++) {
x[0+i*5] = randNum.
Uniform(-10, 10);
x[1+i*5] = randNum.
Uniform(-10, 10);
x[2+i*5] = randNum.
Uniform(-10, 10);
x[3+i*5] = randNum.
Uniform(-10, 10);
x[4+i*5] = randNum.
Uniform(-10, 10);
e[i] = 0.01;
y[i] = 4*x[0+i*5] + x[1+i*5] + 2*x[2+i*5] + 3*x[3+i*5] + 0.2*x[4+i*5] + randNum.
Gaus()*e[i];
}
printf("\nMore Points:\n");
for (
Int_t i=0; i<6; i++)
printf("par[%d]=%f+-%f\n", i, params(i), errors(i));
printf("chisquare=%.15f\n", chisquare);
printf("\nWithout Constant\n");
for (
Int_t i=0; i<5; i++)
printf("par[%d]=%f+-%f\n", i, params(i), errors(i));
printf("chisquare=%f\n", chisquare);
printf("\nFixed Constant:\n");
for (i=0; i<6; i++)
printf("par[%d]=%f+-%f\n", i, params(i), errors(i));
printf("chisquare=%.15f\n", chisquare);
delete lf;
}
- Author
- Anna Kreshuk
Definition in file fitLinear2.C.