Evaluation of Multivariate Gaussian with NumPy
source link: http://siongui.github.io/2012/05/25/evaluation-of-multivariate-gaussian-with-numpy/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Evaluation of Multivariate Gaussian with NumPy
May 25, 2012
To implement a continuous HMM, it involves the evaluation of multivariate Gaussian (multivariate normal distribution). This post gives description of how to evaluate multivariate Gaussian with NumPy.
The formula for multivariate Gaussian used for continuous HMM is:
where o is vector extracted from observation, μ is mean vector, and Σ is covariance matrix.
For the computation and implementation to be easily done, covariance matrix is assume to be diagonal without loss of much performance. The following is the code snippet:
dimension = mean_vector.size detDiagCovMatrix = numpy.sqrt(numpy.prod(numpy.diag(covariance_matrix))) frac = (2*numpy.pi)**(-dimension/2.0) * (1/detDiagCovMatrix) fprime = feature_vector - mean_vector fprime **= 2 if log: logValue = -0.5*numpy.dot(fprime, 1/numpy.diag(covariance_matrix)) logValue += numpy.log(frac) return logValue else: return frac * numpy.exp(-0.5*numpy.dot(fprime, 1/numpy.diag(covariance_matrix)))
Both mean vector and covariance matrix are of type numpy.ndarray with proper dimension. The code is self-explanatory. If more details are needed, please follow the link in [1].
References:
[2]David Cournapeau (author of source code in [1])
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK