blocked_cv#
- pypillometry.signal.gaussmarkov.blocked_cv(bank, theta, y, fs, segments=None, prior=None, block='60 s', folds=5, refit=True, maxiter=30)[source]#
Blocked cross-validation of a timescale-bank model.
The signal is cut into blocks; every folds-th block is held out in turn. The held-out blocks are scored by their joint predictive density given the rest of the signal,
\[\log p(y_B \mid y_{-B}, \hat\theta_{-B}) = \ell(\hat\theta_{-B}; y) - \ell(\hat\theta_{-B}; y_{-B}),\]where \(y_{-B}\) is the signal with the blocks B missing. A block has to be bridged from its neighbours, which is what the slow components are for, so the score is more sensitive to them than the likelihood (as long as the blocks are not much longer than their time scales).
- Parameters:
bank (TimescaleBank)
theta (array) – estimate from the whole signal (the starting value of the refits)
y – signal, sampling rate (Hz) and segments, as for
fit_bank()fs – signal, sampling rate (Hz) and segments, as for
fit_bank()segments – signal, sampling rate (Hz) and segments, as for
fit_bank()prior (GaussianPrior, str or None) – prior of the refits
block (float, str or Quantity) – length of the blocks (plain numbers are ms; default 60 s)
folds (int) – number of folds (default 5)
refit (bool) – re-estimate the parameters without the held-out blocks (default); if False, theta is used for all folds (faster, optimistic)
maxiter (int) – maximum number of iterations of each refit
- Return type:
- Returns:
sum of the log predictive densities of the folds (higher is better)