-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into neuron_implementation_work
- Loading branch information
Showing
6 changed files
with
287 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
p8_integration_tests/test_csa_connectors/test_csa_connectors.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
import spynnaker8 as p | ||
from p8_integration_tests.base_test_case import BaseTestCase | ||
import pylab | ||
import csa | ||
|
||
|
||
def do_run(plot): | ||
|
||
runtime = 3000 | ||
p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) | ||
nNeurons = 200 # number of neurons in each population | ||
p.set_number_of_neurons_per_core(p.IF_curr_exp, nNeurons / 10) | ||
|
||
cell_params_lif = {'cm': 0.25, | ||
'i_offset': 0.0, | ||
'tau_m': 20.0, | ||
'tau_refrac': 2.0, | ||
'tau_syn_E': 5.0, | ||
'tau_syn_I': 5.0, | ||
'v_reset': -70.0, | ||
'v_rest': -65.0, | ||
'v_thresh': -50.0 | ||
} | ||
|
||
populations = list() | ||
projections = list() | ||
|
||
weight_to_spike = 2.0 | ||
delay = 10 | ||
|
||
# connection list in a loop for first population | ||
loopConnections = [] | ||
for i in range(0, nNeurons): | ||
singleConnection = ((i, (i + 1) % nNeurons)) | ||
loopConnections.append(singleConnection) | ||
|
||
# injection list to set the chain going | ||
injectionConnection = [(0, 0)] | ||
spikeArray = {'spike_times': [[0]]} | ||
|
||
# list of populations | ||
populations.append( | ||
p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), | ||
label='pop_1')) | ||
populations.append( | ||
p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), | ||
label='pop_2')) | ||
populations.append( | ||
p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), | ||
label='pop_3')) | ||
populations.append( | ||
p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), | ||
label='pop_4')) | ||
populations.append( | ||
p.Population(1, p.SpikeSourceArray(**spikeArray), | ||
label='inputSpikes_1')) | ||
|
||
# Loop connector: we can just pass in the list we made earlier | ||
CSA_loop_connector = p.CSAConnector(loopConnections) | ||
|
||
# random connector: each connection has a probability of 0.05 | ||
CSA_random_connector = p.CSAConnector(csa.random(0.05)) | ||
|
||
# one-to-one connector: do I really need to explain? | ||
CSA_onetoone_connector = p.CSAConnector(csa.oneToOne) | ||
|
||
# This creates a block of size (5,10) with a probability of 0.05; then | ||
# within the block an individual connection has a probability of 0.3 | ||
csa_block_random = csa.block(15, 10)*csa.random(0.05)*csa.random(0.3) | ||
CSA_randomblock_connector = p.CSAConnector(csa_block_random) | ||
|
||
# list of projections using the connectors above | ||
projections.append(p.Projection( | ||
populations[0], populations[0], CSA_loop_connector, | ||
p.StaticSynapse(weight=weight_to_spike, delay=delay))) | ||
projections.append(p.Projection( | ||
populations[0], populations[1], CSA_random_connector, | ||
p.StaticSynapse(weight=weight_to_spike, delay=delay))) | ||
projections.append(p.Projection( | ||
populations[1], populations[2], CSA_onetoone_connector, | ||
p.StaticSynapse(weight=weight_to_spike, delay=delay))) | ||
projections.append(p.Projection( | ||
populations[2], populations[3], CSA_randomblock_connector, | ||
p.StaticSynapse(weight=weight_to_spike, delay=delay))) | ||
projections.append(p.Projection( | ||
populations[4], populations[0], | ||
p.FromListConnector(injectionConnection), | ||
p.StaticSynapse(weight=weight_to_spike, delay=1))) | ||
|
||
populations[0].record(['v', 'spikes']) | ||
populations[1].record(['v', 'spikes']) | ||
populations[2].record(['v', 'spikes']) | ||
populations[3].record(['v', 'spikes']) | ||
|
||
p.run(runtime) | ||
|
||
# get data (could be done as one, but can be done bit by bit as well) | ||
v = populations[0].spinnaker_get_data('v') | ||
v2 = populations[1].spinnaker_get_data('v') | ||
v3 = populations[2].spinnaker_get_data('v') | ||
v4 = populations[3].spinnaker_get_data('v') | ||
spikes = populations[0].spinnaker_get_data('spikes') | ||
spikes2 = populations[1].spinnaker_get_data('spikes') | ||
spikes3 = populations[2].spinnaker_get_data('spikes') | ||
spikes4 = populations[3].spinnaker_get_data('spikes') | ||
|
||
if plot: | ||
# Use the show functionality of CSA to display connection sets | ||
CSA_loop_connector.show_connection_set() | ||
CSA_random_connector.show_connection_set() | ||
CSA_onetoone_connector.show_connection_set() | ||
CSA_randomblock_connector.show_connection_set() | ||
|
||
# Now plot some spikes | ||
pylab.figure() | ||
pylab.plot([i[1] for i in spikes], | ||
[i[0] for i in spikes], "r.") | ||
pylab.xlabel('Time/ms') | ||
pylab.ylabel('spikes') | ||
pylab.title('spikes: population 1') | ||
|
||
pylab.show() | ||
|
||
pylab.figure() | ||
pylab.plot([i[1] for i in spikes3], | ||
[i[0] for i in spikes3], "g.") | ||
pylab.plot([i[1] for i in spikes4], | ||
[i[0] for i in spikes4], "r.") | ||
pylab.plot([i[1] for i in spikes2], | ||
[i[0] for i in spikes2], "b.") | ||
pylab.xlabel('Time/ms') | ||
pylab.ylabel('spikes') | ||
pylab.title('spikes: populations 2, 3, 4') | ||
|
||
pylab.show() | ||
|
||
p.end() | ||
|
||
return v, v2, v3, v4, spikes, spikes2, spikes3, spikes4 | ||
|
||
|
||
class CSAConnectorTest(BaseTestCase): | ||
def test_run(self): | ||
v, v2, v3, v4, spikes, spikes2, spikes3, spikes4 = do_run(plot=False) | ||
# any checks go here | ||
self.assertEquals(250, len(spikes)) | ||
self.assertLess(2300, len(spikes2)) | ||
self.assertGreater(2600, len(spikes2)) | ||
self.assertLess(2300, len(spikes3)) | ||
self.assertGreater(2600, len(spikes3)) | ||
self.assertLess(3000, len(spikes4)) | ||
self.assertGreater(9000, len(spikes4)) | ||
|
||
|
||
if __name__ == '__main__': | ||
v, v2, v3, v4, spikes, spikes2, spikes3, spikes4 = do_run(plot=True) |
111 changes: 111 additions & 0 deletions
111
p8_integration_tests/test_csa_connectors/test_csa_grid_connectors.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import spynnaker8 as p | ||
from p8_integration_tests.base_test_case import BaseTestCase | ||
import pylab | ||
import csa | ||
|
||
|
||
def do_run(plot): | ||
|
||
p.setup(timestep=1.0) | ||
|
||
cell_params_lif = {'cm': 0.25, | ||
'i_offset': 0.0, | ||
'tau_m': 20.0, | ||
'tau_refrac': 2.0, | ||
'tau_syn_E': 5.0, | ||
'tau_syn_I': 5.0, | ||
'v_reset': -70.0, | ||
'v_rest': -65.0, | ||
'v_thresh': -40.0 | ||
} | ||
|
||
n = 13 # 10 # 5 | ||
p.set_number_of_neurons_per_core(p.IF_curr_exp, n) | ||
weight_to_spike = 2.0 | ||
delay = 5 | ||
runtime = 200 | ||
|
||
# Network | ||
grid = csa.grid2d(n, xScale=1.0*n, yScale=1.0*n) | ||
|
||
# SpikeInjector | ||
injectionConnection = [(0, 0)] | ||
spikeArray = {'spike_times': [[0]]} | ||
inj_pop = p.Population(1, p.SpikeSourceArray(**spikeArray), | ||
label='inputSpikes_1') | ||
|
||
# grid population | ||
grid_pop = p.Population(n*n, p.IF_curr_exp(**cell_params_lif), | ||
label='grid_pop') | ||
|
||
p.Projection(inj_pop, grid_pop, p.FromListConnector(injectionConnection), | ||
p.StaticSynapse(weight=weight_to_spike, delay=delay)) | ||
|
||
# Connectors | ||
exc_connector_set = csa.disc(2.5)*csa.euclidMetric2d(grid) | ||
exc_connector = p.CSAConnector(exc_connector_set) | ||
|
||
inh_connector_set = csa.disc(1.5)*csa.euclidMetric2d(grid) | ||
inh_connector = p.CSAConnector(inh_connector_set) | ||
|
||
# Wire grid | ||
p.Projection(grid_pop, grid_pop, exc_connector, | ||
p.StaticSynapse(weight=2.0, delay=10)) | ||
p.Projection(grid_pop, grid_pop, inh_connector, | ||
p.StaticSynapse(weight=0.5, delay=15)) | ||
|
||
grid_pop.record(['v', 'spikes']) | ||
|
||
p.run(runtime) | ||
|
||
v = grid_pop.spinnaker_get_data('v') | ||
spikes = grid_pop.spinnaker_get_data('spikes') | ||
|
||
if plot: | ||
# original grid | ||
csa.gplot2d(grid, n*n) | ||
|
||
# excitatory connector | ||
exc_connector.show_connection_set() | ||
csa.gplotsel2d(grid, exc_connector_set, range(n*n), range(n*n), N0=n*n) | ||
|
||
# inhibitory connector | ||
inh_connector.show_connection_set() | ||
csa.gplotsel2d(grid, inh_connector_set, range(n*n), range(n*n), N0=n*n) | ||
|
||
# Now plot spikes and v | ||
pylab.figure() | ||
pylab.plot([i[1] for i in spikes], | ||
[i[0] for i in spikes], "r.") | ||
pylab.xlabel('Time/ms') | ||
pylab.ylabel('spikes') | ||
pylab.title('spikes') | ||
|
||
pylab.show() | ||
|
||
pylab.figure() | ||
ticks = len(v) // (n*n) | ||
for pos in range(0, n*n): | ||
v_for_neuron = v[pos * ticks: (pos + 1) * ticks] | ||
pylab.plot([i[2] for i in v_for_neuron]) | ||
pylab.xlabel('Time/ms') | ||
pylab.ylabel('V') | ||
pylab.title('membrane voltages per neuron') | ||
|
||
pylab.show() | ||
|
||
p.end() | ||
|
||
return v, spikes | ||
|
||
|
||
class CSAGridConnectorTest(BaseTestCase): | ||
def test_run(self): | ||
v, spikes = do_run(plot=False) | ||
# any checks go here | ||
self.assertEquals(7224, len(spikes)) | ||
self.assertEquals(33800, len(v)) | ||
|
||
|
||
if __name__ == '__main__': | ||
v, spikes = do_run(plot=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
from spynnaker.pyNN.models.neural_projections.connectors \ | ||
import AbstractConnector | ||
from pyNN.connectors import CSAConnector as PyNNCSAConnector | ||
import CSAConnector as CommonCSAConnector | ||
|
||
|
||
class CSAConnector(AbstractConnector, PyNNCSAConnector): | ||
class CSAConnector(CommonCSAConnector): | ||
""" | ||
Create an CSA (Connection Set Algebra, Djurfeldt 2012) connector. | ||
def __init__(self, cset, safe=True, callback=None): | ||
AbstractConnector.__init__(self, safe=safe) | ||
PyNNCSAConnector.__init__( | ||
self, cset=cset, safe=safe, callback=callback) | ||
raise NotImplementedError | ||
:param cset: a connection set description | ||
:type cset: string | ||
""" | ||
__slots__ = [] | ||
|
||
def __init__( | ||
self, cset, safe=True, callback=None, verbose=False): | ||
# pylint: disable=too-many-arguments | ||
super(CSAConnector, self).__init__( | ||
cset=cset, | ||
safe=safe, callback=callback, verbose=verbose) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters