The code associated with the Bachelor's thesis "Dynamic coding in a large-scale, functional, spiking-neuron model". This code can be used to analyse (model) data. (See this repository for a Nengo model that can generate such data.) More specifically, it checks for either the regular or cross-temporal decodability of oriented gratings.
The meat of this code, which can be found in wolff.py and wolff_cross.py, is based on a paper by Wolff and colleagues (2017), called "Dynamic hidden states underlying working-memory-guided behavior".
Code for calculating decodability curves. The file has two main functions: similarity and similarity_p, where the latter is a parallellised and significantly faster version of the former. They have the following signatures:
def similarity(data, theta, angspace, bin_width):
...
return (cos_amp, distances)
def similarity_p(data, theta, angspace, bin_width, num_cores):
...
return (cos_amp, distances)where the parameters indicate the following:
data: atrialsbychannelsbytimestepsnumpy array of EEG/model data;theta: atrialslong numpy array of associated memory item angles;angspace: a numpy array of centres of the bins that will be used to bindata;binwidth: a value that indicates the bin width of the aforementioned bins;num_cores: the maximum number of coressimilarity_pwill use for its calculations.
The returned variables are:
cos_amp: atrialsbytimestepsnumpy array of decodability values, i.e. a decodability curve for every trial fromdata;distances: atrialsbybinsbytimestepsnumpy array of Mahalanobis distances. Mean-centring, convolving with a cosine and taking the mean across thebindimension givescos_amp.
Code for calculating cross-temporal decodability analyses (CTDAs), designed specifically to use GPUs. The main function to call is:
def cross_decode(data, theta, bin_width, sigma=None, device_i=None):
...
return cross_cos_ampwhere the parameters indicate the following:
data: atrialsbychannelsbytimestepsnumpy array of EEG/model data;theta: atrialslong numpy array of associated memory item angles;binwidth: a value that indicates the bin width of the bins. The bin centres (angspace) are hardcoded;sigma(optional): atrialsbytimestepsbychannelsbychannelsnumpy array of inverse covariance matrices. If not given, will be calculated bycross_decode;device_i: the number of which GPU to use. Not optional:cross_decodehas been designed specifically for use with a GPU.
The returned variable is:
cross_cos_amp: atrialsbytimestepsbytimestepsarray of decodability values, i.e. a CTDA for every trial fromdata.
Two Jupyter notebooks have been added that have been involved in personal use and can serve as examples. analyse_decode_mem.ipynb makes use of wolff.py to calculate decodability curves, while analyse_cross.ipynb uses wolff_cross.py to calculate CTDAs.
A Conda environment file, called dynamic-env.yml, has been added to quickly set up the required dependencies.