Created
September 5, 2019 12:43
-
-
Save kmdupr33/2908ff090b3cbcb38320673d857a0038 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
fun updateGuess( | |
guess: Pair<Double, Double>, | |
learningRate: Double, | |
videoGameData: Array<Pair<Double, Double>> | |
): Pair<Double, Double> { | |
val (m, b) = guess | |
val mGradient = videoGameData.fold(0.0) { acc: Double, pair: Pair<Double, Double> -> | |
val (x, y) = pair | |
acc + ((((m * x) + b) - y) * x) | |
} / videoGameData.size | |
val bGradient = videoGameData.fold(0.0) { acc: Double, pair: Pair<Double, Double> -> | |
val (x, y) = pair | |
acc + ((((m * x) + b) - y)) | |
} / videoGameData.size | |
val newM = m - (learningRate * mGradient) | |
val newB = b - (learningRate * bGradient) | |
return Pair(newM, newB) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment