Skip to content

Instantly share code, notes, and snippets.

@klgraham
Last active April 4, 2016 00:45
Show Gist options
  • Save klgraham/634fc13b28b7b787515a3f11113b244b to your computer and use it in GitHub Desktop.
Save klgraham/634fc13b28b7b787515a3f11113b244b to your computer and use it in GitHub Desktop.
func activate(x: [Double], _ w: [Double]) -> Int {
var sum = 0.0
for i in 0..<x.count {
sum += x[i] * w[i]
}
return sign(sum)
}
func sign(z: Double) -> Int {
// Note that 0 is not considered positive or negative
return (z > 0) ? 1 : -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment