-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tools for saving and loading decoders #35
Comments
Oh, and one of the things I'm thinking about proposing for def on_sim_done(sim):
# this will get triggered when the simulation is over
weight_saver.save(sim) |
Sure you can. You just make a connection from the neurons to the post object as in case 1. E.g. import matplotlib.pyplot as plt
import numpy as np
import nengo
n_neurons = 200
initial = np.random.uniform(-0.0001, 0.0001, size=(1, n_neurons))
with nengo.Network() as model:
x = nengo.Node(nengo.processes.WhiteSignal(period=100, high=5))
ystar = nengo.Node(lambda t, x: x**2, size_in=1)
nengo.Connection(x, ystar)
a = nengo.Ensemble(n_neurons, 1)
y = nengo.Node(size_in=1)
error = nengo.Node(size_in=1)
nengo.Connection(y, error)
nengo.Connection(ystar, error, transform=-1)
conn = nengo.Connection(a.neurons, y, transform=initial,
learning_rule_type=nengo.PES(1e-3))
nengo.Connection(error, conn.learning_rule)
xp = nengo.Probe(x, synapse=0.01)
ystarp = nengo.Probe(ystar, synapse=0.01)
yp = nengo.Probe(y, synapse=0.01)
with nengo.Simulator(model) as sim:
sim.run(15.0)
plt.plot(sim.trange(), sim.data[xp])
plt.plot(sim.trange(), sim.data[ystarp])
plt.plot(sim.trange(), sim.data[yp])
plt.show() |
Huh. I had no idea you could do that. That makes complete sense in hind-sight.... |
In nengo/nengo#649 and nengo/nengo#608 (and maybe other places), there have been requests for ways to save and load decoders. There are two common use cases:
you've computed decoders in some weird way and would like to use those instead
you're using a learning rule and would like to start the learning rule off with the decoders from the end point of a previous run.
Use case 1 can usually be handled by doing
nengo.Connection(a.neurons, b, transform=decoders)
. However, this doesn't work everywhere -- for example,nengo_spinnaker
doesn't allow Connections from.neurons
. Use case 2 is even more problematic -- there's currently no way to seed the start of a learning rule with anything other than the result of someSolver
.The workaround that a few people have implemented is to define a Solver that just returns whatever matrix you've explicitly told it to:
This is quite handy for use case 1, and should at least be put into
nengo_extras
(and maybe even into corenengo
).This also forms the good basis for a solution to use case 2, and indeed it's not too bad to explicitly implement use case 2 with this
Explicit
solver:But that's rather ugly. You have to open the file, handle the initial case when the file doesn't exist, create a probe, and save the data at the end (remembering to take the transpose). So let's make a helper for this:
In order to use this, we can do something like this, only needing to add 2 lines to the whole thing:
One interesting feature of this approach is that it loads the file at build time. I think that's what we usually want....
The text was updated successfully, but these errors were encountered: