def load_Data(): naturalscenes_test = loadexpt(cell_index, "naturalscene", "test", 40) X_test = naturalscenes_test.X y_test = naturalscenes_test.y numTest = (int(X_test.shape[0] / numTime)) * numTime X_test = X_test[:numTest] y_test = y_test[:numTest] X_test = np.reshape(X_test, (int(numTest / numTime), numTime, 40, 50, 50)) y_test = np.reshape(y_test, (int(numTest / numTime), numTime, 1)) return X_test, y_test
def load_Data(): naturalscenes_test = loadexpt(cell_index, 'naturalscene', 'test', 40) X_test = naturalscenes_test.X y_test = naturalscenes_test.y numTest = (int(X_test.shape[0]/numTime))*numTime X_test = X_test[:numTest] y_test = y_test[:numTest] X_test = np.reshape(X_test, (int(numTest/numTime), numTime, 40, 50, 50)) y_test = np.reshape(y_test, (int(numTest/numTime), numTime, 1)) return X_test, y_test
import theano import pyret.filtertools as ft from preprocessing import datagen, loadexpt from utils import rolling_window, mksavedir import h5py from scipy.stats import pearsonr import preprocessing # make save directory save_dir = mksavedir(prefix='Experiment STC') # # Load white noise data # In[2]: whitenoise_train = loadexpt(0, 'whitenoise', 'train', 40, roll=False) # In[5]: import os #f = h5py.File(os.path.join(preprocessing.datadirs['lane.local'], '15-10-07/whitenoise.h5'), 'r') f = h5py.File(os.path.join(preprocessing.datadirs['lenna'], '15-10-07/whitenoise.h5'), 'r') # In[6]: spk = f['spikes/cell01'] # In[8]:
def __init__(self, cell_index, stimulus_type, loss, optimizer, mean_adapt): """ Superclass for managing keras models Parameters ---------- cell_index : int stimulus_type : string Either 'naturalscene' or 'whitenoise' loss : string or object, optional The loss function to use. (Default: poisson_loss) See http://keras.io/objectives/ for more information optimizer : string or object The optimizer to use. (Default: sgd) See http://keras.io/optimizers/ for more information """ # compile the model with notify('Compiling'): self.model.compile(loss=loss, optimizer=optimizer) # save architecture as a json file self.savedir = mksavedir(prefix=str(self)) with notify('Saving architecture'): with open(join(self.savedir, 'architecture.json'), 'w') as f: f.write(self.model.to_json()) # function to write data to a CSV file self.save_csv = partial(tocsv, join(self.savedir, 'performance')) self.save_csv(['Epoch', 'Iteration', 'Training CC', 'Test CC']) # load experimental data self.stimulus_type = stimulus_type if str(self) == 'lstm': numTime = self.stim_shape[0] self.holdout = loadexpt(cell_index, self.stimulus_type, 'test', self.stim_shape[1], mean_adapt=mean_adapt) self.training = loadexpt(cell_index, self.stimulus_type, 'train', self.stim_shape[1], mean_adapt=mean_adapt) X_train = self.training.X y_train = self.training.y X_test = self.holdout.X y_test = self.holdout.y numTrain = (int(X_train.shape[0]/numTime))*numTime numTest = (int(X_test.shape[0]/numTime))*numTime X_train = X_train[:numTrain] y_train = y_train[:numTrain] X_test = X_test[:numTest] y_test = y_test[:numTest] X_train = np.reshape(X_train, (int(numTrain/numTime), numTime, self.stim_shape[1], self.stim_shape[2], self.stim_shape[3])) y_train = np.reshape(y_train, (int(numTrain/numTime), numTime, 1)) X_test = np.reshape(X_test, (int(numTest/numTime), numTime, self.stim_shape[1], self.stim_shape[2], self.stim_shape[3])) y_test = np.reshape(y_test, (int(numTest/numTime), numTime, 1)) self.training = Batch(X_train, y_train) self.holdout = Batch(X_test, y_test) else: self.holdout = loadexpt(cell_index, self.stimulus_type, 'test', self.stim_shape[0], mean_adapt=mean_adapt) self.training = loadexpt(cell_index, self.stimulus_type, 'train', self.stim_shape[0], mean_adapt=mean_adapt) # save model information to a markdown file if 'architecture' not in self.__dict__: self.architecture = 'No architecture information specified' metadata = ['# ' + str(self), '## ' + strftime('%B %d, %Y'), 'Started training on: ' + strftime('%I:%M:%S %p'), '### Architecture', self.architecture, '### Stimulus', 'Experiment 10-07-15', stimulus_type, 'Mean adaptation: ' + str(mean_adapt), 'Cell #{}'.format(cell_index), '### Optimization', str(loss), str(optimizer)] tomarkdown(join(self.savedir, 'README'), metadata)
def __init__(self, cell_index, stimulus_type, loss, optimizer, mean_adapt): """ Superclass for managing keras models Parameters ---------- cell_index : int stimulus_type : string Either 'naturalscene' or 'whitenoise' loss : string or object, optional The loss function to use. (Default: poisson_loss) See http://keras.io/objectives/ for more information optimizer : string or object The optimizer to use. (Default: sgd) See http://keras.io/optimizers/ for more information """ # compile the model with notify('Compiling'): self.model.compile(loss=loss, optimizer=optimizer) # save architecture as a json file self.savedir = mksavedir(prefix=str(self)) with notify('Saving architecture'): with open(join(self.savedir, 'architecture.json'), 'w') as f: f.write(self.model.to_json()) # function to write data to a CSV file self.save_csv = partial(tocsv, join(self.savedir, 'performance')) self.save_csv(['Epoch', 'Iteration', 'Training CC', 'Test CC']) # load experimental data self.stimulus_type = stimulus_type if str(self) == 'lstm': numTime = self.stim_shape[0] self.holdout = loadexpt(cell_index, self.stimulus_type, 'test', self.stim_shape[1], mean_adapt=mean_adapt) self.training = loadexpt(cell_index, self.stimulus_type, 'train', self.stim_shape[1], mean_adapt=mean_adapt) X_train = self.training.X y_train = self.training.y X_test = self.holdout.X y_test = self.holdout.y numTrain = (int(X_train.shape[0] / numTime)) * numTime numTest = (int(X_test.shape[0] / numTime)) * numTime X_train = X_train[:numTrain] y_train = y_train[:numTrain] X_test = X_test[:numTest] y_test = y_test[:numTest] X_train = np.reshape( X_train, (int(numTrain / numTime), numTime, self.stim_shape[1], self.stim_shape[2], self.stim_shape[3])) y_train = np.reshape(y_train, (int(numTrain / numTime), numTime, 1)) X_test = np.reshape( X_test, (int(numTest / numTime), numTime, self.stim_shape[1], self.stim_shape[2], self.stim_shape[3])) y_test = np.reshape(y_test, (int(numTest / numTime), numTime, 1)) self.training = Batch(X_train, y_train) self.holdout = Batch(X_test, y_test) else: self.holdout = loadexpt(cell_index, self.stimulus_type, 'test', self.stim_shape[0], mean_adapt=mean_adapt) self.training = loadexpt(cell_index, self.stimulus_type, 'train', self.stim_shape[0], mean_adapt=mean_adapt) # save model information to a markdown file if 'architecture' not in self.__dict__: self.architecture = 'No architecture information specified' metadata = [ '# ' + str(self), '## ' + strftime('%B %d, %Y'), 'Started training on: ' + strftime('%I:%M:%S %p'), '### Architecture', self.architecture, '### Stimulus', 'Experiment 10-07-15', stimulus_type, 'Mean adaptation: ' + str(mean_adapt), 'Cell #{}'.format(cell_index), '### Optimization', str(loss), str(optimizer) ] tomarkdown(join(self.savedir, 'README'), metadata)