Commit eea92f12 authored by Mark Hymers's avatar Mark Hymers

Tidy up documentation

Signed-off-by: Mark Hymers's avatarMark Hymers <mark.hymers@ynic.york.ac.uk>
parent 8c265765
......@@ -574,14 +574,43 @@ __all__.append('sliding_window_fit')
def pca_reduced_fit(X, delay_vect, ndim, linear_model=VieiraMorfLinearModel):
""" First pass at a helper for computing an MVAR on dimensionality reduced
data. Returns a model fitted to reduced data, the reduced model projected
back to original data dimensions and the pca object used for reduction
"""
Helper for computing an MVAR on dimensionality reduced data (using PCA).
Returns a
model fitted to reduced data, the reduced model projected back to original
data dimensions and the pca object used for reduction
Parameters
----------
X : ndarray
The data to compute the reduced model fit on
delay_vect : ndarray
A vector of lags specifying which lags to fit
ndim : int
Number of components to reduce data to.
linear_model : class
Subclass of AbstractLinearModel to use for fit.
Defaults to VieiraMorfLinearModel.
(Default value = True)
Returns
-------
red_model : AbstractLinearModel
An instance of the linear model passed into the function containing MVAR
parameters for all windows for the reduced model.
proj_model : AbstractLinearModel
An instance of the linear model passed into the function containing MVAR
parameters for all windows for the projected model.
pc : sails.utils.PCA
PCA class with information about the PCA projection included
"""
# PCA requires [samples x channels] whereas data is [channels x samples]
from .utils import PCA
pc = PCA(X.T, ndim)
Xred = pc.scores.T
Xred = Xred[:, :, None]
......@@ -591,13 +620,17 @@ def pca_reduced_fit(X, delay_vect, ndim, linear_model=VieiraMorfLinearModel):
# Project back to data dimensions
Afull = np.zeros((X.shape[0], X.shape[0], len(delay_vect)))
Afull[:, :, 0] = -np.eye(X.shape[0]) # Don't project identity at start
# Don't project identity at start
Afull[:, :, 0] = -np.eye(X.shape[0])
for ii in range(1, len(delay_vect)):
Afull[:, :, ii] = np.dot(pc.components.T, red_model.parameters[:, :, ii]).dot(pc.components)
resid_cov_full = np.dot(pc.components.T, red_model.resid_cov[:, :]).dot(pc.components)[:, :, None]
# Store projected model
proj_model = AbstractLinearModel()
proj_model = linear_model()
proj_model.parameters = Afull
proj_model.resid_cov = resid_cov_full
proj_model.delay_vect = delay_vect
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment