You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
so, this is super hacked, but something along these lines would be nice, at least in some example somewhere (post-cleanup) so you can keep learning between runs without much overhead
importnumpyasnpimporttimeimportnengofromnengo.solversimportLstsqclassKeepLearningSolver(Lstsq):
""" Loads in weights from a file if they exist, otherwise returns weights from Lstsq solver """def__init__(self, filename, weights=False):
super(KeepLearningSolver, self).__init__(weights=weights)
self.filename=filenamedef__call__(self, A, Y, rng=None, E=None):
importosifos.path.isfile('./%s'%self.filename):
print('Loading weights from %s'%self.filename)
tstart=time.time()
weights=np.load(self.filename)['weights'][-1].Tinfo= {'rmses':'what no stop',
'time':time.time() -tstart}
ifweights.shape[0] !=A.shape[1] orweights.shape[1] !=Y.shape[1]:
raiseException('Stored weights are not correct shape for this connection.')
else:
print('No weights file found, generating with Lstsq solver')
weights, info=super(KeepLearningSolver, self).__call__(A, Y)
returnweights, infomodel=nengo.Network(seed=1)
withmodel:
stim=nengo.Node(lambdax: np.cos(x*2))
a=nengo.Ensemble(n_neurons=500, dimensions=1)
err=nengo.Ensemble(n_neurons=1, dimensions=1,
neuron_type=nengo.Direct())
output=nengo.Ensemble(n_neurons=10, dimensions=1,
neuron_type=nengo.Direct())
nengo.Connection(stim, a)
nengo.Connection(stim, err,
function=lambdax: x**2, transform=-1)
nengo.Connection(output, err)
learn_conn=nengo.Connection(a, output,
learning_rule_type=nengo.PES(learning_rate=1e-5),
solver=KeepLearningSolver('weights.npz'))
nengo.Connection(err, learn_conn.learning_rule)
probe_input=nengo.Probe(stim)
probe_output=nengo.Probe(output, synapse=.01)
probe_weights=nengo.Probe(learn_conn, 'weights',
sample_every=5) # in secondssim=nengo.Simulator(model)
sim.run(11)
np.savez_compressed('weights', weights=sim.data[probe_weights])
importmatplotlib.pyplotaspltplt.plot(sim.trange(), sim.data[probe_input])
plt.plot(sim.trange(), sim.data[probe_output])
plt.legend(['Input', 'Output'])
plt.show()
The text was updated successfully, but these errors were encountered:
so, this is super hacked, but something along these lines would be nice, at least in some example somewhere (post-cleanup) so you can keep learning between runs without much overhead
The text was updated successfully, but these errors were encountered: