nstat.LinearCIF
- class nstat.LinearCIF(beta, Xnames, stimNames, fitType='poisson', histCoeffs=None, historyObj=None, nst=None)[source]
Bases:
objectConditional intensity function with closed-form derivatives.
Drop-in compatible with
nstat.cif.CIFfor the 5 eval methods used bynstat.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 ofLinearCIFis closed-form numeric differentiation.Xnames (sequence of str) – Names of every design-matrix column (length equal to
beta).stimNames (sequence of str) – Subset of
Xnamesthat are stimulus/state variables. Every element must appear inXnames.fitType ({"poisson", "binomial"}, optional) – Canonical link family. Default
"poisson".histCoeffs (array_like or None) – History coefficients (1-D, length
history.numWindows). WhenNoneor 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
Historyinternally).nst (nspikeTrain, optional) – Spike train used to pre-compute the history matrix when both
historyObjandnstare 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
stimVarsinsidevarIn.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
Noneif not supplied).spikeTrain (nspikeTrain or None) – Spike train used to pre-compute
historyMat(orNone).historyMat (ndarray or None) – Pre-computed history matrix (shape
(n_time, n_hist)) when bothhistoryandspikeTrainwere supplied at construction time.
- __init__(beta, Xnames, stimNames, fitType='poisson', histCoeffs=None, historyObj=None, nst=None)[source]
- Parameters:
fitType (str)
nst (nspikeTrain | None)
- 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
Historyinstance (itswindowTimesare copied into a freshHistory) or a 1-D vector of window times.- Return type:
None
Notes
Mirrors MATLAB
LinearCIF.setHistoryexactly — accepts either aHistoryobject or a numericwindowTimesarray.
- evalLambdaDelta(stimVal, time_index=None, nst=None)[source]
Evaluate scalar
lambda*deltaat the given stimulus values.- Parameters:
stimVal (array_like) – Either the full design vector (length
len(varIn)) or the stimulus-only subset (lengthlen(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:
- evalGradient(stimVal, time_index=None, nst=None)[source]
Gradient of
lambda*deltaw.r.t. the stimulus variables.- Returns:
Row vector of partial derivatives.
- Return type:
ndarray, shape (1, n_stim)
- Parameters:
time_index (int | None)
nst (nspikeTrain | None)
- 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:
time_index (int | None)
nst (nspikeTrain | None)
- evalJacobian(stimVal, time_index=None, nst=None)[source]
Hessian of
lambda*deltaw.r.t. the stimulus variables.- Returns:
Second-derivative matrix.
- Return type:
ndarray, shape (n_stim, n_stim)
- Parameters:
time_index (int | None)
nst (nspikeTrain | None)
- 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:
time_index (int | None)
nst (nspikeTrain | None)