Skip to content

Instantly share code, notes, and snippets.

@klgraham
Last active April 3, 2016 23:55
Show Gist options
  • Save klgraham/258f43cb7f452ffc29450441b87c84f6 to your computer and use it in GitHub Desktop.
Save klgraham/258f43cb7f452ffc29450441b87c84f6 to your computer and use it in GitHub Desktop.
func randomDouble() -> Double {
return Double(arc4random()) / Double(UINT32_MAX)
}
func createData(numPoints: Int) -> [PerceptronDataPair] {
var data = [PerceptronDataPair]()
for _ in 0..<numPoints {
let x = [2.0 * (randomDouble() - 0.5)]
let y = line(x[0])
data.append(PerceptronDataPair(input: x, output: isAbove(y)))
}
return data
}
let trainingData = createData(100)
let trainer = PerceptronTrainer(data: data)
trainer.train(&p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment