Skip to content

Commit

Permalink
PES and Voja
Browse files Browse the repository at this point in the history
As implemented by @neworderofjamie

Squashed commit of:

commit 0435762
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 13:52:48 2016 +0100

    Python 3

commit b90e219
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 13:49:54 2016 +0100

    pepepep

commit b9a818b
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 13:44:02 2016 +0100

    PEP8 and fixes

commit 2c60543
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 13:28:13 2016 +0100

    Already bored of build times - made scipy optional and imported it where it's used

commit c0cfe0e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 13:17:57 2016 +0100

    Umm, dependency-resolution much!?!

commit 29ccde0
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 13:15:43 2016 +0100

    lapack

commit 302985e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 13:12:29 2016 +0100

    Attempt alternative means of installing scipy

commit 1b674cf
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 13:10:13 2016 +0100

    Attempt to install scipy from apt-get (reverted from commit 9db5dfc)

commit 9db5dfc
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 13:08:09 2016 +0100

    Attempt to install scipy from apt-get

commit f4eda4a
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 12:26:05 2016 +0100

    Actually, for correctness, binned_statistic was present in 0.11 of SciPy

commit d893ee3
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 12:24:45 2016 +0100

    Scipy dependency

commit c539207
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 12:19:57 2016 +0100

    Binaries

commit 8a409d3
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 12:19:28 2016 +0100

    More tests

commit 4768040
Merge: f7ca695 d33c53e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Mon May 23 12:16:50 2016 +0100

    Merge remote-tracking branch 'origin/master' into new_ensemble-new_learning

    Conflicts:
    	nengo_spinnaker/binaries/nengo_ensemble.aplx
    	nengo_spinnaker/binaries/nengo_ensemble_profiled.aplx
    	nengo_spinnaker/binaries/nengo_filter.aplx
    	nengo_spinnaker/binaries/nengo_mc_player.aplx
    	nengo_spinnaker/binaries/nengo_rx.aplx
    	nengo_spinnaker/binaries/nengo_tx.aplx
    	nengo_spinnaker/binaries/nengo_value_sink.aplx
    	nengo_spinnaker/binaries/nengo_value_source.aplx
    	nengo_spinnaker/operators/lif.py
    	nengo_spinnaker/regions/__init__.py
    	nengo_spinnaker/regions/filters.py
    	nengo_spinnaker/regions/recording.py
    	nengo_spinnaker/simulator.py
    	spinnaker_components/ensemble/Makefile
    	spinnaker_components/ensemble/ensemble.c
    	spinnaker_components/ensemble/ensemble.h
    	spinnaker_components/ensemble/neuron_lif.h
    	spinnaker_components/filter/filter_main.c
    	spinnaker_components/value_sink/value_sink.c
    	tests/operators/test_lif.py
    	tests/regions/test_region_recording.py

commit f7ca695
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Wed Apr 6 12:50:28 2016 +0100

    New executables built with spinnaker tools 2.0.0

commit 53965aa
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Wed Apr 6 12:39:40 2016 +0100

    Updates to profile_communication_channel example including fix for #118

commit 7832e7e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Wed Apr 6 12:29:10 2016 +0100

    Update to spinnaker_tools 2.0.0

commit 58ddf1e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 14 12:52:08 2016 +0000

    Mega-optimisation!

commit 0c3ec0c
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Fri Jan 8 14:34:37 2016 +0000

    whole status is actually quite a lot more useful

commit 536d29e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Fri Jan 8 14:31:37 2016 +0000

    ahh shared memory, it works great when you read from it as well as writing

commit 4f9f4e9
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Fri Jan 8 13:54:19 2016 +0000

    Input filters now get sliced - saves memory and doesn't break Voja implementation

commit e5b040f
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 7 15:13:56 2016 +0000

    region-size mismatch

commit 686f21e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 7 15:13:29 2016 +0000

    use correct RTE code

commit 437fc16
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 7 14:43:20 2016 +0000

    Python side dma transfer of learnt signals

commit d33e3cb
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 7 14:42:59 2016 +0000

    actually run learn_associations on SpiNNaker backend...

commit e857616
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 7 14:42:39 2016 +0000

    Also show errors if application dies during runtime

commit c56051e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 7 14:06:15 2016 +0000

    C-side extended DMA state machine

commit 13385c3
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 7 13:52:03 2016 +0000

    C-side data structures for dma transfer of learnt signals

commit ce9b6fe
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 7 13:51:38 2016 +0000

    Thanks @mundya - never actually hits exit

commit 31cccac
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Jan 7 10:51:12 2016 +0000

    Fix malloc_or_die

    Calls RT_ERROR to kill the core after a malloc fails.

commit 1d2c3a7
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Wed Jan 6 15:59:36 2016 +0000

    Full encoder width should be used for top level partitioning

commit 98fc071
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Wed Jan 6 12:36:35 2016 +0000

    Added additional constraint to SMULL instruction - otherwise (codesourcery) assigns sasme registers for output and input :(

commit 7b9571d
Merge: d9e95f4 e56c246
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Tue Jan 5 18:17:55 2016 +0000

    Merge remote-tracking branch 'origin/recording_buffer_reset' into new_ensemble-new_learning

commit d9e95f4
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Tue Jan 5 18:17:29 2016 +0000

    Improved handling of errors during simulation

commit e56c246
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Tue Jan 5 18:12:57 2016 +0000

    Reset recording regions between simulation runs

commit 0f9bb8d
Author: jamie <neworderofjamie@gmail.com>
Date:   Mon Dec 28 18:46:14 2015 +0000

    Profiling tweaks
    * Re-implemented print-stats in terms of my new favourite function - scipy.stats.binned_statistic
    * Also used this rather than mean for writing CSV rows - generally rather more meaningful

commit 13287c8
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Wed Dec 23 12:24:38 2015 +0000

    Spike recording didn't work on clustered ensembles

commit 52cf92e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Fri Dec 18 11:06:52 2015 +0000

    Extra PES tests

commit 016aa07
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 17 17:27:53 2015 +0000

    test learning rule probing

commit 9bcff4e
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 17 17:16:44 2015 +0000

    Encoder recording test

commit 9dbf316
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 17 16:28:44 2015 +0000

    Executables

commit 0cd4d6a
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 17 16:28:38 2015 +0000

    Voja tests

commit a4c1f41
Author: jamie <neworderofjamie@gmail.com>
Date:   Thu Dec 17 11:40:02 2015 +0000

    beginning of work on PES test - need advice from JH regarding how best to test slicing logic

commit 9607dad
Author: jamie <neworderofjamie@gmail.com>
Date:   Thu Dec 17 11:39:07 2015 +0000

    Caught bug in PESRegion (it's like testing works)

commit 2fa4034
Author: jamie <neworderofjamie@gmail.com>
Date:   Thu Dec 17 10:52:17 2015 +0000

    Learning rule connectivity builder tests

commit b34b4bd
Author: jamie <neworderofjamie@gmail.com>
Date:   Thu Dec 17 10:25:19 2015 +0000

    fixup existing tests, add some to cover learnt_slices etc

commit 7eea2e2
Author: jamie <neworderofjamie@gmail.com>
Date:   Thu Dec 17 10:24:56 2015 +0000

    Fix for numpy 1.8

commit 717041e
Author: jamie <neworderofjamie@gmail.com>
Date:   Wed Dec 16 18:30:51 2015 +0000

    Voja profiling

commit 5e24cd5
Author: jamie <neworderofjamie@gmail.com>
Date:   Wed Dec 16 13:21:50 2015 +0000

    correct SDRAM usage

commit 03918f8
Author: jamie <neworderofjamie@gmail.com>
Date:   Mon Dec 14 15:30:17 2015 +0000

    how the crap did that compile

commit be21a66
Author: jamie <neworderofjamie@gmail.com>
Date:   Mon Dec 14 14:08:32 2015 +0000

    fixed DTCM partitioning

commit 86becf5
Author: jamie <neworderofjamie@gmail.com>
Date:   Mon Dec 14 13:23:00 2015 +0000

    Profiling
    * Tidied up PES function a bit - just takes ensemble pointer rather than numerous parameters
    * Added profiler tags
    * Renamed skip() nop() as it resulted in some epically confusing errors
    * Added PES profiling tags

commit a9c3e0e
Author: jamie <neworderofjamie@gmail.com>
Date:   Mon Dec 14 11:23:39 2015 +0000

    write voja-learnt encoder to write location!

commit b25365a
Author: jamie <neworderofjamie@gmail.com>
Date:   Mon Dec 14 10:11:07 2015 +0000

    Re-figured out matplotlib animation and made animated encoder plot

commit a79cc3e
Author: jamie <neworderofjamie@gmail.com>
Date:   Fri Dec 11 12:32:44 2015 +0000

    Re-added total encoder width parameter - recorded encoders now don't look TOTALLY trashes

commit 101d361
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 10 16:58:28 2015 +0000

    Small bug fixes in scaled encoder recording - still doesn't actually work

commit d9a6ed7
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 10 16:17:26 2015 +0000

    Examples that can be removed from here before merging, but I want to not lose this time :)

commit 7103e0a
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 10 15:26:36 2015 +0000

    pep8

commit 82d3cb5
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 10 15:18:36 2015 +0000

    Correct slicing of PES learning

commit 2c0ce8f
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 10 12:32:43 2015 +0000

    Python side of working Voja
    * Seperate decoders and keys regions for learnt and static decoders
    * Static and learnt output space partitioned seperately
    * 'Properly' disabled filtered activity mode

commit 3fea698
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 10 12:30:54 2015 +0000

    c-side of functioning PES
    * ensemble.parameters hampers anything approximating 80 character lines - assigned to params in a bunch of places
    * Seperate learnt and static decoder and keys regions concatenated when loaded so existing static processing can be employed

commit cdebc38
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Wed Dec 9 16:25:52 2015 +0000

    New C implementation of non-filtered PES

commit 6b43f69
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Wed Dec 9 13:43:28 2015 +0000

    Small bits of python learning which failed to merge

commit 5b29214
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Wed Dec 9 13:43:03 2015 +0000

    * decode_spike_train doesn't belong in the header - Discuss!
    * looping on n suggests neurons which made me more confused than seemed necessary
    * PES can't be updated in simulate_neurons

commit 6448dca
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Fri Dec 4 11:14:57 2015 +0000

    Most of c-code integrated - still needs more thought in places
    * Filtered activity basically disabled

commit 302d31a
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 3 11:33:25 2015 +0000

    flake8

commit e9c2db7
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 3 11:23:25 2015 +0000

    Tidying of include guards #includes to match new names post-rename

commit c9bd1b0
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 3 11:18:05 2015 +0000

    Renames of c files

commit 3801cad
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 3 11:13:40 2015 +0000

    Renamed EnsembleRegions to Regions for terseness - discuss!

commit 67edf4d
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 3 11:02:06 2015 +0000

    Python side of encoder learning

commit 800a3b3
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Thu Dec 3 10:34:38 2015 +0000

    Python side of learning rule re-integration
    * ConnectionMap.get_signals_from_object builds a DEFAULTdict of lists
    * ReceptionParams and TransmissionParams contain reference to learning rule

commit 0e05a33
Author: neworderofjamie <james.knight@manchester.ac.uk>
Date:   Tue Dec 1 17:07:30 2015 +0000

    Updated ensemble builder to use new semantics

commit 4a34ddc
Author: Andrew Mundy <andrew.mundy@ieee.org>
Date:   Mon Oct 12 15:52:43 2015 +0100

    Shared memory ensembles

    Use SDRAM to reduce the communication load presented by Ensembles.  Each
    Ensemble in a `cluster` writes its spike vector into SDRAM and is then
    responsible for decoding a subspace of the entire output space.

commit 497fe48
Author: Andrew Mundy <andrew.mundy@ieee.org>
Date:   Mon Oct 12 15:52:43 2015 +0100

    Shared memory ensembles

    Use SDRAM to reduce the communication load presented by Ensembles.  Each
    Ensemble in a `cluster` writes its spike vector into SDRAM and is then
    responsible for decoding a subspace of the entire output space.

    Includes suggestions by @neworderofjamie

commit 67bc0af
Author: Andrew Mundy <andrew.mundy@ieee.org>
Date:   Thu Oct 15 20:32:26 2015 +0100

    Make Region.sizeof_padded use args, kwargs

    This makes the API more flexible.

commit 7ef8a11
Author: Andrew Mundy <andrew.mundy@ieee.org>
Date:   Sat Dec 5 10:55:34 2015 +0000

    Expand partitioning to deal with multiple slices

    Creates a new `partition_multiple` tool for partitioning multiple slices
    simultaneously; the original `partition` function is rewritten as a
    wrapper for this new function.
  • Loading branch information
mundya committed Jun 9, 2016
1 parent dd87d87 commit 6e7d4b8
Show file tree
Hide file tree
Showing 51 changed files with 2,748 additions and 460 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ script :
after_success : coveralls
notifications:
email: false


145 changes: 145 additions & 0 deletions examples/learn_associations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import numpy as np
import matplotlib.animation as animation
import matplotlib.pyplot as plt

import nengo
import nengo_spinnaker

num_items = 5

d_key = 2
d_value = 4

spinnaker = True
record_encoders = True

rng = np.random.RandomState(seed=7)
keys = nengo.dists.UniformHypersphere(surface=True).sample(num_items, d_key, rng=rng)
values = nengo.dists.UniformHypersphere(surface=False).sample(num_items, d_value, rng=rng)

intercept = (np.dot(keys, keys.T) - np.eye(num_items)).flatten().max()
print("Intercept: %s" % intercept)

def cycle_array(x, period, dt=0.001):
"""Cycles through the elements"""
i_every = int(round(period/dt))
if i_every != period/dt:
raise ValueError("dt (%s) does not divide period (%s)" % (dt, period))
def f(t):
i = int(round((t - dt)/dt)) # t starts at dt
return x[(i/i_every)%len(x)]
return f

# Model constants
n_neurons = 200
dt = 0.001
period = 0.3
T = period*num_items*2

# Model network
model = nengo.Network()
with model:

# Create the inputs/outputs
stim_keys = nengo.Node(output=cycle_array(keys, period, dt))
stim_values = nengo.Node(output=cycle_array(values, period, dt))
learning = nengo.Node(output=lambda t: -int(t>=T/2))
recall = nengo.Node(size_in=d_value)

# Create the memory
memory = nengo.Ensemble(n_neurons, d_key, intercepts=[intercept]*n_neurons)

# Learn the encoders/keys
voja = nengo.Voja(post_tau=None, learning_rate=5e-2)
conn_in = nengo.Connection(stim_keys, memory, synapse=None,
learning_rule_type=voja)
nengo.Connection(learning, conn_in.learning_rule, synapse=None)

# Learn the decoders/values, initialized to a null function
conn_out = nengo.Connection(memory, recall, learning_rule_type=nengo.PES(1e-3),
function=lambda x: np.zeros(d_value))

# Create the error population
error = nengo.Ensemble(n_neurons, d_value)
nengo.Connection(learning, error.neurons, transform=[[10.0]]*n_neurons,
synapse=None)

# Calculate the error and use it to drive the PES rule
nengo.Connection(stim_values, error, transform=-1, synapse=None)
nengo.Connection(recall, error, synapse=None)
nengo.Connection(error, conn_out.learning_rule)

# Setup probes
p_keys = nengo.Probe(stim_keys, synapse=None)
p_values = nengo.Probe(stim_values, synapse=None)
p_learning = nengo.Probe(learning, synapse=None)
p_error = nengo.Probe(error, synapse=0.005)
p_recall = nengo.Probe(recall, synapse=None)

if record_encoders:
p_encoders = nengo.Probe(conn_in.learning_rule, 'scaled_encoders')

if spinnaker:
sim = nengo_spinnaker.Simulator(model)
else:
sim = nengo.Simulator(model)

sim.run(T)
t = sim.trange()

figure, axes = plt.subplots(4, sharex=True)

axes[0].set_title("Keys")
axes[0].plot(t, sim.data[p_keys])
axes[0].set_ylim((-1, 1))

axes[1].set_title("Values")
axes[1].plot(t, sim.data[p_values])
axes[1].set_ylim((-1, 1))

axes[2].set_title("Learning")
axes[2].plot(t, sim.data[p_learning])
axes[2].set_ylim((-1.2, 0.2))

axes[3].set_title("Value error")

train = t<=T/2
axes[3].plot(t[train], sim.data[p_error][train])

test = ~train
axes[3].plot(t[test], sim.data[p_recall][test] - sim.data[p_values][test])


if record_encoders:
# Calculate encoder scale
scale = (sim.model.params[memory].gain / memory.radius)[:, np.newaxis]

# Create figure to show encoder animation
figure, axis = plt.subplots()
axis.set_xlim(-1.5, 1.5)
axis.set_ylim(-1.5, 2)
axis.set_aspect("equal")

# Plot empty encoder and keys scatter
scatter = axis.scatter([],[], label="Encoders")
axis.scatter(keys[:, 0], keys[:, 1], c="red", s=150, alpha=0.6, label="Keys")

# Generate legend
axis.legend()

def initfig():
scatter.set_offsets([[]])
return (scatter,)

def updatefig(frame, encoders):
xy = encoders[frame].copy() / scale
scatter.set_offsets(xy)

return (scatter,)

# Play animation
ani = animation.FuncAnimation(figure, updatefig, init_func=initfig, frames=range(int(T / (2 * dt))),
fargs=(sim.data[p_encoders],), interval=5,
blit=True, repeat=False)

plt.show()
58 changes: 58 additions & 0 deletions examples/learn_communication_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import numpy as np
import matplotlib.pyplot as plt

import nengo
import nengo_spinnaker
from nengo.processes import WhiteSignal

dimensions = 4
spinnaker = True

model = nengo.Network()
with model:
num_neurons = dimensions * 30
inp = nengo.Node(WhiteSignal(num_neurons, high=5), size_out=dimensions)
pre = nengo.Ensemble(num_neurons, dimensions=dimensions)
nengo.Connection(inp, pre)
post = nengo.Ensemble(num_neurons, dimensions=dimensions)
conn = nengo.Connection(pre, post, function=lambda x: np.random.random(dimensions))
inp_p = nengo.Probe(inp)
pre_p = nengo.Probe(pre, synapse=0.01)
post_p = nengo.Probe(post, synapse=0.01)

error = nengo.Ensemble(num_neurons, dimensions=dimensions)
error_p = nengo.Probe(error, synapse=0.03)

# Error = actual - target = post - pre
nengo.Connection(post, error)
nengo.Connection(pre, error, transform=-1)

# Add the learning rule to the connection
conn.learning_rule_type = nengo.PES()

# Connect the error into the learning rule
nengo.Connection(error, conn.learning_rule)

if spinnaker:
sim = nengo_spinnaker.Simulator(model)
else:
sim = nengo.Simulator(model)

sim.run(20.0)

figure, axes = plt.subplots(dimensions + 1, sharex=True)

for a, d in zip(axes, range(dimensions)):
a.plot(sim.trange(), sim.data[inp_p].T[d], c='k', label='Input')
a.plot(sim.trange(), sim.data[pre_p].T[d], c='b', label='Pre')
a.plot(sim.trange(), sim.data[post_p].T[d], c='r', label='Post')

a.set_ylabel("Dimensions 1")
a.legend()

axes[dimensions].plot(sim.trange(), sim.data[error_p], c='b')
axes[dimensions].set_ylim(-1, 1)
axes[dimensions].set_ylabel("Error")
#axes[dimensions].legend(("Error[0]", "Error[1]"), loc='best');

plt.show()
46 changes: 26 additions & 20 deletions examples/profile_communication_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
from nengo.processes import WhiteNoise
from nengo_spinnaker.utils import profiling

# Import functions
from six import iteritems

# Parameters to profile
dimensions = 1
ensemble_size = 200
Expand All @@ -33,23 +36,26 @@
model.config[inp].function_of_time = True
model.config[pre].profile = True

# Create a SpiNNaker simulator and run model
sim = nengo_spinnaker.Simulator(model)
with sim:
sim.run(10.0)

# Read profiler data
profiler_data = sim.profiler_data[pre]

# Open CSV file and create writer
with open("profile_communication_channel.csv", "wb") as csv_file:
csv_writer = csv.writer(csv_file)

# Write header row for CSV with extra columns
# for number of neurons and dimensions
profiling.write_csv_header(profiler_data, csv_writer,
["Num neurons", "Dimensions"])

# Write a row from the profiler data dollo
profiling.write_csv_row(profiler_data, csv_writer,
[ensemble_size, dimensions])
# Create a SpiNNaker simulator and run model
sim = nengo_spinnaker.Simulator(model)
with sim:
sim.run(10.0)

# Read profiler data
profiler_data = sim.profiler_data[pre]

# Open CSV file and create writer
with open("profile_communication_channel.csv", "wb") as csv_file:
csv_writer = csv.writer(csv_file)

# Loop through cores simulating pre-ensemble
for i, (neuron_slice, core_data) in enumerate(iteritems(profiler_data)):
# If this is the first row, write header with extra
# columns for number of neurons and dimensions
if i == 0:
profiling.write_csv_header(core_data, csv_writer,
["Num neurons", "Dimensions"])

# Write a row from the profiler data
profiling.write_csv_row(core_data, 10.0, 0.001, csv_writer,
[neuron_slice[1] - neuron_slice[0], dimensions])
Binary file modified nengo_spinnaker/binaries/nengo_ensemble.aplx
Binary file not shown.
Binary file modified nengo_spinnaker/binaries/nengo_ensemble_profiled.aplx
Binary file not shown.
Binary file modified nengo_spinnaker/binaries/nengo_filter.aplx
Binary file not shown.
Binary file modified nengo_spinnaker/binaries/nengo_mc_player.aplx
Binary file not shown.
Binary file modified nengo_spinnaker/binaries/nengo_rx.aplx
Binary file not shown.
Binary file modified nengo_spinnaker/binaries/nengo_tx.aplx
Binary file not shown.
Binary file modified nengo_spinnaker/binaries/nengo_value_sink.aplx
Binary file not shown.
Binary file modified nengo_spinnaker/binaries/nengo_value_source.aplx
Binary file not shown.
13 changes: 11 additions & 2 deletions nengo_spinnaker/builder/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ def generic_sink_getter(model, conn):


@Model.reception_parameter_builders.register(nengo.base.NengoObject)
@Model.reception_parameter_builders.register(nengo.connection.LearningRule)
@Model.reception_parameter_builders.register(nengo.ensemble.Neurons)
def build_generic_reception_params(model, conn):
"""Build parameters necessary for receiving packets that simulate this
connection.
"""
# Just extract the synapse from the connection.
return ReceptionParameters(conn.synapse, conn.post_obj.size_in)
return ReceptionParameters(conn.synapse, conn.post_obj.size_in,
conn.learning_rule)


class EnsembleTransmissionParameters(object):
Expand All @@ -35,11 +37,14 @@ class EnsembleTransmissionParameters(object):
decoders : array
Decoders to use for the connection.
"""
def __init__(self, decoders, transform):
def __init__(self, decoders, transform, learning_rule):
# Copy the decoders
self.untransformed_decoders = np.array(decoders)
self.transform = np.array(transform)

# Cache learning rule
self.learning_rule = learning_rule

# Compute and store the transformed decoders
self.decoders = np.dot(transform, decoders.T)

Expand All @@ -56,6 +61,10 @@ def __eq__(self, other):
if type(self) is not type(other):
return False

# Equal iff. neither connection has a learning rule
if self.learning_rule is not None or other.learning_rule is not None:
return False

# Equal iff. the decoders are the same shape
if self.decoders.shape != other.decoders.shape:
return False
Expand Down
Loading

0 comments on commit 6e7d4b8

Please sign in to comment.