Package gmisclib :: Module g_localfit
[frames] | no frames]

Module g_localfit

source code

Fit a linear transform to a bunch of tt input/output vectors.


Notes:
Functions
numpy.ndarray
err_before_fit(data, minsv=None, minsvr=None, constant=True)
How much variation did the data have before the fit? This is used to compare with the error after the fit, to allow a F-test or ANOVA.
source code
 
pack(data, constant=True)
Prepare the data array and (optionally) weight the data.
source code
(A, B, errs, sv, rank) where
  • A is a 2-D numpy.ndarray matrix.
  • B is a 1-D numpy.ndarray vector (if constant, else None).
  • errs is a numpy.ndarray vector, one value for each output coordinate. The length is the same as the out vector (see pack).
  • sv is a numpy.ndarray vector. The length is the same as the in vector (see pack).
localfit(data, minsv=None, minsvr=None, constant=True)
Does a linear fit to data via a singular value decomposition algorithm.
source code
 
reg_localfit(data, regstr=0.0, regtgt=None, rscale=None, constant=True)
Does a linear fit to data via a singular value decomposition algorithm.
source code
 
robust_localfit(data, minsv=None, minsvr=None, constant=True)
Data is [ (input_coordinates, output_coordinates), ...
source code
 
fit_giving_sigmas(data, minsv=None, minsvr=None, constant=True)
Does a linear fit to data via a singular value decomposition algorithm.
source code
 
leaktest() source code
 
test0() source code
 
test_localfit11(r) source code
 
test_localfit11e() source code
 
test_localfit21() source code
 
test_localfit21u() source code
 
test_localfit22(r) source code
 
test_fgs1() source code
 
test_wt() source code
Variables
  __package__ = 'gmisclib'

Imports: numpy, warnings, gpk_lsq, gpk_rlsq


Function Details

err_before_fit(data, minsv=None, minsvr=None, constant=True)

source code 

How much variation did the data have before the fit? This is used to compare with the error after the fit, to allow a F-test or ANOVA. Strictly speaking, we compute the mean-squared error about a constant.

Parameters:
Returns: numpy.ndarray
Returns the per-coordinate sum-squared-error of the output coordinates.

pack(data, constant=True)

source code 

Prepare the data array and (optionally) weight the data.

Parameters:
  • data ([(numpy.ndarray, numpy.ndarray), ...] or [(numpy.ndarray, numpy.ndarray, float), ...]) - [(input_coordinates, output_coordinates), ...] or [(input_coordinates, output_coordinates, weight), ...]. A list of (in,out) tuples corresponding to the independent and dependent parameters of the linear transform. Both in and out are one-dimensional numpy vectors. They don't need to have the same length, though (obviously) all instances of "in" need to have the same length and all instances of "out" also need to match one another. If weight is given, it must be a scalar.

localfit(data, minsv=None, minsvr=None, constant=True)

source code 

Does a linear fit to data via a singular value decomposition algorithm. It returns the matrix A and vector B such that A*input_coordinates+B is the best fit to output_coordinates.

Parameters:
  • minsv (float or None) - sets the minimum useable singular value;
  • minsvr (float or None) - sets the minimum useable s.v. in terms of the largest s.v.
  • constant (Boolean) - Do you want a constant built into the linear equations?
  • data (See pack.) - list of tuples. See pack.
Returns: (A, B, errs, sv, rank) where
  • A is a 2-D numpy.ndarray matrix.
  • B is a 1-D numpy.ndarray vector (if constant, else None).
  • errs is a numpy.ndarray vector, one value for each output coordinate. The length is the same as the out vector (see pack).
  • sv is a numpy.ndarray vector. The length is the same as the in vector (see pack).
(A, B, errs, sv, rank) where
  • A is the matrix of coefficients
  • B is a vector of constants. (Or None) One constant per component of the out vector in pack.
  • errs Each component gives the sum of squared residuals for the corresponding component of the out vector.
  • sv are the singular values, sorted into decreasing order.

reg_localfit(data, regstr=0.0, regtgt=None, rscale=None, constant=True)

source code 

Does a linear fit to data via a singular value decomposition algorithm. It returns the matrix A and vector B such that A*input_coordinates+B is the best fit to output_coordinates.

Parameters:
  • constant (Boolean) - Do you want a constant built into the linear equations?
  • data (See pack.) - list of tuples. See pack.
Returns:
(A, B, errs, sv, rank) where
  • A is a 2-D numpy.ndarray matrix.
  • B is a 1-D numpy.ndarray vector (if constant, else None).
  • errs is a numpy.ndarray vector, one value for each output coordinate. It gives the sum of squared residuals.
  • sv are the singular values, sorted into decreasing order.

robust_localfit(data, minsv=None, minsvr=None, constant=True)

source code 

Data is [ (input_coordinates, output_coordinates), ... ] Minsv sets the minimum useable singular value; minsvr sets the minimum useable s.v. in terms of the largest s.v.. It returns the matrix A and vector B such that the best fit is A*input_coordinates+B in a tuple (A, B, errs, rank). errs is a vector, one value for each output coordinate. Rank is the minimum rank of the various fits.

Warning! Not tested.

fit_giving_sigmas(data, minsv=None, minsvr=None, constant=True)

source code 

Does a linear fit to data via a singular value decomposition algorithm. It returns the matrix A and vector B such that A*input_coordinates+B is the best fit to output_coordinates.

Parameters:
  • minsv (float or None) - sets the minimum useable singular value;
  • minsvr (float or None) - sets the minimum useable s.v. in terms of the largest s.v.
  • constant (Boolean) - Do you want a constant built into the linear equations?
  • data ([(numpy.ndarray, numpy.ndarray), ...]) - [(input_coordinates, output_coordinates), ...]. A list of (in,out) tuples corresponding to the independent and dependent parameters of the linear transform. Both in and out are one-dimensional numpy vectors. They don't need to have the same length, though (obviously) all instances of "in" need to have the same length and all instances of "out" also need to match one another.
Returns:
(A, B, sigmaA, sigmaB) where
  • A is a 2-D numpy.ndarray matrix.
  • B is a 1-D numpy.ndarray vector (if constant, else None). )