# How to store the weights and reproduce them in the next run?

Hello everyone!
I plan to use nengo_bio to create a cerebellum model, using PES online learning rules. So, how do you save the trained weights (decoder and encoder) and reproduce it?
By the way, how to input a pulse of a specified frequency into the entire network?
Any ideas or suggestions are welcome！ Thank you for your questions! You may want to consider to open several threads if you have multiple questions in the future. This may make the questions and their answers easier to find.

Regarding your first question, NengoBio does not use encoders/decoders. Thus, if you have a `bio.Connection` object, you can only access the corresponding full weight matrices. You can access the computed weights as follows (there should also be an example doing this in the NengoBio example notebook):

``````with nengo.Network(seed=5892) as net:
ens_a = bio.Ensemble(n_neurons=101, dimensions=1, p_exc=0.5)
ens_b = bio.Ensemble(n_neurons=102, dimensions=1, p_exc=0.5)

conn = bio.Connection(ens_a, ens_b)

with nengo.Simulator(net) as sim:
wE = sim.data[conn].weights[bio.Excitatory]
wI = sim.data[conn].weights[bio.Inhibitory]
``````

You can restore these weights by simply overriding them at any time during the simulation.

Edit: You might want to use the `[...]` syntax to override the weights in-place, i.e., write

``````sim.data[conn].weights[bio.Excitatory][...] = wE
``````

Regarding your second question, it is a little unclear what you mean by “pulse of a specified frequency”. Per definition, a pulse will be composed of an infinite number of frequencies with non-zero power. If you just want to generate a rectangle signal with a specified `t_on`, `t_off` time you can use the following code:

``````def RectangleSignal(t_on, t_off):
return lambda t: 1.0 if ((t % (t_on + t_off)) < t_on) else 0.0

with nengo.Network() as net:
nd_input = nengo.Node(RectangleSignal(1.0, 1.0))
``````

Thank you very much for your answer. By the way, if I use nengo.Connection and PES connection rules, how can I save and reproduce the connection weight at a certain point?

You can probe the `weights` of a connection. See for example this tutorial:
{"ft_lang_label":"__label__en","ft_lang_prob":0.8508013,"math_prob":0.92534983,"size":2096,"snap":"2022-27-2022-33","text_gpt3_token_len":520,"char_repetition_ratio":0.10372849,"word_repetition_ratio":0.0,"special_character_ratio":0.24045801,"punctuation_ratio":0.17701149,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9820853,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-29T19:05:01Z\",\"WARC-Record-ID\":\"<urn:uuid:611449b7-b7a9-4288-ba08-0fbfc3169ccf>\",\"Content-Length\":\"23192\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:251c104c-f65f-4648-b4cd-62763211e8f0>\",\"WARC-Concurrent-To\":\"<urn:uuid:d75e0226-fbb8-42fc-aad2-efa598de0b43>\",\"WARC-IP-Address\":\"162.243.45.222\",\"WARC-Target-URI\":\"https://forum.nengo.ai/t/how-to-store-the-weights-and-reproduce-them-in-the-next-run/1451\",\"WARC-Payload-Digest\":\"sha1:SJPIPJHWUT2GSNTH5DPQCEHALO3VNF7D\",\"WARC-Block-Digest\":\"sha1:KC5LVHTJLBROWZBCUPDC5XBHZWAS4NMC\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103642979.38_warc_CC-MAIN-20220629180939-20220629210939-00667.warc.gz\"}"}