MATLAB Integrate-and-Fire model fitting code

This software fits the parameters of an SRM, which is a variation of the integrate-and-fire neural model, to a neural voltage data sequence.

The code can be downloaded in this tar archive. The software was developed with MATLAB version R2006a, and NEURON 5.8. It was written for my summer project at Edinburgh, and so the main reference for what it does is my MSc thesis (screen-friendly version, printer-friendly version also available).

Instead of real neural data, the input to the fitting process is a voltage trace produced by a Hodgkin-Huxley model (as implemented in NEURON) in response to a random current. Therefore, the project was partly to demonstrate how well an simple integrate-and-fire model could approximate a complex conductance-based model.

The fitting method follows the work of Renaud Jolivet and colleagues, especially in Jolivet et al. (2004). The method has two main steps:

  1. A template for the shape of spikes is found and extracted from the voltage data.
  2. Linear regression is used to find the convolution kernel that best reproduces the voltage, given the input current.
My key contribution was a direct comparison of two types of kernel, the SIK kernel which was independent of spike times, and the SDK kernel which varied with the time since the last spike.

Key files

makeData directory

Shell scripts, MATLAB and NEURON code for producing the input current and voltage data, using the HH model. Copies the MATLAB and NEURON scripts to the current directory, sets the correct parameters the source files, and runs MATLAB and NEURON.
Other .sh files (e.g. Set up parameters and call Run these to produce the HH data.
whitenoise.m MATLAB file to produce a white noise input current.
input.hoc NEURON file to create the HH voltage in response to input current from a file, and save the output to a file.

k0offset directory

Versions of some of the MATLAB code files for the SDK, modified to include an offset (bias) parameter in the SRM model. It was realised very late in the project that an offset should really be used, and none of the actual results in the thesis are obtained using this code.

Main code files - fitting

mainSIK.m/mainSDK.m Master scripts which load data and call the fitting functions.
defaultParams.m Function which defines/sets up the values of all parameters used.
loadData.m Loads the correct data files, based on parameters set up in by 'defaultParams'.
findEta.m Finds the eta kernel (average spike shape) and subtracts it from u(t).
findSpikeTimes.m Finds the times of spikes using a voltage gradient threshold (called by 'findEta').
findKappaSIK.m Finds the kappa kernel (SIK case).
findKappaSDK.m Finds the kappa kernel (SDK case).
srmForward.m Produces u_SRM(t) for the SIK, by adding eta whenever the threshold is reached.
sdkForward.m Produces v_SRM(t) and u_SRM(t) for the SDK, where v_SRM(t) is found using the correct kappa for the time elapsed since the last spike.
smse.m Calculates the Standardised Mean Squared Error.
gamma.m Calculates the Gamma spike coincidence factor.

Other code files

plot*.m Helper functions to plot data.
expDecayErrGrad.m, expDecayError.m, tanhErrGrad.m, tanhError.m, tanhNegErrGrad.m, tanhNegError.m Functions used when fitting functions to the kappa kernels found.
optimise*.m Run over a range of parameters, and find the best on the basis of SMSE and/or Gamma.
run*.m Code to run the core elements of the SDK fitting procedure, without producing graphs, for use by the optimise*.m functions
thetaVsGamma.m Core code used when plotting the Gamma factor for various theta threshold values.
sikVsSDK.m Script fragments to produce some plots comparing the SIK and SDK outputs.
sta.m, vSpikeAverage.m, upDownBlips.m Scripts to investigate the effects discussed in section 6.3 of the thesis.

Any other code files are mostly experimental approaches to the fitting procedure tried early in the project.


Jolivet R, Lewis T and Gerstner W.
Generalized Integrate-and-Fire Models of Neuronal Activity Approximate Spike Trains of a Detailed Model to a High Degree of Accuracy.
Journal of Neurophysiology 92, 959-976, 2004.

Back to my home page