pycsa.core.lin_reg

Linear regression module with buffer pool and sparse solver support

Functions

do(fobj, cell[, lmbda, iter_solve, ...])

Does the linear regression with optional buffer pool and sparse solver

get_coeffs(fobj[, ctx, buffer_pool])

Assembles the Fourier coefficients from the sine and cosine terms generated in the Fourier transformer class.

pycsa.core.lin_reg.get_coeffs(fobj, ctx=None, buffer_pool=None)

Assembles the Fourier coefficients from the sine and cosine terms generated in the Fourier transformer class.

Parameters:
  • fobj (pycsa.core.fourier.f_trans instance) – instance of the Fourier transformer class.

  • ctx (ComputeContext, optional) – Compute context bundling the buffer pool. If absent, defaults to fobj.ctx (set by f_trans.__init__).

  • buffer_pool (BufferPool, optional) – Deprecated. Pass ctx=ComputeContext(buffer_pool=...) instead.

Returns:

2D array corresponding to the M matrix.

Return type:

array-like

pycsa.core.lin_reg.do(fobj, cell, lmbda=0.0, iter_solve=True, save_coeffs=False, ctx=None, buffer_pool=None, use_sparse=False, prior=None)

Does the linear regression with optional buffer pool and sparse solver

Parameters:
  • fobj (pycsa.core.fourier.f_trans instance) – instance of the Fourier transformer class.

  • cell (pycsa.data.cell.topo_cell instance) – cell object instance

  • lmbda (float, optional) – regularisation parameter, by default 0.0

  • iter_solve (bool, optional) – toggles between using direct or iterative solver, by default True

  • save_coeffs (bool, optional) – skips the linear regression and just saves the generated M matrix for diagnostics and debugging, by default False

  • ctx (ComputeContext, optional) – Compute context bundling the buffer pool. If absent, defaults to fobj.ctx. If ctx.prior is set and the prior kwarg is None, the context’s prior is used.

  • buffer_pool (BufferPool, optional) – Deprecated. Pass ctx=ComputeContext(buffer_pool=...) instead.

  • use_sparse (bool, optional) – Use sparse matrix solver (automatic for few modes), by default False

  • prior (pycsa.core.priors.Prior, optional) – Pluggable Tikhonov diagonal generator. When None (default), the existing scalar-trace branch is used and numerics are bit-identical to historical behavior. When supplied, the prior is called as prior(fobj, E_tilda_lm, lmbda=lmbda) and the returned diagonal is added to diag(E_tilda_lm). Opt-in only; no production caller passes this kwarg.

Returns:

  • a_m (ndarray) – Fourier amplitudes corresponding to the unknown vector in the linear problem. When save_coeffs=True the regression is skipped and (None, None) is returned instead.

  • data_recons (ndarray) – vector-like topography reconstructed from a_m (None when save_coeffs=True).

Raises:

ValueError – If the supplied prior returns a diagonal whose shape does not match E_tilda_lm (checked in both the sparse and dense solver branches).