Last active
April 3, 2016 23:55
-
-
Save klgraham/258f43cb7f452ffc29450441b87c84f6 to your computer and use it in GitHub Desktop.
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
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