Skip to content

Instantly share code, notes, and snippets.

@shubham0204
Created June 9, 2019 06:15
Show Gist options
  • Save shubham0204/627b32ae4425700ec0a488dfaf0c46ce to your computer and use it in GitHub Desktop.
Save shubham0204/627b32ae4425700ec0a488dfaf0c46ce to your computer and use it in GitHub Desktop.
private fun optimizeParameters( gradients : ArrayList<Array<Any>> , learningRate : Double ) {
val weightGradientsList = ArrayList<DoubleArray>()
for( gradient in gradients ) {
weightGradientsList.add( gradient[0] as DoubleArray )
}
val weightGradients = MathOps.multidimMean( weightGradientsList.toTypedArray() ).toDoubleArray()
val biasGradientsList = ArrayList<Double>()
for( gradient in gradients ) {
biasGradientsList.add( gradient[1] as Double )
}
val biasGradients = ( biasGradientsList.toTypedArray() ).average()
this.weights = MathOps.subtract( this.weights , MathOps.multiplyScalar( weightGradients , learningRate ) )
this.bias = this.bias - ( biasGradients * learningRate )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment