joptima
Class ChiSquaredFitter
- java.lang.Object
-
- joptima.Fitter
-
- joptima.ChiSquaredFitter
-
- All Implemented Interfaces:
- Function, Minimizable
public class ChiSquaredFitter extends Fitter
χ² fitter. This class can be passed to a
Minimizerto minimize χ² of a sum of one or more functions fit to the given data set. Error bars may be provided for the data points if the data has compounded errors that are Gaussian. sqrt(y) errors are assumed otherwise. For different likelihood functions you can extend thecalculate()method on this class.A typical usage of this class would go as follows:
// The data points. double[] x = new double[]{ 1, 2, 3, 4, 5}; double[] y = new double[]{1.1, 4.0, 8.7, 15.4, 26}; // TheFunctionto fit to the data points. Function f = new Quadratic(); ChiSquaredFitter fitter = new ChiSquaredFitter(); fitter.setData(x, y); fitter.addFunction(f); Minimizer.minimize(fitter); // At this point, if the fit converged, theFunctionf will have // itsParameters set to the optimal values.
-
-
Constructor Summary
Constructors Constructor and Description ChiSquaredFitter()Constructor.ChiSquaredFitter(double[] x, double[] y)Constructor.ChiSquaredFitter(double[] x, double[] y, double[] errors)Constructor.ChiSquaredFitter(double[] x, double[] y, double[] errors, Function f)Constructor.ChiSquaredFitter(double[] x, double[] y, Function f)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublecalculate()Calculates the χ² given parameter values set by aMinimizerusing reflection.voidsetData(double[] x, double[] y)Fit the sum of functions to this set of points.voidsetData(double[] x, double[] y, double[] errors)Fit the sum of functions to this set of points.-
Methods inherited from class joptima.Fitter
addFunction, calculate, getName, getParameters, removeAllFunctions, setName
-
-
-
-
Constructor Detail
-
ChiSquaredFitter
public ChiSquaredFitter()
Constructor.
-
ChiSquaredFitter
public ChiSquaredFitter(double[] x, double[] y)Constructor. Assumes sqrt(y) errors.- Parameters:
x- the x coordinates of pointsy- the y coordinates of points
-
ChiSquaredFitter
public ChiSquaredFitter(double[] x, double[] y, double[] errors)Constructor.- Parameters:
x- the x coordinates of pointsy- the y coordinates of pointserrors- the error bars on y coordinates of points
-
ChiSquaredFitter
public ChiSquaredFitter(double[] x, double[] y, Function f)Constructor. Assumes sqrt(y) errors.- Parameters:
x- the x coordinates of pointsy- the y coordinates of pointsf- theFunctionto fit to the given set of points
-
-
Method Detail
-
setData
public void setData(double[] x, double[] y)Fit the sum of functions to this set of points. Assumes sqrt(y) error bars.- Parameters:
x- the x coordinates of pointsy- the y coordinates of points
-
setData
public void setData(double[] x, double[] y, double[] errors)Fit the sum of functions to this set of points.- Parameters:
x- the x coordinates of pointsy- the y coordinates of pointserrors- the error bars on y coordinates of points
-
calculate
public double calculate()
Calculates the χ² given parameter values set by aMinimizerusing reflection. The formula is:for each point in the data set { f = 0 for eachFunction{ f +=Function.calculate(double)(x[point]) } χ² += (y[point] - f)² / error[point]² }
-
-
DMelt 3.0 © DataMelt by jWork.ORG