我一直试图进入神经网络一段时间,我在JavaScript中创建了一个简单的感知器作为测试。阻碍我的一件事就是支持反击。我发现的每一个搜索引擎结果似乎都太复杂而不易理解。
我的Perceptron代码供参考:
class Perceptron {
constructor(actFunc, inputs, bias, learningRate, normalizer){
this.weights = [];
for(var i = 0; i < inputs; i++){
this.weights[i] = Math.random();
}
this.activation = actFunc;
this.bias = bias;
this.normalizer = normalizer;
this.learningRate = learningRate;
}
train(input, expected) {
var result = this.evaluate(input);
var error = expected - result;
this.weights[0] += this.learningRate*(error)*input[0];
this.weights[1] += this.learningRate*(error)*input[1];
this.bias += this.learningRate*error;
console.log("Train: " + input + ": " + result + " Error: " + error);
}
evaluate(input){
return this.activation((this.weights[0]*this.normalizer(input[0]))+(this.weights[1]*this.normalizer(input[1])) + this.bias);
}
}
我最终希望能够将这些字符串组合成一个函数神经网络,但正如我所说,我遇到了障碍。