Model Fitting

Model fitting is normally performed by either the sails.modelfit.VieiraMorfLinearModel or sails.modelfit.OLSLinearModel class. If you wish to fit a model using another method, an example of this can be found in :ref:tutorial8.

class sails.modelfit.VieiraMorfLinearModel[source]

A class implementing the Vieira-Morf linear model fit

classmethod fit_model(data, delay_vect)[source]

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].

Parameters:
  • 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.
Returns:

A populated object containing the fitted forward and backwards coefficients and several other useful variables and methods.

Return type:

sails.VieiraMorfLinearModel

get_residuals(data, forward_parameters=True, mode='valid')[source]

Returns the prediction error from a fitted model. This is a wrapper function for get_residuals()

Parameters:
  • 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)
Returns:

Residual data

Return type:

ndarray

class sails.modelfit.OLSLinearModel[source]

A class implementing ordinary least squares linear model fit

classmethod fit_model(data, delay_vect)[source]

This is a class method which fits a linear model and returns a populated OLSLinearModel instance containing the fitted model.

Parameters:
  • 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
Returns:

A populated object containing the fitted coefficients and several other useful variables and methods.

Return type:

sails.OLSLinearModel

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.

sails.modelfit.sliding_window_fit(model_class, data, delay_vect, win_len_samp, win_step_samp, compute_diagnostics=True)[source]

A helper function for fitting many MVAR models within sliding windows across a dataset.

Parameters:
  • 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)
Returns:

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]

Return type:

LinearModel