Skip to content

Instantly share code, notes, and snippets.

@kmdupr33
Created September 5, 2019 12:41
Show Gist options
  • Save kmdupr33/aeacbc7468c7dfe898e4078c45fac8b9 to your computer and use it in GitHub Desktop.
Save kmdupr33/aeacbc7468c7dfe898e4078c45fac8b9 to your computer and use it in GitHub Desktop.
fun cost(videoGameData: Array<Pair<Double, Double>>, learningParameters: Pair<Double, Double>): Double =
videoGameData.fold(0.0) { acc: Double, pair: Pair<Double, Double> ->
val (m, b) = learningParameters
val (x, y) = pair
acc + ((((m * x) + b) - y).pow(2)/2)
} / videoGameData.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment