-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add two parallel implementations of EP with numpy and pytorch
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
||
|