Class FitResult

java.lang.Object
edu.cnu.mdi.splot.fit.FitResult

public final class FitResult extends Object
Generic result for a (weighted) least-squares fit.

This class is intentionally model-agnostic: it stores parameter values and common diagnostics that apply across nonlinear and linear least-squares fits (Gaussian, erf/erfc, exponential, polynomial, etc.).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    final double
    Chi-square: sum r_i^2 = cost^2 (weighted if weights used).
    final double
    Reduced chi-square: chiSquare / dof.
    final double
    Least-squares cost: sqrt(sum r_i^2) where r_i are residuals.
    final org.apache.commons.math3.linear.RealMatrix
    Optional covariance matrix of parameters (p x p), or null if unavailable.
    final int
    Degrees of freedom: max(1, nPoints - nParameters).
    final int
    Evaluations used by an iterative optimizer; may be 0 for closed-form fits.
    "Use as a function" evaluator for the fit.
    final int
    Iterations used by an iterative optimizer; may be 0 for closed-form fits.
    final double[]
    Best-fit parameters.
    static final String
     
    final double
    RMS of residuals (same residual space as optimizer).
    Gets descriptive strings from fitter
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    FitResult(IFitStringGetter stringGetter, double[] params, org.apache.commons.math3.linear.RealMatrix covariance, double cost, double chiSquare, int dof, double chiSquareReduced, double rms, int iterations, int evaluations)
    Create a fit result.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    HTML summary of the fit result.
    int
     
    double
    param(int i)
    Convenience access to parameter i.
    double
    Standard error for parameter i (NaN if unavailable).
    double[]
    Standard errors for parameters computed from covariance: sqrt(cov[i,i]).
    void
    Set the evaluator.
    Single-line text summary of the fit result.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • CHI

      public static final String CHI
      See Also:
    • CHISQ

      public static final String CHISQ
      See Also:
    • PLUSMINUS

      public static final String PLUSMINUS
      See Also:
    • params

      public final double[] params
      Best-fit parameters. Interpretation depends on the model.
    • stringGetter

      public IFitStringGetter stringGetter
      Gets descriptive strings from fitter
    • covariance

      public final org.apache.commons.math3.linear.RealMatrix covariance
      Optional covariance matrix of parameters (p x p), or null if unavailable.
    • cost

      public final double cost
      Least-squares cost: sqrt(sum r_i^2) where r_i are residuals. If weights are used, r_i are in the weighted residual space.
    • chiSquare

      public final double chiSquare
      Chi-square: sum r_i^2 = cost^2 (weighted if weights used).
    • dof

      public final int dof
      Degrees of freedom: max(1, nPoints - nParameters).
    • chiSquareReduced

      public final double chiSquareReduced
      Reduced chi-square: chiSquare / dof.
    • rms

      public final double rms
      RMS of residuals (same residual space as optimizer).
    • iterations

      public final int iterations
      Iterations used by an iterative optimizer; may be 0 for closed-form fits.
    • evaluations

      public final int evaluations
      Evaluations used by an iterative optimizer; may be 0 for closed-form fits.
    • evaluator

      public Evaluator evaluator
      "Use as a function" evaluator for the fit.
  • Constructor Details

    • FitResult

      protected FitResult(IFitStringGetter stringGetter, double[] params, org.apache.commons.math3.linear.RealMatrix covariance, double cost, double chiSquare, int dof, double chiSquareReduced, double rms, int iterations, int evaluations)
      Create a fit result.
      Parameters:
      stringGetter - access to descriptive strings about fitter
      params - best-fit parameters
      covariance - optional covariance matrix (may be null)
      cost - least-squares cost
      chiSquare - chi-square
      dof - degrees of freedom
      chiSquareReduced - reduced chi-square
      rms - RMS of residuals
      iterations - iterations used (0 if not applicable)
      evaluations - evaluations used (0 if not applicable)
  • Method Details

    • setEvaluator

      public void setEvaluator(Evaluator evaluator)
      Set the evaluator.
      Parameters:
      evaluator -
    • nParams

      public int nParams()
      Returns:
      number of parameters.
    • param

      public double param(int i)
      Convenience access to parameter i.
    • hasCovariance

      public boolean hasCovariance()
      Returns:
      true if covariance is present.
    • paramStdErrors

      public double[] paramStdErrors()
      Standard errors for parameters computed from covariance: sqrt(cov[i,i]). Returns NaN for entries where covariance is missing or diagonal is non-positive.
    • paramStdError

      public double paramStdError(int i)
      Standard error for parameter i (NaN if unavailable).
    • htmlSummary

      public String htmlSummary()
      HTML summary of the fit result.
      Returns:
      HTML string
    • singleLineSummary

      public String singleLineSummary()
      Single-line text summary of the fit result.
      Returns:
      single-line string
    • toString

      public String toString()
      Overrides:
      toString in class Object