"""Ordinary NEF connection: different spikes, approximately the same scalar. Isolated teaching circuit, not an articulatory simulation or productive study. Run: python make_connection_example.py [--figures-only] Requires nengo 4.1.0, numpy, matplotlib. Outputs are placed in figures/. """ from pathlib import Path import hashlib, json, sys import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import nengo import numpy as np HERE=Path(__file__).resolve().parent OUT=HERE/'figures' DT=.001 DURATION=2.4 BLUE,ORANGE,GREY='#245b78','#ac572b','#89959c' def stimulus(t): if t < .1: return 0. if t < .8: return .65 if t < 1.6: return -.55 return .35 def run(): with nengo.Network(seed=241, label='Ordinary communication channel') as model: model.config[nengo.Ensemble].neuron_type=nengo.LIF() model.config[nengo.Ensemble].max_rates=nengo.dists.Uniform(80,160) value=nengo.Node(stimulus, label='Supplied scalar') source=nengo.Ensemble(100,1,seed=2411,label='Source') recipient=nengo.Ensemble(100,1,seed=2412,label='Recipient') nengo.Connection(value,source,synapse=.01) channel=nengo.Connection(source,recipient,transform=1.,synapse=.01) probes={'input':nengo.Probe(value)} for key,pop in [('source',source),('recipient',recipient)]: probes[key]=nengo.Probe(pop,synapse=.01) probes[key+'_spikes']=nengo.Probe(pop.neurons) with nengo.Simulator(model,dt=DT,progress_bar=False) as sim: sim.run(DURATION,progress_bar=False) data={k:sim.data[p].copy() for k,p in probes.items()} data['time']=sim.trange() for key,pop in [('source',source),('recipient',recipient)]: data[key+'_encoders']=sim.data[pop].encoders.copy() data[key+'_gain']=sim.data[pop].gain.copy() data[key+'_bias']=sim.data[pop].bias.copy() # Nengo implements the identity channel in factored form. The effective # neuron-to-neuron matrix combines source decoders and target encoders. data['channel_decoders']=sim.data[channel].weights.copy() data['effective_weights']=sim.data[recipient].scaled_encoders @ sim.data[channel].weights np.savez_compressed(OUT/'connection-recording.npz',**data) summaries=[] for name,a,b,target in [('Positive',.3,.7,.65),('Negative',1.,1.5,-.55),('Smaller positive',1.8,2.3,.35)]: mask=(data['time']>=a)&(data['time']