<jupyter_start><jupyter_text>AdditionIn this example, we will construct a network that adds two inputs.The network utilizes two communication channelsinto the same neural population.Addition is thus somewhat 'free', since the incoming currentsfrom different synaptic connections interact linearly(though two inputs don't have tocombine in this way; see the combining demo).<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt

import nengo<jupyter_output><empty_output><jupyter_text>Step 1: Create the ModelThe model has three ensembles, which we will call A, B, and C.<jupyter_code># Create the model object
model = nengo.Network(label="Addition")
with model:
    # Create 3 ensembles each containing 100 leaky integrate-and-fire neurons
    A = nengo.Ensemble(100, dimensions=1)
    B = nengo.Ensemble(100, dimensions=1)
    C = nengo.Ensemble(100, dimensions=1)<jupyter_output><empty_output><jupyter_text>Step 2: Provide Input to the ModelWe will use two constant scalar values for the two input signalsthat drive activity in ensembles A and B.<jupyter_code>with model:
    # Create input nodes representing constant values
    input_a = nengo.Node(output=0.5)
    input_b = nengo.Node(output=0.3)

    # Connect the input nodes to the appropriate ensembles
    nengo.Connection(input_a, A)
    nengo.Connection(input_b, B)

    # Connect input ensembles A and B to output ensemble C
    nengo.Connection(A, C)
    nengo.Connection(B, C)<jupyter_output><empty_output><jupyter_text>Step 3: Probe OutputLet's collect output data from each ensemble and output.<jupyter_code>with model:
    input_a_probe = nengo.Probe(input_a)
    input_b_probe = nengo.Probe(input_b)
    A_probe = nengo.Probe(A, synapse=0.01)
    B_probe = nengo.Probe(B, synapse=0.01)
    C_probe = nengo.Probe(C, synapse=0.01)<jupyter_output><empty_output><jupyter_text>Step 4: Run the ModelIn order to run the model, we have to create a simulator.Then, we can run that simulator over and over againwithout affecting the original model.<jupyter_code># Create the simulator
with nengo.Simulator(model) as sim:
    # Run it for 5 seconds
    sim.run(5)<jupyter_output><empty_output><jupyter_text>The data produced by running the model can now be plotted.<jupyter_code># Plot the input signals and decoded ensemble values
t = sim.trange()
plt.figure()
plt.plot(sim.trange(), sim.data[A_probe], label="Decoded Ensemble A")
plt.plot(sim.trange(), sim.data[B_probe], label="Decoded Ensemble B")
plt.plot(sim.trange(), sim.data[C_probe], label="Decoded Ensemble C")
plt.plot(
    sim.trange(), sim.data[input_a_probe], label="Input A", color="k", linewidth=2.0
)
plt.plot(
    sim.trange(), sim.data[input_b_probe], label="Input B", color="0.75", linewidth=2.0
)
plt.legend()
plt.ylim(0, 1)
plt.xlabel("time [s]")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10184528034066714, 'fraction_numerical': 0.015613910574875798, 'mean_word_length': 5.349099099099099, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '263027', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 988, 'n_tokens_neox': 910, 'n_words': 277, 'path': 'docs/examples/basic/addition.ipynb', 'repo_name': 'Michaeljurado24/nengo', 'size': '2818'}