ChiSquaredFitter2D
joptima

Class ChiSquaredFitter2D

  • All Implemented Interfaces:
    Function, Minimizable


    public class ChiSquaredFitter2Dextends Fitter

    χ² fitter. This class can be passed to a Minimizer to minimize χ² of a sum of one or more functions fit to the given two-dimensional data set. Error bars may be provided for the data points if the data has compounded errors that are Gaussian. sqrt(z) errors are assumed otherwise.

    Note that the usual two-dimensional matrix of values is passed to this function unfolded into a single array, i.e. the (x[i], y[i], z[i]) tuple for an m by n histogram where z = f(x, y) will have indices running from 0 through m * n - 1.

    A typical usage of this class would go as follows:

       // The data points.   double[] x = new double[]{  1,   2,   3,                               1,   2,   3,                               1,   2,   3};   double[] y = new double[]{  1,   1,   1,                               2,   2,   2,                               3,   3,   3};   double[] z = new double[]{1.1, 4.0, 8.7,                             3.9,  16,  24,                             9.2,  22,  38};   // The Function to fit to the data points.   Function2D f = new Sum2D(new Quadratic(), new Quadratic);   ChiSquaredFitter2D fitter = new ChiSquaredFitter2D();   fitter.setData(x, y, z);   fitter.addFunction(f);   Minimizer.minimize(fitter);   // At this point, if the fit converged, the Function f will have   // its Parameters set to the optimal values. 

    • Constructor Detail

      • ChiSquaredFitter2D

        public ChiSquaredFitter2D()
        Constructor.
      • ChiSquaredFitter2D

        public ChiSquaredFitter2D(double[] x,                  double[] y,                  double[] z)
        Constructor. Assumes sqrt(z) errors.
        Parameters:
        x - the x coordinates of points
        y - the y coordinates of points
        z - the z coordinates of points
      • ChiSquaredFitter2D

        public ChiSquaredFitter2D(double[] x,                  double[] y,                  double[] z,                  double[] errors)
        Constructor.
        Parameters:
        x - the x coordinates of points
        y - the y coordinates of points
        z - the z coordinates of points
        errors - the error bars on z coordinates of points
      • ChiSquaredFitter2D

        public ChiSquaredFitter2D(double[] x,                  double[] y,                  double[] z,                  Function f)
        Constructor. Assumes sqrt(y) errors.
        Parameters:
        x - the x coordinates of points
        y - the y coordinates of points
        z - the z coordinates of points
        f - the Function to fit to the given set of points
      • ChiSquaredFitter2D

        public ChiSquaredFitter2D(double[] x,                  double[] y,                  double[] z,                  double[] errors,                  Function f)
        Constructor.
        Parameters:
        x - the x coordinates of points
        y - the y coordinates of points
        z - the z coordinates of points
        errors - the error bars on z coordinates of points
        f - the Function to fit to the given set of points
    • Method Detail

      • addFunction

        public void addFunction(Function f)
        Invalidates this signature of this method on the superclass. This form throws an UnsupportedOperationException() because its meaning is ambiguous for a 2D fitter. Use addFunction(joptima.Function) instead.
        Overrides:
        addFunction in class Fitter
      • addFunction1Dx

        public void addFunction1Dx(Function f)
        Adds a one-dimensional Function to this Fitter. This form makes 2D extension of the given function along the y-axis, i.e. makes a Sum2D(function, null).
        Parameters:
        f - the one-dimensional function to extend along the y-axis
      • addFunction1Dy

        public void addFunction1Dy(Function f)
        Adds a one-dimensional Function to this Fitter. This form makes 2D extension of the given function along the x-axis, i.e. makes a Sum2D(null, function).
        Parameters:
        f - the one-dimensional function to extend along the x-axis
      • setData

        public void setData(double[] x,           double[] y,           double[] z)
        Fit the sum of functions to this set of points. Assumes sqrt(y) error bars.
        Parameters:
        x - the x coordinates of points
        y - the y coordinates of points
        z - the z coordinates of points
      • setData

        public void setData(double[] x,           double[] y,           double[] z,           double[] errors)
        Fit the sum of functions to this set of points.
        Parameters:
        x - the x coordinates of points
        y - the y coordinates of points
        z - the z coordinates of points
        errors - the error bars on y coordinates of points
      • calculate

        public double calculate()
        Calculates the χ² given parameter values set by a Minimizer using reflection. The formula is:
           for each point in the data set {     f = 0     for each Function {       f += Function.calculate(double)(x[point], y[point])     }     χ² += (y[point] - f)² / error[point]²   } 

SCaVis 2.2 © jWork.ORG