Repository for the code used in developing, testing and using MINE. The paper "Model discovery to link neural activity to behavioral tasks" which publishes this code can be found at:
Costabile JD, Balakrishnan KA, Schwinn S, Haesemeyer M (2023) eLife 12:e83289
Simple to use interface to apply MINE to data as described in the last paper figure and below.
Includes the class definition of the CNN that forms the core of MINE.
Contains routines for Taylor decomposition and associated metrics.
Analysis scripts for the zebrafish random wave data demonstrating using MINE outside the mine.py interface.
Contains general helper functions for data management, clustering, etc.
The Mine
class in mine.py is the main interface to MINE.
Data is returned in a MineData
object defined in mine.py as well.
An example for running MINE is given in processMusall.py as well as below:
import numpy as np
from typing import List
from mine import Mine
import h5py
predictors: List[np.ndarray] # list of m_timepoints long vectors of predictors
for p in predictors:
# z-score all predictors
p -= np.mean(p)
p /= np.std(p)
responses: np.ndarray # n_responses * m_timepoints matrix of responses to fit
# z-score responses
responses -= np.mean(responses)
responses /= np.std(responses)
# Create Mine object with the following options:
# Use 2/3 of the timepoints for traning last third for testing
# Use 50 timepoints as model history - NOTE: Shifting predictors relative to responses
# allows to capture preparatory activity as well see processMusall.py
# Consider any neuron with a test correlation >= 0.5 as fit by MINE
# only for these neurons will metrics be computed
# Compute Taylor metrics including complexity/nonlinearity evaluation
# Return receptive fields (network jacobians). To perform exhaustive receptive field
# analysis as in cnn_sta_test.py, set miner.return_hessians to True and extract
# principal dynamic modes from joint matrix created from Jacobians and Hessians
# (see cnn_sta_test.py and paper Methods section for details)
# To calculate Taylor metrics predict 25 frames ahead
# Compute metrics every five frames
miner = Mine(2.0/3, 50, 0.5, True, True, 25, 5)
# create file to store fit model weights during analysis
with h5py.File("model_data.hdf5", "w") as model_file:
miner.model_weight_store = model_file
# analyze data with this MINE object, returning MineData object - since miner.model_weight_store was set
# whenever a model is fit and passes threshold its weights will be stored in a group
# with the name cell_{index}_weights
mine_data = miner.analyze_data(predictors, responses)
# save mine_data to hdf5 file
with h5py.File("result.hdf5", 'w') as dfile:
mine_data.save_to_hdf5(dfile)
Panels for test figures of MINE were generated using cnn_fit_test.py, cnn_sta_test.py, mine_edf.py and cnn_nonlin_test.py. Panels for the figure on mouse cortical data were generated using plotMusall.py. Panels for zebrafish figures were generated using rwave_plot_panels.py and rspinal_plot_panels.py.
All required dependencies are listed in environment_utf8.yml
Raw acquisition data in NWB format is deposited on DANDI in the following DANDIsets:
Final project data (generated by running rwave_build_main.py, rspinal_build_main.py, and processMusall.py ) are deposited on zenodo.org:
Fit model weight data for the zebrafish and mouse cortex dataset are deposited on zenodo.org split across the folllowing two repositories. These weights were generated by running rwave_data_fit.py and processMusall.py respectively:
All code is licensed under the MIT license. See LICENSE for details.
© Martin Haesemeyer, Kaarthik A Balakrishnan and Jamie D Costabile, 2020-2023