From dc1e5dc869832c45047ff081efb7cf7b18e201ca Mon Sep 17 00:00:00 2001 From: mariakesa Date: Mon, 10 Jun 2019 04:16:59 +0300 Subject: [PATCH] Add two parallel implementations of EP with numpy and pytorch --- EnsemblePursuitNumpy.py | 20 ++++++++++++++++++++ EnsemblePursuitPyTorch.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 EnsemblePursuitNumpy.py create mode 100644 EnsemblePursuitPyTorch.py diff --git a/EnsemblePursuitNumpy.py b/EnsemblePursuitNumpy.py new file mode 100644 index 0000000..205a4df --- /dev/null +++ b/EnsemblePursuitNumpy.py @@ -0,0 +1,20 @@ +import numpy as np + + +class EnsemblePursuitNumpy(): + def __init__(self,n_ensembles,lambd,options_dict): + self.n_ensembles=n_ensembles + self.lambd=lambd + self.options_dict=options_dict + + + def zscore(self,X): + mean_stimuli=np.mean(X,axis=1)[...,np.newaxis] + std_stimuli=np.std(X,axis=1)[...,np.newaxis]+0.0000000001 + X=np.subtract(X,mean_stimuli) + X=np.divide(X,std_stimuli) + return X + + def fit_transform(self,X): + X=self.zscore(X) + print(X) diff --git a/EnsemblePursuitPyTorch.py b/EnsemblePursuitPyTorch.py new file mode 100644 index 0000000..d3c6423 --- /dev/null +++ b/EnsemblePursuitPyTorch.py @@ -0,0 +1,28 @@ +import torch + +class EnsemblePursuitPyTorch(): + def __init__(self, n_ensembles, lambd, options_dict): + self.n_ensembles=n_ensembles + self.lambd=lambd + self.options_dict=options_dict + + def zscore(self,X): + #Have to transpose X to make torch.sub and div work. Transpose back into + #original shape when done with calculations. + mean_stimuli=X.t().mean(dim=0) + std_stimuli=X.t().std(dim=0)+0.0000000001 + + X=torch.sub(X.t(),mean_stimuli) + X=X.div(std_stimuli) + return X.t() + + def fit_transform(self,X): + ''' + X-- shape (neurons, timepoints) + ''' + X=torch.cuda.FloatTensor(X) + X=self.zscore(X) + print(X) + + +