Public
Edited
Jul 18, 2024
1 fork
Insert cell
Insert cell
Insert cell
function signal(t) {
return 2*Math.sin(t);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function activity_level(i, lif) {
const T_STEP = 1e-3;
const T = 0.2;
let spikeCount = 0;
lif.reset();
for(let t = 0; t<=T; t+=T_STEP) {
const output = lif.step(i, T_STEP);
if(output > 0) {
spikeCount++;
}
}
return spikeCount / T;
}
Insert cell
function computeGamma(lif, range_low, range_high, interval) {
let gamma = 0;
const di = interval;
for(let i = range_low; i<=range_high; i+=interval) {
gamma += di * Math.pow(activity_level(i, lif), 2);
}

return gamma;
}
Insert cell
function computeUpsilon(lif, range_low, range_high, interval) {
let upsilon = 0;
const di = interval;
for(let i = range_low; i<=range_high; i+=interval) {
upsilon += di * i * activity_level(i, lif);
}
return upsilon;
}
Insert cell
function computePhi(lif, range_low=-1, range_high=1, interval=1e-2) {
return computeUpsilon(lif, range_low, range_high, interval) / computeGamma(lif, range_low, range_high, interval);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
class NeuronCollection {
constructor(createNeuronFn, n) { // createNeuronFn is a function to create a neuron instance. n is the number of neurons
this.neurons = []; // Neuron instances

// Create n neurons
for(let i = 0; i<n; i++) {
this.neurons.push(createNeuronFn(i));
}

this.output = this.neurons.map(neuron => neuron.output); // Assign our output to be a list of neuron outputs
}

step(inputs, t_step) {
// Step every individual neuron
// Assign this.output to the neurons' outputs
// Return this.output
return this.output = this.neurons.map((neuron, i) => neuron.step(inputs[i], t_step));
}
}
Insert cell
Insert cell
function getLIFCollection1(n, tau_rc=0.02, tau_ref=0.002, thresh=1, max_rate_range = [200, 400], intercept_range = [-1, 1]) {
return new NeuronCollection(() => {
const maxRate = randomBetween(max_rate_range[0], max_rate_range[1]);
const intercept = randomBetween(intercept_range[0], intercept_range[1]);
const [gain, bias] = getGainBias(tau_rc, tau_ref, thresh, maxRate, intercept);

const lif = new LIF(tau_rc, 0, tau_ref, thresh);
lif.step = (I, t_step) => LIF.prototype.step.call(lif, I * gain + bias, t_step);
lif.gain = gain;
lif.bias = bias;
return lif;
}, n);
}
Insert cell
Insert cell
Insert cell
Insert cell
function getLIFCollection(n, tau_rc=0.02, tau_ref=0.002, thresh=1, max_rate_range = [200, 400], intercept_range = [-1, 1]) {
return new NeuronCollection(() => {
const maxRate = randomBetween(max_rate_range[0], max_rate_range[1]);
const intercept = randomBetween(intercept_range[0], intercept_range[1]);

const [gain, bias] = getGainBias(tau_rc, tau_ref, thresh, maxRate, intercept);
const encoder = randomItem([-1, 1]);

const lif = new LIF(tau_rc, 0, tau_ref, thresh);
lif.step = (I, t_step) => LIF.prototype.step.call(lif, I * gain * encoder + bias, t_step);
lif.gain = gain;
lif.bias = bias;
lif.encoder = encoder;
return lif;
}, n);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
class PSP {
constructor(collection, tau) {
this.collection = collection; // NeuronCollection instance
this.tau = tau; // time constant for decay
this.output = this.collection.output.map(o => o); // Use the collection's output (but make a clone so we don't mutate the original)
}

step(t_step) {
// Loop through my output, decay it, and add the output from the incoming collection.
for(let i = 0; i<this.output.length; i++) {
this.output[i] = (this.collection.output[i] * t_step / this.tau) + this.output[i] * (1 - t_step / this.tau);
}
return this.output;
}
}
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

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more