Commit cb662cf4 authored by Mark Hymers's avatar Mark Hymers

Tidy up documentation and add anamnesis support

Signed-off-by: Mark Hymers's avatarMark Hymers <mark.hymers@ynic.york.ac.uk>
parent eea92f12
......@@ -6,6 +6,8 @@ import math
import numpy as np
from scipy import signal, stats
from .anam import AbstractAnam, register_class
__all__ = []
......@@ -212,8 +214,10 @@ def gesd(x, alpha=0.05, p_out=.1, outlier_side=0):
def detect_artefacts(X, reject_dim='channels', reject_metric='std',
segment_len=100, gesd_args=None, ret_mode='bad_inds'):
"""Detect bad channels or segments in M/EEG data
Compute a Principal Components Analysis on a given dataset using the SVD
method.
Parameters
----------
X : ndarray
Array of size [channels x samples] or [channels x samples x trials] to
find artefacts in.
reject_dim : {'channels','samples','trials'}
......@@ -334,22 +338,21 @@ def detect_artefacts(X, reject_dim='channels', reject_metric='std',
return out
class PCA:
"""The class structure here could be seriously cleaned up and merged into
main sails. Longer term it would be good to use this for dimensionality
reduction of sensor data, and projecting A and associated metrics back into
full space. Currently lots of redundancy and comments/links for my own
education whilst figuring this out.
class PCA(AbstractAnam):
"""
Class for handling PCA-based reduction before fitting a model
"""
Can also be the basis for some of the methods
in: https://doi.org/10.1016/j.jneumeth.2016.12.016 if interesting...
hdf5_outputs = ['npcs', 'data_mean', '_U', '_s', '_VT',
'explained_variance', 'components', 'loadings', 'scores']
I'll update and merge into main sails
"""
def __init__(self, data=None, npcs=None):
AbstractAnam.__init__(self)
def __init__(self, data, npcs):
self.data_mean = data.mean(axis=0)
self._pca_svd(data, npcs)
# Need to cope with no-argument initialisation for anamnesis
if data is not None:
self.data_mean = data.mean(axis=0)
self._pca_svd(data, npcs)
def _pca_svd(self, data, npcs=10):
"""
......@@ -414,3 +417,7 @@ class PCA:
Compute a projection of a set of scores back to original data space
"""
return self.data_mean + np.dot(scores, self.components)
__all__.append('PCA')
register_class(PCA)
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