File Exchange

image thumbnail

Easily Simulate Custom Networks of LIF Neurons

version 1.1 (8.53 KB) by Zachary Danziger
Design and simulate your leaky integrate and fire (LIF) neuron network in only a few lines of code.


Updated 31 Jul 2020

View License

In only a few lines of code you can customize and simulate a network of leaky integrate and fire neurons (LIF). This function facilitates quick testing of network architectures. The network can be simple, only specifying the weights of the connections between neurons, or complex with options ranging from offset currents, refractory periods, speed of synaptic transmission, noise, etc.
Usage notes, extensive examples, and sources are given in the help.

Cite As

Zachary Danziger (2020). Easily Simulate Custom Networks of LIF Neurons (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (8)

@Antonio, The bug is fixed, and would only affect simulations where there were unconnected neurons, so all your other results were accurate.

Because of accummarray behavior, the code would halt if there were neurons not connected to any other neurons, unless 1) no neurons were connected (in which case the code was accurate) or 2) only the first neuron was connected (in which case all neurons received the first neuron's input because the array of synaptic currents ended up being a scalar that MATLAB added to all neurons without throwing an error). Anyway, the issue is resolved.

@Elia, Your error seems like it is a problem with getting this function on your MATLAB path, not this function itself.

I have tried
>> W = log(abs(randn(12)));
>> [spk NetParams V] = SimLIFNet(W,'simTime',35,'tstep',1e-2,'offsetCurrents',1.1*ones(length(W),1));

Attempt to execute SCRIPT SimLIFNet as a function:
Please advise

I tried to run the software but without success. This is the error message
>> SimLIFNet
Unrecognized function or variable 'etimLIFNetfunction'.

Error in SimLIFNet (line 1)
etimLIFNetfunction [spk NetParams V] = SimLIFNet(W,varargin)

Could you please advise. Thanks

This is an interesting bug. Exploring just a bit more, I am able to get more strange behavior (and I can even get the code to halt with an error) in cases where there is a single neuron that is not connected to any other neurons in the network. It is a case I never tested during development. As far as I can tell, when there are no unconnected neurons the code runs accurately, so I suspect this is a problem with the way indexing works in the code.
I have not been maintaining this code in the past few years, but hopefully next month I will have a bit of time to track down the bug. In the meantime, it should work for typical networks where there are no neurons left unconnected.

Dear Zachary,
your code is indeed great to play with integrate and fire networks.
I noticed however a strange behavior with self connections (i.e. connections from a neuron onto itself). I am attaching below the code to replicate the behavior I observed.

If you run the following code:
[spk NetParams V] = SimLIFNet(W,'simTime',35,'tstep',1e-2, ...
'offsetCurrents',[0.8 0.8 0.8]','forcingFunctions',Ffcns);
Ffcns = {@(t) 1.5*heaviside(t-10), 1; @sin, 2};
W = [0 0 0; 0 0 0; 0 0 0];

The spike trains of the three simulated neurons are independent one of the other since no connectivity is specified in the matrix W. However, if you add a self connection, for example, in neuron 1 (i.e. you modify W as W=W = [.5 0 0; 0 0 0; 0 0 0];) then this will affect not only the spiking behavior of neuron 1 (as expected) but that of ALL three neurons.

Why is that the case?
Antonino Casile


Helpful for starter kit of LIF in Matlab
Many thanks

Great for getting started with LIF in matlab! Thanks!



% Bugfix: Updated accumarray call to output as many elements as there are
% neurons to avoid synamptic contribution errors when there are neurons in
% the network that have no connections to other neurons. ZC Danziger July 2020

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux