autowisp.fit_expression.iterative_fit module — AutoWISP documentation

# autowisp.fit_expression.iterative_fit module

Define a function doing iterative re-fitting of terms from an expression.

autowisp.fit_expression.iterative_fit.iterative_fit(predictors, target_values, *, max_downdates=20, weights=None, error_avg, rej_level, max_rej_iter, fit_identifier, pre_reject=False)

  Find least squares coefficients reproducing target_values using predictors.

  Parameters:

    - predictors – The derivatives w.r.t. to the fit coefficients of the predicted values (i.e. the matrix defining the fitting problem, apart from weighting).

    - target_values – The values wey are trying to reproduce.

    - max_downdates (float or int) – The maximum number of deletions to handle by downdating the QR decomposition, either as a fraction of the size of weighted_target (if max_downdates is a floating point between 0 and 1), or as an absolute value (if max_downdates is a positive integer). If an operation results in a larger number of deletions, the original matrix is re-constructed, the corresponding rows are deleted and a new QR decomposition is derived from scratch.

    - weights – The weight to give to each entry in target_values. If None, no weighting is done.

    - phot_ind – The index of the photometry being fit (only used for reporting errors).

    - error_avg (str) – How to average fitting residuals for outlier rejection. Should be a scipy/numpy top-level function (e.g. mean, nanmedian etc).

    - rej_level (float) – How far away from the fit should a point be before it is rejected in units of error_avg.

    - max_rej_iter – The maximum number of rejection/re-fitting iterations to perform. If the fit has not converged by then, the latest iteration is accepted.

    - fit_identifier – Identifier of what is being fit. Only used in logging messages.

    - pre_reject – Should a rejection iteration be performed before even the first fit is attempted (i.e. discard outliers even from the first fit).

  Returns:

    The best fit coefficients.

    float:

      The average square residual of the best fit.

    int:

      The number of non-rejected points used in the last fit iteration.

  Return type:

    numpy.array

autowisp.fit_expression.iterative_fit.iterative_fit_qr(weighted_predictors, weighted_qrp, weighted_target, *, weights=None, max_downdates=20, error_avg, rej_level, max_rej_iter, fit_identifier, pre_reject=False)

  Same as iterative_fit() but using the QR decomposition of predictors.

  Parameters:

    - weighted_predictors (2-D array) – The matrix of predictors, with weights already applied (used for calculating residuals and if too many poinst get rejected, see max_downdates).

    - weighted_qrp (2-D array) – The QR decomposition of weighted_predictors with pivoting. Should be exactly the output of scipy.linalg.qr(weighted_predictors, pivoting=True), possibly with mode=’economic’.

    - weighted_target (1-D array) – The vector of values to reproduce as a linear combination of predictors. Should also already be weighted.

    - max_downdates – See iterative_fit().

    - weights – See iterative_fit(). Only used for outlier detection.

    - error_avg – See iterative_fit().

    - rej_level – See iterative_fit().

    - max_rej_iter – See iterative_fit().

    - fit_identifier – See iterative_fit().

  Returns:

    See iterative_fit_qr()