lcsim/test/org/lcsim/fit/line
diff -N SlopeInterceptLineFitterTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SlopeInterceptLineFitterTest.java 28 Mar 2006 04:51:18 -0000 1.1
@@ -0,0 +1,63 @@
+/*
+ * SlopeInterceptLineFitterTest.java
+ *
+ * Created on March 27, 2006, 7:35 PM
+ *
+ * $Id: SlopeInterceptLineFitterTest.java,v 1.1 2006/03/28 04:51:18 ngraf Exp $
+ */
+
+package org.lcsim.fit.line;
+
+import java.util.Random;
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class SlopeInterceptLineFitterTest extends TestCase
+{
+
+ /** Creates a new instance of SlopeInterceptLineFitterTest */
+ public void testSlopeInterceptLineFitter()
+ {
+ Random r = new Random();
+ SlopeInterceptLineFitter fitter = new SlopeInterceptLineFitter();
+ double[] pars = {8.2, 1.5};
+ int npoints = 10;
+ int nparams = pars.length;
+ double[] x = new double[npoints];
+ double[] y = new double[npoints];
+ double[] sigma = new double[npoints];
+ double eps = .01;
+
+ double x0 = 0.;
+ double delta = 1.;
+ for(int i = 0; i<npoints; ++i)
+ {
+ x[i] = x0+i*delta;
+
+ for(int j=0; j<pars.length; ++j)
+ {
+ y[i]+=pars[j]*Math.pow(x[i], j);
+ }
+ // now smear the measurement
+ y[i]+=r.nextGaussian()*eps;
+ sigma[i] = eps;
+ }
+
+ boolean success = fitter.fit(x, y, sigma, npoints);
+ assertTrue(success);
+ SlopeInterceptLineFit fit = fitter.getFit();
+ System.out.println(fit);
+ double slope = fit.slope();
+ double slopeErr = fit.slopeUncertainty();
+
+ assertEquals(pars[1],slope,5*slopeErr);
+
+ double b = fit.intercept();
+ double bErr = fit.interceptUncertainty();
+ System.out.println(b+" +/- "+bErr);
+ assertEquals(pars[0],b, 5*bErr);
+ }
+}