Created
April 24, 2021 14:17
-
-
Save shubham0204/13fbb554a32982a2ea30c9c227f106d0 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
// A Gaussian Distribution which will be constructed for every feature, given the mean and standard deviation. | |
class GaussianDistribution( var mean : Float , var stdDev : Float ) { | |
private val p = 1f / ( sqrt( 2.0 * Math.PI ) ).toFloat() | |
// Get the likelihood for given x. | |
fun getProb( x : Float ) : Float { | |
val exp = exp( -0.5 * ((x - mean) / stdDev ).pow( 2 ) ).toFloat() | |
return ( 1 / stdDev ) * p * exp | |
} | |
// Get the log of the likelihood for given x. | |
fun getLogProb( x : Float ) : Float { | |
return log10( getProb( x ) ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment