Skip to content

Instantly share code, notes, and snippets.

@shubham0204
Created June 9, 2019 06:11
Show Gist options
  • Save shubham0204/7315dd301dd822dfc10086d91cba0ccc to your computer and use it in GitHub Desktop.
Save shubham0204/7315dd301dd822dfc10086d91cba0ccc to your computer and use it in GitHub Desktop.
private fun calculateGradients( inputs : DoubleArray , predY : Double , targetY : Double ) : Array<Any> {
val dJ_dPred = meanSquaredErrorDerivative( predY , targetY )
val dPred_dW = inputs
val dJ_dW = MathOps.multiplyScalar( dPred_dW , dJ_dPred )
val dJ_dB = dJ_dPred
return arrayOf( dJ_dW , dJ_dB )
}
private fun meanSquaredErrorDerivative( predY : Double , targetY : Double ) : Double {
return 2 * ( predY - targetY )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment