Skip to content

Instantly share code, notes, and snippets.

@baofengyv
Last active February 22, 2018 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baofengyv/7b02ba35a18d62bd6d6694776f2ef23f to your computer and use it in GitHub Desktop.
Save baofengyv/7b02ba35a18d62bd6d6694776f2ef23f to your computer and use it in GitHub Desktop.
神经元
class Neural {
constructor() {
this.id = Math.random();
this.weightS = [1];
}
setWeightS(newWeightS) {
this.weightS = newWeightS;
}
// 刺激神经元
activate(input) {
return this.activation(input);
}
activation(input) {
let sum = .5;
for (let i = 0; i < input.length; i++)
sum += this.__FUNCTION_line_kx_12(input[i], this.weightS[i]);
return (sum > .5) * 1;
}
// 普通线性函数
__FUNCTION_line_kx(input, weight) {
return input * weight;
}
// 恒过点(0.5,0.5)
__FUNCTION_line_kx_12(input, weight) {
return .5 - weight * (input - .5);
}
}
let x = new Neural;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment