nstat.LinearCIF

class nstat.LinearCIF(beta, Xnames, stimNames, fitType='poisson', histCoeffs=None, historyObj=None, nst=None)[source]

Bases: object

Conditional intensity function with closed-form derivatives.

Drop-in compatible with nstat.cif.CIF for the 5 eval methods used by nstat.decoding_algorithms.DecodingAlgorithms.PPDecode_update: evalLambdaDelta, evalGradient, evalGradientLog, evalJacobian, evalJacobianLog.

Parameters:
  • beta (array_like) – Numeric regression coefficients (length len(Xnames)). Must be numeric — symbolic input is unsupported here because the entire point of LinearCIF is closed-form numeric differentiation.

  • Xnames (sequence of str) – Names of every design-matrix column (length equal to beta).

  • stimNames (sequence of str) – Subset of Xnames that are stimulus/state variables. Every element must appear in Xnames.

  • fitType ({"poisson", "binomial"}, optional) – Canonical link family. Default "poisson".

  • histCoeffs (array_like or None) – History coefficients (1-D, length history.numWindows). When None or empty, the linear predictor has no history term.

  • historyObj (History or array_like, optional) – History object or a window-times vector (which is converted into a History internally).

  • nst (nspikeTrain, optional) – Spike train used to pre-compute the history matrix when both historyObj and nst are provided.

Variables:
  • b (ndarray, shape (n_var,)) – Regression coefficients (row-vector semantics for left-multiplies).

  • varIn (tuple of str) – All variable names (preserves order).

  • stimVars (tuple of str) – Stimulus-variable subset of varIn.

  • stimIdx (ndarray of int, shape (n_stim,)) – 0-based indices of stimVars inside varIn.

  • bStim (ndarray, shape (n_stim,)) – Stimulus subset of b (row-vector semantics).

  • fitType (str) – "poisson" or "binomial".

  • histCoeffs (ndarray or None) – History coefficient row-vector.

  • history (History or None) – History object (or None if not supplied).

  • spikeTrain (nspikeTrain or None) – Spike train used to pre-compute historyMat (or None).

  • historyMat (ndarray or None) – Pre-computed history matrix (shape (n_time, n_hist)) when both history and spikeTrain were supplied at construction time.

__init__(beta, Xnames, stimNames, fitType='poisson', histCoeffs=None, historyObj=None, nst=None)[source]
Parameters:
Return type:

None

setSpikeTrain(spikeTrain)[source]

Replace the stored spike train and refresh historyMat.

Parameters:

spikeTrain (nspikeTrain) – Spike train to use for history evaluation. A deep copy is taken via spikeTrain.nstCopy() so subsequent mutations of the source do not affect this CIF.

Return type:

None

setHistory(histObj)[source]

Replace the stored history object.

Parameters:

histObj (History or array_like) – A History instance (its windowTimes are copied into a fresh History) or a 1-D vector of window times.

Return type:

None

Notes

Mirrors MATLAB LinearCIF.setHistory exactly — accepts either a History object or a numeric windowTimes array.

evalLambdaDelta(stimVal, time_index=None, nst=None)[source]

Evaluate scalar lambda*delta at the given stimulus values.

Parameters:
  • stimVal (array_like) – Either the full design vector (length len(varIn)) or the stimulus-only subset (length len(stimVars)).

  • time_index (int or None) – 0-based time index into historyMat. Mirrors MATLAB’s 0-based indexing (nst.dataToMatrix(time_index)).

  • nst (nspikeTrain or None) – On-the-fly history computation for the supplied train.

Returns:

Scalar value of lambda*delta.

Return type:

float

evalGradient(stimVal, time_index=None, nst=None)[source]

Gradient of lambda*delta w.r.t. the stimulus variables.

Returns:

Row vector of partial derivatives.

Return type:

ndarray, shape (1, n_stim)

Parameters:
evalGradientLog(stimVal, time_index=None, nst=None)[source]

Gradient of log(lambda*delta) w.r.t. the stimulus variables.

Returns:

Row vector of partial derivatives.

Return type:

ndarray, shape (1, n_stim)

Parameters:
evalJacobian(stimVal, time_index=None, nst=None)[source]

Hessian of lambda*delta w.r.t. the stimulus variables.

Returns:

Second-derivative matrix.

Return type:

ndarray, shape (n_stim, n_stim)

Parameters:
evalJacobianLog(stimVal, time_index=None, nst=None)[source]

Hessian of log(lambda*delta) w.r.t. the stimulus variables.

Returns:

For Poisson: zero matrix (canonical-link log-likelihood is linear in the stimulus, so its Hessian vanishes). For binomial: -ld·(1-ld)·outer(bStim, bStim).

Return type:

ndarray, shape (n_stim, n_stim)

Parameters: