Skip to content

Commit

Permalink
Add two parallel implementations of EP with numpy and pytorch
Browse files Browse the repository at this point in the history
  • Loading branch information
mariakesa committed Jun 10, 2019
1 parent c307ace commit dc1e5dc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions EnsemblePursuitNumpy.py
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 28 additions & 0 deletions EnsemblePursuitPyTorch.py
Original file line number Diff line number Diff line change
@@ -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)



0 comments on commit dc1e5dc

Please sign in to comment.