Last active
January 31, 2018 23:06
-
-
Save qti3e/e9af0f8aceee1563cae078f8ac8a9c9f to your computer and use it in GitHub Desktop.
Simple Perceptron in Propel
This file contains hidden or 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
import { Params, T } from "propel" | |
let params = new Params() | |
let trainingData = [ | |
[[0, 0, 1], 0], | |
[[0, 1, 1], 1], | |
[[1, 0, 1], 1], | |
[[1, 1, 1], 1] | |
] | |
let unit_step = x => x < 0 ? 0 : 1 | |
let w = params.randn("W", [3]) | |
errors = [] | |
eta = 0.2 | |
n = 100 | |
for(let i = 0; i < n;i++){ | |
let d = trainingData[i % trainingData.length] | |
let x = d[0] | |
let expected = d[1] | |
let result = w.dot(x) | |
let error = expected - unit_step(result) | |
w = w.add(T(x).mul(eta * error)) | |
} | |
for(let x of trainingData){ | |
result = w.dot(x[0]) | |
console.log(x[1], result, unit_step(result)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment