class Neuron {
constructor(nin) {
this.w = util.array(nin, () => new Value(util.randomUniform(-1, 1)).set({ label: 'weight', color: Colors.weights }));
this.b = new Value(util.randomUniform(-1, 1)).set({ label: 'bias', color: Colors.bias });
}
_call = x => {
const activation = util.zip(this.w, x).reduce((sum, [wi, _xi]) => {
const xi = typeof _xi === 'number'
? new Value(_xi).set({ label: 'input', color: Colors.input })
: _xi;
return sum.add(wi.mult(xi));
}, this.b);
const out = activation.tanh().set({ label: 'act', color: Colors.activation });
return out;
}
parameters = () => [...this.w, this.b]
}