ANNarchy provides a set of predefined Population
objects to ease the definition of standard networks.
ANNarchy.
PoissonPopulation
(geometry, name=None, rates=None, target=None, parameters=None, refractory=None)[source]¶Population of spiking neurons following a Poisson distribution.
Case 1: Input population
Each neuron of the population will randomly emit spikes, with a mean firing rate defined by the rates argument.
The mean firing rate in Hz can be a fixed value for all neurons:
pop = PoissonPopulation(geometry=100, rates=100.0)
but it can be modified later as a normal parameter:
pop.rates = np.linspace(10, 150, 100)
It is also possible to define a temporal equation for the rates, by passing a string to the argument:
pop = PoissonPopulation(geometry=100, rates="100.0 * (1.0 + sin(2*pi*t/1000.0) )/2.0")
The syntax of this equation follows the same structure as neural variables.
It is also possible to add parameters to the population which can be used in the equation of rates:
pop = PoissonPopulation(
geometry=100,
parameters = '''
amp = 100.0
frequency = 1.0
''',
rates="amp * (1.0 + sin(2*pi*frequency*t/1000.0) )/2.0"
)
Note
The preceding definition is fully equivalent to the definition of this neuron:
poisson = Neuron(
parameters = '''
amp = 100.0
frequency = 1.0
''',
equations = '''
rates = amp * (1.0 + sin(2*pi*frequency*t/1000.0) )/2.0
p = Uniform(0.0, 1.0) * 1000.0 / dt
''',
spike = '''
p < rates
'''
)
The refractory period can also be set, so that a neuron can not emit two spikes too close from each other.
Case 2: Hybrid population
If the rates
argument is not set, the population can be used as an interface from a rate-coded population.
The target
argument specifies which incoming projections will be summed to determine the instantaneous firing rate of each neuron.
See the example in examples/hybrid/Hybrid.py
for a usage.
Parameters:
ANNarchy.
SpikeSourceArray
(spike_times, name=None)[source]¶Spike source generating spikes at the times given in the spike_times array.
Depending on the initial array provided, the population will have one or several neurons, but the geometry can only be one-dimensional.
Parameters:
You can later modify the spike_times attribute of the population, but it must have the same number of neurons as the initial one.
The spike times are by default relative to the start of a simulation (ANNarchy.get_time()
is 0.0).
If you call the reset()
method of a SpikeSourceArray
, this will set the spike times relative to the current time.
You can then repeat a stimulation many times.
# 2 neurons firing at 100Hz with a 1 ms delay
times = [
[ 10, 20, 30, 40],
[ 11, 21, 31, 41]
]
inp = SpikeSourceArray(spike_times=times)
compile()
# Spikes at 10/11, 20/21, etc
simulate(50)
# Reset the internal time of the SpikeSourceArray
inp.reset()
# Spikes at 60/61, 70/71, etc
simulate(50)
ANNarchy.
TimedArray
(rates, schedule=0.0, period=-1.0, name=None)[source]¶Data structure holding sequential inputs for a rate-coded network.
Parameters:
The input values are stored in the (recordable) attribute r
, without any further processing. You will need to connect this population to another one using the connect_one_to_one()
method.
By default, the firing rate of this population will iterate over the different values step by step:
inputs = np.array(
[
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
]
)
inp = TimedArray(rates=inputs)
pop = Population(10, ...)
proj = Projection(inp, pop, 'exc')
proj.connect_one_to_one(1.0)
compile()
simulate(10.)
This creates a population of 10 neurons whose activity will change during the first 10*dt milliseconds of the simulation. After that delay, the last input will be kept (i.e. 1 for the last neuron).
If you want the TimedArray to “loop” over the different input vectors, you can specify a period for the inputs:
inp = TimedArray(rates=inputs, period=10.)
If the period is smaller than the length of the rates, the last inputs will not be set.
If you do not want the inputs to be set at every step, but every 10 ms for example, youcan use the schedule
argument:
inp = TimedArray(rates=inputs, schedule=10.)
The input [1, 0, 0,…] will stay for 10 ms, then[0, 1, 0, …] for the next 10 ms, etc…
If you need a less regular schedule, you can specify it as a list of times:
inp = TimedArray(rates=inputs, schedule=[10., 20., 50., 60., 100., 110.])
The first input is set at t = 10 ms (r = 0.0 in the first 10 ms), the second at t = 20 ms, the third at t = 50 ms, etc.
If you specify less times than in the array of rates, the last ones will be ignored.
Scheduling can be combined with periodic cycling. Note that you can use the reset()
method to manually reinitialize the TimedArray, times becoming relative to that call:
simulate(100.) # ten inputs are shown with a schedule of 10 ms
inp.reset()
simulate(100.) # the same ten inputs are presented again.
ANNarchy.extensions.image.
ImagePopulation
(geometry, name=None)[source]¶Specific rate-coded Population allowing to represent images (png, jpg…) as the firing rate of a population (each neuron represents one pixel).
This extension requires the Python Image Library (pip install Pillow).
Usage:
from ANNarchy import *
from ANNarchy.extensions.image import ImagePopulation
pop = ImagePopulation(geometry=(480, 640))
pop.set_image('image.jpg')
Parameters:
About the geometry:
If the third dimension is 3, each will correspond to the RGB values of the pixels.
Warning
Due to the indexing system of Numpy, a 640*480 image should be fed into a (480, 640) or (480, 640, 3) population.
ANNarchy.extensions.image.
VideoPopulation
(geometry, name=None)[source]¶Specific rate-coded Population allowing to feed a webcam input into the firing rate of a population (each neuron represents one pixel).
This extension requires the C++ library OpenCV >= 2.0 (apt-get/yum install opencv). pkg-config opencv --cflags --libs
should not return an error.
Usage :
from ANNarchy import *
from ANNarchy.extensions.image import VideoPopulation
pop = VideoPopulation(geometry=(480, 640))
compile()
pop.start_camera(0)
while(True):
pop.grab_image()
simulate(10.0)
Parameters:
About the geometry:
If the third dimension is 3, each will correspond to the RGB values of the pixels.
Warning
Due to the indexing system of Numpy, a 640*480 image should be fed into a (480, 640) or (480, 640, 3) population.