Skip to content

Instantly share code, notes, and snippets.

@hunse
Created May 21, 2019 19:09
Show Gist options
  • Save hunse/6766f39354418fd32c4a39b17c81577e to your computer and use it in GitHub Desktop.
Save hunse/6766f39354418fd32c4a39b17c81577e to your computer and use it in GitHub Desktop.
Count how many Loihi neurons are redundant
import matplotlib.pyplot as plt
import numpy as np
import nengo
import nengo_loihi
def test(n_trials=3):
neurons = np.logspace(1, 3, 20).astype(int)
result = np.zeros((len(neurons), n_trials))
for i, n in enumerate(neurons):
for k in range(n_trials):
with nengo.Network() as net:
nengo_loihi.config.set_defaults()
u = nengo.Node(1.)
a = nengo.Ensemble(n, 1)
c = nengo.Connection(u, a)
with nengo_loihi.Simulator(net) as sim:
block = sim.model.objs[a.neurons]['out']
comp = block.compartment
assert len(block.synapses) == 1
syn = block.synapses[0]
keys = list(zip(comp.bias, syn.weights[0][0]))
result[i, k] = len(np.unique(keys, axis=0)) / n
return neurons, result
neurons, result = test(n_trials=5)
plt.semilogx(neurons, result.mean(axis=1))
plt.semilogx(neurons, result.max(axis=1))
plt.semilogx(neurons, result.min(axis=1))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment