Created
August 21, 2016 09:20
-
-
Save goloroden/1f6fbb07d5f196cebe4731300b0c3eff to your computer and use it in GitHub Desktop.
A very, very simple neural network (with only 1 neuron ;-))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const input = 0.5; | |
const expected = 0.8; | |
let weight = 0.5; | |
const alpha = 0.1; | |
const iterations = 100; | |
for (let i = 0; i < iterations; i++) { | |
const actual = input * weight; | |
const error = (expected - actual) * (expected - actual); | |
console.log(`i=${i}, weight=${weight}, prediction=${actual}, error=${error}`); | |
const derivative = 2 * (expected - actual); | |
const scaledDerivative = alpha * input * derivative; | |
weight = weight + scaledDerivative; | |
} | |
console.log(); | |
console.log(`f(${input}) = ${input * weight}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment