Previous topic

pycrtools.core.hftools.mFilter

Next topic

pycrtools.core.hftools.mIO

This Page

pycrtools.core.hftools.mFitting

pycrtools.core.hftools.mFitting.hLinearFitPolynomialX()

hLinearFitPolynomialX(vecout, xvec, powers)

Calculate the x-value vector for the polynomial (linear-fitting) routine, calculating essentially all powers of the input vector.

Parameters

vecout Output vector containing rows with all the requested powers of the x-vector. Size is (n+1)*len(xvec), where n=len(powers).
xvec Input vector with x-values for the fitting routine.
powers Input vector with the powers to consider in the fitting. For an nth order polynomial, this is simply [0,1,2,...,n].

Description

n is the number of powers of the polynomial to fit, i.e. len(powers). The length of the output vector is the length of xvec*(n+1).

See also

hLinearFit()

Example

[x_0,x_1,x_2,...] -> [0,x_0,x_0^2,...,x_0^n,0,x_1,x_1^2,...,x_1^n]
pycrtools.core.hftools.mFitting.hBSplineFitXValues()

hBSplineFitXValues(vecout, xvec, Ncoeffs, xmin, xmax, k)

Calculate the x-value vector for the basis Spline (BSpline) fitting routine, calculating essentially all powers of the input vector.

Parameters

vecout Output vector containing rows with all the requested powers of the x-vector. Size is Ncoeffs * len(xvec).
xvec Input vector with x-values for the fitting routine.
Ncoeffs Number of coefficients to calculate.
xmin Lower end of the x-range for calculation of break points.
xmax Upper end of the x-range for calculation of break points.
k Order of polynomial to fit locally, e.g. k=4 is a 3rd order polynomial.

Description

Note: for k=2 you get a linear fit.

See also

hBSplineFit(), hBSplineCalc(), hBSpline(), hBSplineFitXValues(), hBSplineCalcAdd(), hBSplineCalcMul()

pycrtools.core.hftools.mFitting.hBSpline()

hBSpline(vecout, xvec, coeffs, k)

Calculate the y-value vector of the results of a basis Spline fit, providing the powers of x as input.

Parameters

vecout Output vector containing the y-values for the input vector x-values.
xvec Input vector of Ndata*Ncoeffs x-values produced with hBSplineFitXValues(). Size is Ncoeffs*len(xvec).
coeffs Input vector with the coefficients calculated by the fitting routine.
k Order of polynomial to fit locally, e.g. k=4 is a 3rd order polynomial.

See also

hBSplineFit(), hBSplineCalc(), hBSpline(), hBSplineFitXValues(), hBSplineCalcAdd(), hBSplineCalcMul()

pycrtools.core.hftools.mFitting.hBSplineCalcMul()

hBSplineCalcMul(vecout, xvec, coeffs, xmin, xmax, k)

Calculate the y-values of the results of a basis Spline fit and Mul to the output vector.

Parameters

vecout Output vector containing the y-values for the input vector x-values.
xvec Input vector with x-values.
coeffs Input vector with the number of coefficients calculated by the fitting routine.
xmin Lower limit of interval where spline is defined.
xmax Upper limit of interval where spline is defined.
k Order of polynomial to fit locally, e.g. k=4 is 3rd order polynomial.

See also

hBSplineFit(), hBSpline(), hBSplineFitXValues(), hBSplineCalc(), hBSplineCalcAdd(), hBSplineCalcMul()

pycrtools.core.hftools.mFitting.hBSplineCalcAdd()

hBSplineCalcAdd(vecout, xvec, coeffs, xmin, xmax, k)

Calculate the y-values of the results of a basis Spline fit and Add to the output vector.

Parameters

vecout Output vector containing the y-values for the input vector x-values.
xvec Input vector with x-values.
coeffs Input vector with the number of coefficients calculated by the fitting routine.
xmin Lower limit of interval where spline is defined.
xmax Upper limit of interval where spline is defined.
k Order of polynomial to fit locally, e.g. k=4 is 3rd order polynomial.

See also

hBSplineFit(), hBSpline(), hBSplineFitXValues(), hBSplineCalc(), hBSplineCalcAdd(), hBSplineCalcMul()

pycrtools.core.hftools.mFitting.hBSplineCalcAssign()

hBSplineCalcAssign(vecout, xvec, coeffs, xmin, xmax, k)

Calculate the y-values of the results of a basis Spline fit and Assign to the output vector.

Parameters

vecout Output vector containing the y-values for the input vector x-values.
xvec Input vector with x-values.
coeffs Input vector with the number of coefficients calculated by the fitting routine.
xmin Lower limit of interval where spline is defined.
xmax Upper limit of interval where spline is defined.
k Order of polynomial to fit locally, e.g. k=4 is 3rd order polynomial.

See also

hBSplineFit(), hBSpline(), hBSplineFitXValues(), hBSplineCalc(), hBSplineCalcAdd(), hBSplineCalcMul()

pycrtools.core.hftools.mFitting.hBSplineCalc()

hBSplineCalc(vecout, xvec, coeffs, xmin, xmax, k)

Calculate the y-values of the results of a basis Spline fit and assign to the output vector.

Parameters

vecout Output vector containing the y-values for the input vector x-values.
xvec Input vector with x-values.
coeffs Input vector with the number of coefficients calculated by the fitting routine.
xmin Lower limit of interval where spline is defined.
xmax Upper limit of interval where spline is defined.
k Order of polynomial to fit locally, e.g. k=4 is a 3rd order polynomial.

See also

hBSplineFit(), hBSpline(), hBSplineFitXValues(), hBSplineCalc(), hBSplineCalcAdd(), hBSplineCalcMul()

pycrtools.core.hftools.mFitting.hBSplineFit()

hBSplineFit(vecout, veccov, xmatrix, xvec, yvec, xmin, xmax, k)

Do a basis spline fit to a data set (without weights) and return the coefficients and covariance matrix in two vectors.

Parameters

vecout Output vector containing the bets fit coefficients C_n of the polynomial \sum_n C_n x^n. The first element is C_0, i.e. the constant. Its length determines the order of the polynomial.
veccov Output vector of length n^2 containing the covariance matrix of the fit.
xmatrix Output vector containing the x-values of the data, where each value is actually one row of ncoeff values some power of x. Calculated with hBSplineFitXValues().
xvec Vector containing the x values of the data.
yvec Vector containing the y values of the data.
xmin Lower limit of interval where spline is defined.
xmax Upper limit of interval where spline is defined.
k Order of polynomial to fit locally, e.g. k=4 is a 3rd order polynomial.

Description

Returns the \chi^2 value of the fit.

See also

hBSplineFit(), hBSpline(), hBSplineFitXValues(), hBSplineCalcAssign(), hBSplineCalcAdd(), hBSplineCalcMul()

pycrtools.core.hftools.mFitting.hPolynomial()

hPolynomial(vecout, xvec, coeff, powers)

Calculates a polynomial from a vector of x-values, coefficients, and powers writing it to the output vector.

Parameters

vecout Output vector containing the polynomial y-values.
xvec Input vector with x-values.
coeff Coefficients for each power in powers.
powers Input vector with the powers to take into account. For an n-th order polynomial, this is simply [0,1,2,...,n].

Usage

xvec=[x_0,x_1,x_2,...],powers=[0,1,2,....],coeff=[C_0,C_1,C_2,...]:

vecout.polynmomial(xvec,coeff,powers) -> [sum(C_0,C_1*x_0,C_2*x_0**2,...),sum(C_0,C_1*x_1,C_2*x_1**2,...,C_n*x_1**n),...]

See also

hLinearFit(), hLinearFitPolynomialX(), hPolynomialAdd(), hPolynomialMul()

pycrtools.core.hftools.mFitting.hPolynomialMul()

hPolynomialMul(vecout, xvec, coeff, powers)

Calculates a polynomial from a vector of x-values, coefficients, and powers multiplies it to the output vector.

Parameters

vecout Output vector containing the polynomial y-values.
xvec Input vector with x-values.
coeff Coefficients for each power in powers.
powers Input vector with the powers to take into account. For an n-th order polynomial, this is simply [0,1,2,...,n].

Description

Same as hPolynomialMul(), but multiply result to the output (i.e., use *=). So, for a first iteration vecout has to be filled with 1.

Usage

vecout.polynmomialmul(xvec,coeff,powers) -> vecout_0 *= [sum(C_0,C_1*x_0,C_2*x_0**2,...,C_n*x_0**n),sum(C_0,C_1*x_1,C_2*x_1**2,...,C_n*x_1**n),...]

xvec=[x_0,x_1,x_2,...],powers=[0,1,2,....],coeff=[C_0,C_1,C_2,...]

See also

hLinearFit(), hLinearFitPolynomialX(), hPolynomialAdd(), hPolynomialMul(), hPolynomial()

pycrtools.core.hftools.mFitting.hPolynomialAdd()

hPolynomialAdd(vecout, xvec, coeff, powers)

Calculates a polynomial from a vector of xvalues, coefficients, and powers and adds it to the output vector.

Parameters

vecout Output vector containing the polynomial y-values.
xvec Input vector with x-values.
coeff Coefficients for each power in powers.
powers Input vector with the powers to take into account. For an n-th order polynomial, this is simply [0,1,2,...,n].

Description

Same as hPolynomialMul(), but add result to the output (i.e., use +=). So, for a first iteration vecout has to be filled with 1.

Usage

vecout.polynmomialadd(xvec,coeff,powers) -> vecout += [sum(C_0,C_1*x_0,C_2*x_0**2,...),sum(C_0,C_1*x_1,C_2*x_1**2,...,C_n*x_1**n),...]

xvec=[x_0,x_1,x_2,...],powers=[0,1,2,....],coeff=[C_0,C_1,C_2,...]

See also

hLinearFit(), hLinearFitPolynomialX(), hPolynomialAdd(), hPolynomialMul(), hPolynomial()

pycrtools.core.hftools.mFitting.hErrorsToWeights()

hErrorsToWeights(vecout, vecin)

Calculates a weight factor from an error for a fitting routine, i.e. w=1/Error^2.

Parameters

vecout Output vector containing the weights.
vecin Input vector with errorvalues.

See also

hLinearFit(), hLinearFitPolynomialX(), hPolynomial()

Example

[x_0,x_1,x_2,...] -> [1/x_0^2,1/x_1^2,...]
pycrtools.core.hftools.mFitting.hLinearFit()

hLinearFit(vecout, veccov, xvec, yvec, wvec, ndata)

Do a linear fit (e.g. to an n-th order polynomial) to a data set provided a vector of weights and return the coefficients and covariance matrix in two vectors.

Parameters

vecout Output vector containing the bets fit coefficients C_n of the polynomial \sum_n C_n x^n). The first element is C_0, i.e. the constant. Its length determines the order of the polynomial.
veccov Output vector of length n^2 containing the covariance matrix of the fit.
xvec Vector containing the x-values of the data, where each value is actually one row of n+1 values of x^n (e.g., if x-values are [2,3] => xvec=[0,2,4,0,3,9] for a quadratic polynomical (n=2)).
yvec Vector containing the y-values of the data.
wvec Vector containing the weights of the data (which are 1/Error^2).
ndata Number of data points to take into account (ndata=-1 -> take all elements in yvec; if ndata > 0 only take the first ndata).

Description

Returns as function value the \chi^2 value of the fit.

See also

hLinearFitPolynomialX(), hPolynomial()

hLinearFit(vecout, veccov, xvec, yvec, ndata)

Do a linear fit (e.g. to an n-th order polynomial) to a data set (without weights) and return the coefficients and covariance matrix in two vectors.

Parameters

vecout Output vector containing the bets fit coefficients C_n of the polynomial \sum_n C_n x^n. The first element is C_0, i.e. the constant. Its length determines the order of the polynomial.
veccov Output vector of length n^2 containing the covariance matrix of the fit.
xvec Vector containing the x-values of the data, where each value is actually one row of n+1 values of x^n (e.g., if x-values are [2,3] => xvec=[0,2,4,0,3,9] for a quadratic polynomical (n=2)).
yvec Vector containing the y-values of the data.
ndata Number of data points to take into account (ndata=-1 -> take all elements in yvec; if ndata > 0 only take the first ndata).

Description

Returns as function value the \chi^2 value of the fit.

See also

hLinearFitPolynomialX(), hPolynomial()

pycrtools.core.hftools.mFitting.hLinearFit()

hLinearFit(vecout, veccov, xvec, yvec, wvec, ndata)

Do a linear fit (e.g. to an n-th order polynomial) to a data set provided a vector of weights and return the coefficients and covariance matrix in two vectors.

Parameters

vecout Output vector containing the bets fit coefficients C_n of the polynomial \sum_n C_n x^n). The first element is C_0, i.e. the constant. Its length determines the order of the polynomial.
veccov Output vector of length n^2 containing the covariance matrix of the fit.
xvec Vector containing the x-values of the data, where each value is actually one row of n+1 values of x^n (e.g., if x-values are [2,3] => xvec=[0,2,4,0,3,9] for a quadratic polynomical (n=2)).
yvec Vector containing the y-values of the data.
wvec Vector containing the weights of the data (which are 1/Error^2).
ndata Number of data points to take into account (ndata=-1 -> take all elements in yvec; if ndata > 0 only take the first ndata).

Description

Returns as function value the \chi^2 value of the fit.

See also

hLinearFitPolynomialX(), hPolynomial()

hLinearFit(vecout, veccov, xvec, yvec, ndata)

Do a linear fit (e.g. to an n-th order polynomial) to a data set (without weights) and return the coefficients and covariance matrix in two vectors.

Parameters

vecout Output vector containing the bets fit coefficients C_n of the polynomial \sum_n C_n x^n. The first element is C_0, i.e. the constant. Its length determines the order of the polynomial.
veccov Output vector of length n^2 containing the covariance matrix of the fit.
xvec Vector containing the x-values of the data, where each value is actually one row of n+1 values of x^n (e.g., if x-values are [2,3] => xvec=[0,2,4,0,3,9] for a quadratic polynomical (n=2)).
yvec Vector containing the y-values of the data.
ndata Number of data points to take into account (ndata=-1 -> take all elements in yvec; if ndata > 0 only take the first ndata).

Description

Returns as function value the \chi^2 value of the fit.

See also

hLinearFitPolynomialX(), hPolynomial()