Yes, I see there has been much talk on this.
So as I get it, in order to save the weights for a connection having a learning rule :
class Mousebrain(nengo.Network) :
def build(self):
with self :
a = nengo.Ensemble(n_neurons=50, dimensions=2, radius=1)
b = nengo.Ensemble(n_neurons=200, dimensions=2)
conn = nengo.Connection(a,b, function=some_function, learning_rule_type=nengo.PES(learning_rate=1e-4, pre_tau=0.1))
self.ws = WeightSaver(conn, 'conn_weights')
I don’t want the weights be initialized at 0 but be optimized towards some_function.
So I change the WeightSaver class and I don’t build a LoadFrom instance as I just want to save the weights
class WeightSaver(object):
def __init__(self, connection, filename, sample_every=None, weights=False):
assert isinstance(connection.pre, nengo.Ensemble)
if not filename.endswith('.npy'):
filename = filename + '.npy'
self.filename = filename
#connection.solver = LoadFrom(self.filename, weights=weights)
self.probe = nengo.Probe(connection, 'weights', sample_every=sample_every)
self.connection = connection
def save(self, sim):
np.save(self.filename, sim.data[self.probe][-1].T)
I create an instance of Mousebrain and a Simulator :
mousebrain = Mousebrain()
mousebrain.build()
mousebrain_sim = nengo.Simulator(mousebrain, dt=0.001)
I run the simulator for some steps
mousebrain_sim.step()
and at some point I call the saver
mousebrain.ws.save(mousebrain_sim)
The file it creates is not readable, containing some gibbrish.
“NUMPY F {‘descr’: ‘<f8’, ‘fortran_order’: True, ‘shape’: (50, 2), }
ÞL\Þ¡Ç?Uø… and more like this
Is that the expected behavior?