HTTPS SSH
Source code for the paper "Dendritic nonlinearities are tuned for efficient spike-based
computations in cortical circuits" by Ujfalussy, Makara, Branco and Lengyel appearing in 
eLife in 2015. The code has been written by Balazs Ujfalussy (balazs.ujfalussy@gmail.com)

The code is written in R and was tested in OSX (Lion, Mavericks, Yosemite) and on 
various linux clusters. This code can be used to reproduce Figures 1-4 of the paper. 

/***************************/
The main directory contains the following high level scripts:

Popact.R: Generates popualtion activity (membrane potential + spiking) as shown in Figs 1,2,4,5 
of the paper given the parameters of the neurons (see  Figure 2—figure supplement 1.) 

/***************************/
Inference.R: This script can be used to predict the optimal response for a given presynaptic
statistics and the input spike patterns - i.e., to perform inference in the model (Eq. 20-22). 
This was used the calculate the opitmal response in all Figures.

Performance.R: Calculates the error made by different estimators (Fig. 4.)

DataFit.R: Predict response to experiments shown in Fig. 5 and compares it with the
hippocampal and neocortical data.

/***************************/
The directories contain several functions implementing these algorithms. In particular

swOU: algorithms to generate data and perform inference in the switching OU model.

swOU_sil: similar to swOU but includes the possibility to perform inference in the presence of
silent neurons. These cells have similar parameters as other neurons, just they did not happen to be
active during the observed period (e.g., in our in vitro experiments, these cells are the targeting
the those dendritic spines that did not receive uncaging stimulus on the same branch.) As the
posterior is the same for all these cells (both the prior and the likelihood are the same), the
inference is computationally more efficient if we do not explicitely model all of them. In this way
we easily can perform inference for N > 100.

fit_LNmodel: funtions to fit a Linear Nonlinear (LN) cascade model to approximate the optimal
response. The functions for the optimization are in the directoryes SU and SU_id.

SU: training the LN models is based on gradient descent. These functions are required to simulate an
LN model (Sim_), Initialise it for training (Init_), calculate the gradient of the error wrt. its
parameters (Grad_ and Err_) and to manage the training process (Train_).

SU_id: similar to SU, but the parameters of all dendritic subunits are identical 

DataFit: Experimental data (ExpData.RData), postsynaptic parameters fitted (FittedPars.RData) and
the errors between the model's prediction and the experimental data (Errors.RData). Also contains a
script that calculates the predictions for different experimental protocols.

graphics: some graphical scripts

functions: general functions used by different algorithms

/***************************/

The experimental data is presented in the following format:
ExpData is a list of 20 elements. Each element is itself a list corresponding to
particular recording. There are 4 types of recordings - indicated by their name: 
	- HP1-6: recording from hippocampal cells; 
	- NC1-6 neocortical cells; 
	- HP_APV1-5: hippocampal cells in the presence of NMDA blocker APV
	- NC_APV1-3: neocortical cells in the presence of NMDA blocker APV

For each recording the following data is given:
	- resp: matrix of M x L , each row is the average recorded somatic membrane potential for a
particualr stimulation pattern (L = 500, sampling rate: 2000 Hz, M is the number of different
stimulation patterns). The first row is a double-exponential fit to the average EPSP elicited by
stimulating the spines individually.

 - a.sp: a binary (NA-1) vector indicating the position of the responsive
spines within the stimulation sequence.

 - delay: M-long vector containing the inter stimulution interval used for
the uncaging in a given trial (ms; NA if n.stim = 1)

 - n.stim: M-long vector containing the number of spines stimulated in a given trial

 - dendr.delay: scalar, the delay between the somatic response and the dendritic
stimulation (ms)