<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import scipy as sp <EOL> from . datatools import atleast_3d , cat_trials , dot_special <EOL> from . import backend <EOL> from . import backend_builtin as builtin <EOL> from . varbase import VARBase <EOL> def generate ( ) : <EOL> from sklearn . decomposition import FastICA <EOL> from sklearn . decomposition import PCA <EOL> def wrapper_fastica ( data , random_state = None ) : <EOL> """<STR_LIT>""" <EOL> ica = FastICA ( random_state = random_state ) <EOL> ica . fit ( cat_trials ( data ) . T ) <EOL> u = ica . components_ . T <EOL> m = ica . mixing_ . T <EOL> return m , u <EOL> def wrapper_pca ( x , reducedim ) : <EOL> """<STR_LIT>""" <EOL> pca = PCA ( n_components = reducedim ) <EOL> pca . fit ( cat_trials ( x ) . T ) <EOL> d = pca . components_ <EOL> c = pca . components_ . T <EOL> y = dot_special ( c . T , x ) <EOL> return c , d , y <EOL> class VAR ( VARBase ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , model_order , fitobj = None , n_jobs = <NUM_LIT:1> , verbose = None ) : <EOL> VARBase . __init__ ( self , model_order = model_order , n_jobs = n_jobs , <EOL> verbose = verbose ) <EOL> if fitobj is None : <EOL> from sklearn . linear_model import LinearRegression <EOL> fitobj = LinearRegression ( fit_intercept = False ) <EOL> self . fitting_model = fitobj <EOL> def fit ( self , data ) : <EOL> """<STR_LIT>""" <EOL> data = atleast_3d ( data ) <EOL> ( x , y ) = self . _construct_eqns ( data ) <EOL> self . fitting_model . fit ( x , y ) <EOL> self . coef = self . fitting_model . coef_ <EOL> self . residuals = data - self . predict ( data ) <EOL> self . rescov = sp . cov ( cat_trials ( self . residuals [ : , : , self . p : ] ) ) <EOL> return self <EOL> backend = builtin . generate ( ) <EOL> backend . update ( { '<STR_LIT>' : wrapper_fastica , '<STR_LIT>' : wrapper_pca , '<STR_LIT>' : VAR } ) <EOL> return backend <EOL> backend . register ( '<STR_LIT>' , generate ) </s>
