zhenruiliao / tension

A Python package for FORCE training chaotic neural networks
MIT License
5 stars 2 forks source link

Possibility to perform simulations using weights learned from FORCE #32

Closed dmnburrows closed 1 year ago

dmnburrows commented 1 year ago

Hi there,

Very interested in using your package for FORCE! I had a methodological question which wasn't clear from the paper/github - lets say I am using FORCE to learn the recurrent weights in the reservoir pool to produce neuronal activity traces (like in the zebrafish example). Once the weights have been learned, I want to be able to perform simulations, for example to see how changing the weights of certain neurons in the network changes the network activity - is there a way in tension to simulate this (without any learning occurring)?

Thanks!

lubin-liu commented 1 year ago

One can access the recurrent weights of a layer via esn_layer.recurrent_kernel. With tensorflow tensors you cannot do slice assignments like with numpy, so to modify the weights you would have to use esn_layer.recurrent_kernel.assign(...) with a new tensor of the same shape containing the modified weights (see docs tf.Variable.assign, note that this modifies the tensor in memory so you will lose your original weights). Then, you can run forward pass with force_model.predict(...) to get the output with the new weights. Be careful not to re-assign the weights using esn_layer.recurrent_kernel = .... which will decouple the weights used in the forward pass and training.

dmnburrows commented 1 year ago

Great, thanks! This seems to work