pycsa.core.priors¶
Pluggable Tikhonov priors for the linear-fit step.
The default fit in pycsa.core.lin_reg.do() adds a scalar
lmbda * trace(MᵀM)/N to the diagonal of the normal-equations
matrix. That branch is preserved unchanged — it is what every
existing call site hits and what the reproducibility fixtures
pin down.
This module introduces a Prior protocol so spike scripts can
experiment with structured (per-mode) regularization without
touching the default code path. A prior is a callable that returns
the diagonal vector to add to diag(E_tilda_lm).
IsotropicPrior is a parallel implementation of the existing
scalar-trace branch. It is NOT routed through by default; passing
prior=IsotropicPrior() to lin_reg.do should produce the
same numerical result as prior=None, within floating-point
re-association noise (the parallel path computes the same scalar
but the assignment sequence is different). Unit-tested for parity
on a synthetic E_tilda_lm.
SpectralPrior is the alternative under test in the spike: a
per-mode prior whose diagonal grows with wavenumber norm.
Classes
Parallel implementation of the current scalar-trace diagonal. |
|
|
Callable that returns the Tikhonov diagonal to add to |
|
Per-mode prior with diagonal growing with wavenumber norm. |
- class pycsa.core.priors.Prior(*args, **kwargs)¶
Callable that returns the Tikhonov diagonal to add to
diag(MᵀM).- Parameters:
fobj – The
pycsa.core.fourier.f_transinstance used to build the design matrix. Carries the mode-index attributes (m_i,m_j, optionalk_idx/l_idx) that structured priors need to compute per-mode weights.E_tilda_lm – The dense normal-equations matrix (
MᵀM), shape(N, N). Priors may usetrace(E)for scale normalization.lmbda – The overall regularization scale (the same scalar that the existing
lin_reg.doaccepts).
- Returns:
diag – Non-negative diagonal to be added to
diag(E_tilda_lm).- Return type:
np.ndarray, shape (N,)
- __init__(*args, **kwargs)¶
- class pycsa.core.priors.IsotropicPrior¶
Parallel implementation of the current scalar-trace diagonal.
Returns
lmbda * trace(E) / N * ones(N). Equivalent to the inline scalar-trace branch inlin_reg.do(the dense and sparseprior is Nonepaths), within reassociation noise — the inline branch computes one scalar and broadcasts; this returns an array. Provided so spike scripts can compose it as an explicit baseline alongside other priors.Not the default path.
lin_reg.do(prior=None)continues to use the inline branch and produces bit-identical fixture output.
- class pycsa.core.priors.SpectralPrior(alpha: float, eps: float = 0.001)¶
Per-mode prior with diagonal growing with wavenumber norm.
For each mode
mwith wavenumber pair(k_m, l_m):\[\lambda_m = \lambda \cdot \frac{\mathrm{tr}(E)}{N} \cdot \left( \frac{\Vert k_m \Vert}{\Vert k \Vert_{\max}} + \varepsilon \right)^\alpha\]Equivalent to a zero-mean Gaussian prior on the coefficients with variance proportional to
‖k_m‖^(-alpha). Implies an assumed topographic power spectrum behaving like‖k‖^(-alpha), soalphashould be calibrated from the input fixture’s empirical power-law slope rather than picked from generic physics constants.alpha=0recovers the isotropic baseline (modulo the+ epsfloor).- Parameters: