step = {
const inputLayer = new DigitInput();
const inputPSP = new PSP(inputLayer, 0.1);
const stdp = new STDPWeights(DIGIT_SIZE, NUM_NEURONS);
const excitatory_neurons = new NeuronCollection(() => new ALIF, NUM_NEURONS);
const exPSP = new PSP(excitatory_neurons, 0.2);
const inhibitory_neurons = new NeuronCollection(() => new LIF, NUM_NEURONS)
const inhPSP = new PSP(inhibitory_neurons, 0.2);
const display_tau = 0.2;
const inputDisplay = new PSP(inputLayer, display_tau);
const exDisplay = new PSP(excitatory_neurons, display_tau);
let numFiresForRound = 0;
inputLayer.onAdvance = () => numFiresForRound = 0;
return async function(t_step, t) {
await inputLayer.step(t_step, t);
inputPSP.step(t_step);
const weightedInputVals = stdp.weightedOutput(inputPSP.output);
const totalInhibitoryOutput = sum(inhPSP.output);
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
}
}
}