# Released under The MIT License (MIT)
# http://opensource.org/licenses/MIT
# Copyright (c) 2013-2015 SCoT Development Team

""" Use internally implemented functions as backend.
"""

from __future__ import absolute_import

from . import backend


def generate():
    import scipy as sp

    from . import datatools, pca, csp
    from .var import VAR
    from .external.infomax_ import infomax

    def wrapper_infomax(data):
        """ Call Infomax (from MNE) for ICA calculation.
        """
        u = infomax(datatools.cat_trials(data).T).T
        m = sp.linalg.pinv(u)
        return m, u

    def wrapper_pca(x, reducedim):
        """ Call SCoT's PCA algorithm.
        """
        c, d = pca.pca(datatools.cat_trials(x),
                       subtract_mean=False, reducedim=reducedim)
        y = datatools.dot_special(c.T, x)
        return c, d, y

    def wrapper_csp(x, cl, reducedim):
        c, d = csp.csp(x, cl, numcomp=reducedim)
        y = datatools.dot_special(c.T, x)
        return c, d, y

    return {
        'ica': wrapper_infomax,
        'pca': wrapper_pca,
        'csp': wrapper_csp,
        'var': VAR
    }


backend.register('builtin', generate)

@@ -97,9 +97,9 @@
 -201
-5
+6
  SCo
@@ -121,17 +121,16 @@
 eam%0A%0A%22%22%22
- 
 Use inte
@@ -169,17 +169,16 @@
 backend.
-%0A
 %22%22%22%0A%0Afro
@@ -423,25 +423,24 @@
 %0A        %22%22%22
- 
 Call Infomax
@@ -441,16 +441,24 @@
 nfomax (
+adapted 
 from MNE
@@ -479,25 +479,16 @@
 ulation.
-%0A        
 %22%22%22%0A    
@@ -632,17 +632,16 @@
      %22%22%22
- 
 Call SCo
@@ -658,25 +658,16 @@
 gorithm.
-%0A        
 %22%22%22%0A    
@@ -1007,25 +1007,16 @@
 return %7B
-%0A        
 'ica': w
@@ -1030,24 +1030,16 @@
 infomax,
-%0A       
  'pca': 
@@ -1050,24 +1050,16 @@
 per_pca,
-%0A       
  'csp': 
@@ -1079,16 +1079,20 @@
         
+    
 'var': V
@@ -1093,21 +1093,16 @@
 ar': VAR
-%0A    
 %7D%0A%0A%0Aback

Clean up backend_builtin.py