Model fitting is normally performed by either the
sails.modelfit.OLSLinearModel class. If you wish
to fit a model using another method, an example of this
can be found in :ref:tutorial8.
A class implementing the Vieira-Morf linear model fit
Estimates the multichannel autoregressive spectral estimators using a Vieira-Morf algorithm. Equations are referenced to [Marple1987], appendix 15.B.
This is the multitrial versions of the algorithm, using the AMVAR method outlined in [Ding2000].
- data (numpy.ndarray) – array of shape [nsignals, nsamples, ntrials]
- delay_vect (numpy.ndarray) – Vector containing evenly spaced delays to be assessed in the model. Delays are represented in samples. Must start with zero.
A populated object containing the fitted forward and backwards coefficients and several other useful variables and methods.
get_residuals(data, forward_parameters=True, mode='valid')¶
Returns the prediction error from a fitted model. This is a wrapper function for get_residuals()
- data (ndarray) – Data to compute the residuals from, of size [nchannels x nsamples x nrealisations]
- forward_parameters (bool) – If True, use forward parameters, otherwise use backward parameters (Default value = True)
A class implementing ordinary least squares linear model fit
This is a class method which fits a linear model and returns a populated
OLSLinearModelinstance containing the fitted model.
- data (ndarray) – The data to be used to compute the model fit
- delay_vect (ndarray) – A vector of lag indices defining the lags to fit
A populated object containing the fitted coefficients and several other useful variables and methods.
Model fitting helper functions¶
In addition to basic model fitting routines, some helper functions exist; for instance to help with fitting a number of models to a data series following a “sliding window” pattern.
sliding_window_fit(model_class, data, delay_vect, win_len_samp, win_step_samp, compute_diagnostics=True)¶
A helper function for fitting many MVAR models within sliding windows across a dataset.
- model_class (LinearModel) – The SAILS linear model typee to fit
- data (ndarray) – Data to fit the model on, of size [nchannels x nsamples x nrealisations]
- delay_vect (ndarray) – A vector of lags specifying which lags to fit
- win_len_samp (int) – The window length in samples
- win_step_samp (int) – The step size between windows in samples
- compute_diagnostics (boolean) – Flag indicating whether to compute model diagnostics at each window (Default value = True)
An instance of linear model passed into the function containing MVAR parameters for all windows. The parameters are stored in model.parameters which is of size: [nchannels x nchannels x model order x nwindows]