# `bucky.util.spline_smooth`#

Method of smoothing data w/ splines. Based of a GAM from mgcv with a cr() basis.

## Module Contents#

### Classes#

 `identity_link` Class for idenity link functions. `log_link` Class for log link functions.

### Functions#

 `PIRLS`(x, y, alp, pen, tol=1e-07, dist='g', max_it=10000, w=None, gamma=1.0, tqdm_label='PIRLS', fixed_lam=False, ret_beta=False, bootstrap=False) Penalized iterativly reweighted least squares. `_absorb_constraints`(design_matrix, constraints, pen=None) Apply constraints to the design matrix. `_compute_base_functions`(x, knots) Return base functions for the spline basis. `_cr`(x, df, center=True) Python version of the R lib mgcv function cr(). `_find_knots_lower_bounds`(x, knots) Find the lower bound for the knots. `_get_free_crs_dmatrix`(x, knots) Builds an unconstrained cubic regression spline design matrix. `_get_natural_f`(knots) Returns mapping of natural cubic spline values to 2nd derivatives. `fit`(y, x=None, df=10, alp=2.0, dist='g', standardize=True, w=None, gamma=1.4, tol=1e-07, clip=(None, None), label='fit', bootstrap=False) Perform fit of natural cubic splines to the vector y, return the smoothed y. `lin_reg`(y, x=None, alp=0.0, quad=False, return_fit=True) Calculate exact soln for batched linear regression and return either weights or fitted values. `logistic_fit`(y, x_out, x=None, alp=0.6, t0_max=200, L=None) WIP Fit a logistic function to batched y. Add I to a batch of matrices (...,M,M) until all are positive-definite (and cholesky-able). `nunique`(arr, axis=-1) Return the number of uniq values along a given axis. `opt_lam`(x, y, alp=0.6, pen=None, min_lam=0.1, step_size=None, tol=0.001, max_it=100, gamma=1.0, fixed_lam=False) Calculate the exact soln to the ridge regression of the weights for basis x that fit data y. `ridge`(x, y, alp=0.0) Calculate the exact soln to the ridge regression of the weights for basis x that fit batched data y.

### Attributes#

bucky.util.spline_smooth.dtype[source]#

Class for idenity link functions.

static g(mu)[source]#

Id link - \$g\$.

static g_prime(mu)[source]#

Id link - \$g’\$.

static mu(eta)[source]#

Id link - \$mu\$.

Class for log link functions.

static g(mu)[source]#

Log link - \$g\$.

static g_prime(mu)[source]#

Log link - \$g’\$.

static mu(eta)[source]#

Log link - \$mu\$.

bucky.util.spline_smooth.PIRLS(x, y, alp, pen, tol=1e-07, dist='g', max_it=10000, w=None, gamma=1.0, tqdm_label='PIRLS', fixed_lam=False, ret_beta=False, bootstrap=False)[source]#

Penalized iterativly reweighted least squares.

bucky.util.spline_smooth._absorb_constraints(design_matrix, constraints, pen=None)[source]#

Apply constraints to the design matrix.

bucky.util.spline_smooth._compute_base_functions(x, knots)[source]#

Return base functions for the spline basis.

bucky.util.spline_smooth._cr(x, df, center=True)[source]#

Python version of the R lib mgcv function cr().

bucky.util.spline_smooth._find_knots_lower_bounds(x, knots)[source]#

Find the lower bound for the knots.

bucky.util.spline_smooth._get_free_crs_dmatrix(x, knots)[source]#

Builds an unconstrained cubic regression spline design matrix.

bucky.util.spline_smooth._get_natural_f(knots)[source]#

Returns mapping of natural cubic spline values to 2nd derivatives.

bucky.util.spline_smooth.fit(y, x=None, df=10, alp=2.0, dist='g', standardize=True, w=None, gamma=1.4, tol=1e-07, clip=(None, None), label='fit', bootstrap=False)[source]#

Perform fit of natural cubic splines to the vector y, return the smoothed y.

bucky.util.spline_smooth.lin_reg(y, x=None, alp=0.0, quad=False, return_fit=True)[source]#

Calculate exact soln for batched linear regression and return either weights or fitted values.

bucky.util.spline_smooth.logistic_fit(y, x_out, x=None, alp=0.6, t0_max=200, L=None)[source]#

WIP Fit a logistic function to batched y.

bucky.util.spline_smooth.make_DP(x)[source]#

Add I to a batch of matrices (…,M,M) until all are positive-definite (and cholesky-able).

bucky.util.spline_smooth.nunique(arr, axis=- 1)[source]#

Return the number of uniq values along a given axis.

bucky.util.spline_smooth.opt_lam(x, y, alp=0.6, pen=None, min_lam=0.1, step_size=None, tol=0.001, max_it=100, gamma=1.0, fixed_lam=False)[source]#

Calculate the exact soln to the ridge regression of the weights for basis x that fit data y.

bucky.util.spline_smooth.ridge(x, y, alp=0.0)[source]#

Calculate the exact soln to the ridge regression of the weights for basis x that fit batched data y.