fitters

Code for fitting polynomials to data.

class pydaddy.fitters.Poly(coeffs, degree, stderr)

Bases: object

class pydaddy.fitters.Poly1D(coeffs, degree, stderr=None)

Bases: pydaddy.fitters.Poly

A rudimentary 2D polynomial class for polynomials with optional error intervals for coefficients. Returns polynomial objects that can be called or pretty-printed.

class pydaddy.fitters.Poly2D(coeffs, degree, stderr=None)

Bases: pydaddy.fitters.Poly

A rudimentary 2D polynomial class for polynomials with optional error intervals for coefficients. Returns polynomial objects that can be called or pretty-printed.

class pydaddy.fitters.PolyFit1D(**kwargs)

Bases: pydaddy.fitters.PolyFitBase

_evaluate_poly(c, x)
_get_callable_poly(coeffs, stderr)

Construct a callable polynomial from a given coefficient array.

_get_coeffs()
_get_poly_dictionary(x)
class pydaddy.fitters.PolyFit2D(**kwargs)

Bases: pydaddy.fitters.PolyFitBase

_evaluate_poly(c, x)
_get_callable_poly(coeffs, stderr)
_get_coeffs()
_get_poly_dictionary(x)
class pydaddy.fitters.PolyFitBase(threshold=0, max_degree=5, alpha=0, library=None)

Bases: object

Fits polynomial to estimated drift and diffusion functions with sparse regression.

_evaluate(c, x)
_evaluate_poly(c, x)
_get_bic(p, x, y)

Compute the BIC for a fitted polynomial with given data x, y.

_get_callable_poly(coeffs, stderr)
_get_coeffs()
_get_cv_error(x, y, folds)
_get_poly_dictionary(x)
fit(x, y, weights=None)

Fit a polynomial using sparse regression using STLSQ (Sequentially thresholded least-squares) :param x: Independent variable. Could either be an array (for 1D case) or

a list of two arrays (for 2D case).

Parameters
  • y (np.array) – Dependent variable

  • weights (np.array) – Sample weights for regression. If None (default), simple unweighted ridge regression will be performed.

Returns

np.poly1d object for 1D case, Poly2D object for 2D case.

model_selection(thresholds, x, y, weights=None, method='cv', plot=False)

Automatically choose the best threshold using BIC. :param thresholds: List of thresholds to search over. :param x: Data to be used for parameter tuning. :param y: Data to be used for parameter tuning. :param weights: (Optional) weights for fitting. :param method: {‘bic’, ‘cv’} The metric used for model selection :param plot: If true, plot the model selection curves

tune_and_fit(x, y, thresholds=None, steps=20, plot=False)
Parameters
  • x – Data to fit

  • y – Data to fit

  • thresholds – List of thresholds to try, will be automatically chosen if None

  • steps – When auto-choosing thesholds, the number of steps to take in the threshold range.

  • plot – Whether to plot the cross-validation error curves.