Giter Club home page Giter Club logo

shah-elife-2020's Introduction

shah-elife-2020

Code for "Nishal P. Shah, N. Brackbill, C. Rhoades, A. Tikidji-Hamburyan, G. Goetz, A. Litke, A. Sher, E. P. Simoncelli, E.J. Chichilnisky. Inference of Nonlinear Receptive Field Subunits with Spike-Triggered Clustering. eLife, 2019. https://doi.org/10.7554/eLife.45743"

Dependencies

The code requires Python 2, Tensorflow 1.x, and other standard libraries such as numpy, scipy and pickle.

Prepare data

The data associated with the paper can be downloaded from "Shah, Nishal et al. (2020), Inference of nonlinear receptive field subunits with spike-triggered clustering, v4, Dryad, Dataset, https://doi.org/10.5061/dryad.dncjsxkvk"

The data for a given figure are loaded using pickle.

import pickle
data = pickle.load(open('Figure_2.pkl', 'rb'))
stim_use, resp_use, stim_dim1, stim_dim2 = (data['A']['stimulus'], data['A']['response'], 
                                            data['A']['stim_dim1'], data['A']['stim_dim2'])

Verify the loaded data.

sta = stim_use.T.dot(resp_use) / np.sum(resp_use)
plt.figure()
plt.imshow(np.reshape(sta[:, 0], [stim_dim1, stim_dim2]), 
         cmap='gray', interpolation='nearest')

sta

Fitting

Set fitting parameters and partition the data.

nsub = 5  # number of subunits.

# Take last 10% as testing, and randomly partition the remaining samples for training and validation. 
frac_test = 0.1  
tms_test = np.arange(np.floor(stim_use.shape[0]*(1 - frac_test)),
	    				   1*np.floor(stim_use.shape[0])).astype(np.int)

frac_validate = 0.1
frac_train = 1 - frac_test - frac_validate
perm = np.random.permutation(tms_train_validate)
tms_train_validate = np.arange(0, np.floor(
	    stim_use.shape[0]*(1 - frac_test))).astype(np.int)
tms_train = perm[0: np.int(np.floor(frac_train * perm.shape[0]))]
tms_validate = perm[np.int(np.floor((1 - frac_validate) * perm.shape[0])): np.int(perm.shape[0])]

Estimate model parameters, without any regularization.

op = su_model.spike_triggered_clustering(stim_use, resp_use, nsub,
                                         tms_train,
                                         tms_validate,
                                         save_filename_partial='test', 
                                         fitting_phases=[1, 2, 3])
k, b, nl_params, lam_log_train, lam_log_validation, fitting_phase, fit_params = op

a) Visualize filters :

for isub in range(nsub):
  plt.subplot(1, nsub, isub + 1)
  plt.imshow(np.reshape(k[:, isub], [stim_dim1, stim_dim2]), cmap='gray', interpolation='nearest')
  plt.xticks([])
  plt.yticks([])

su_noreg

b) Predict firing rate and loss on test data :

fitting_phase = 1
k, b, nl_params = fit_params[fitting_phase] 
pred_test, loss_test = su_model.compute_fr_loss(k, b, stim_use[tms_test, :], resp_use[tms_test, :],
                                    nl_params=nl_params)

Alternatively, use regularization.

For locally normalized L1 regularization (promotes spatial locality, see paper) :

# L1 regularization
lam_proj = 0.1
projection_type = 'lnl1'

# Locally normalized L1 regularization
mask = np.ones((stim_dim1, stim_dim2)).astype(np.bool)
neighbor_mat = su_model.get_neighbormat(mask, nbd=1)
lam_proj = 0.1
projection_type = 'lnl1'

# Fit the model for either regularization.
op = su_model.spike_triggered_clustering(stim_use, resp_use, nsub,
                                         tms_train,
                                         tms_validate,
                                         steps_max=10000, eps=1e-9,
                                         projection_type=projection_type,
                                         neighbor_mat=neighbor_mat,
                                         lam_proj=lam_proj, eps_proj=0.01,
                                         save_filename_partial='test', 
                                         fitting_phases=[1, 2, 3])		
k, b, nl_params, lam_log_train, lam_log_validation, fitting_phase, fit_params = op

The subunits are cleaner (less background noise) for LNL1 regularization. su_reg

shah-elife-2020's People

Contributors

bhaishahster avatar elifeproduction avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.