Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
step = {
// Create the input and post-synaptic potential for the input
const inputLayer = new DigitInput();
const inputPSP = new PSP(inputLayer, 0.1);

// STDP-learned weights between input and excitatory layer
const stdp = new STDPWeights(DIGIT_SIZE, NUM_NEURONS);

// Create the excitatory neurons and post-synaptic potential for them
const excitatory_neurons = new NeuronCollection(() => new ALIF, NUM_NEURONS);
const exPSP = new PSP(excitatory_neurons, 0.2);

// Create the inhibitory neurons and post-synaptic potential for them
const inhibitory_neurons = new NeuronCollection(() => new LIF, NUM_NEURONS)
const inhPSP = new PSP(inhibitory_neurons, 0.2);

// These PSPs are used for our display code (they have nothing to do with
// the functionality of the network)
const display_tau = 0.2;
const inputDisplay = new PSP(inputLayer, display_tau); // For displaying input
const exDisplay = new PSP(excitatory_neurons, display_tau); // For displaying excitatory output

// Track the number of neurons that have fired
let numFiresForRound = 0;
inputLayer.onAdvance = () => numFiresForRound = 0; // When our input layer advances, reset our number of fires
return async function(t_step, t) {
await inputLayer.step(t_step, t); // Step the input
inputPSP.step(t_step); // Step input post-synaptic
const weightedInputVals = stdp.weightedOutput(inputPSP.output); // Compute the weighted inputs for the excitatory layer

// Compute the output of the inhibitory layer by...
const totalInhibitoryOutput = sum(inhPSP.output); // Finding the total inhibitory output
// And take the sum *minus* each inhibitory neuron's value to get every other inhibitory neuron's value
const inhibitoryOutputs = inhPSP.output.map((v) => totalInhibitoryOutput - v);

// Compute the input to the excitatory layer as the sum of the weighted input from the digit and the
// inhibitory input
const excitatoryInput = addArrays(weightedInputVals, mulArray(negArray(inhibitoryOutputs), 2));

excitatory_neurons.step(excitatoryInput, t_step); // Step excitatory layer
exPSP.step(t_step); // Step excitatory post-synaptic

inhibitory_neurons.step(excitatory_neurons.output, t_step); // Step inhibitory layer (using excitatory output as its input)
inhPSP.step(t_step); // Step inhibitory post-synaptic

stdp.step(t_step); // Step STDP
stdp.updateWeights(inputLayer.output, excitatory_neurons.output); // Update STDP weights

updateDisplays(t_step, inputDisplay, exDisplay, stdp, excitatory_neurons); // This will update the interactive displays

const numFires = excitatory_neurons.output.filter((val) => val > 0).length; // Number of neurons that fired in this timestep
numFiresForRound += numFires; // Total number of neurons that have fired since this digit has been displayed
if(numFiresForRound > 5) { // If enough neurons have fired...
inputLayer.canAdvance = true; // Then tell the input layer we can advance to the next digit
}
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more