Reputation: 14037
How does one calculate the probability of a multivariate Gaussian at point x
in Scipy?
I tried
probability = multivariate_normal(x, mean, v)
where x
, mean
, v
are all correctly sized vectors, but I get:
probability = multivariate_normal(x, mean, v )
TypeError: __call__() takes at most 3 arguments (4 given)
Upvotes: 2
Views: 8391
Reputation: 4238
First the error. When you call multivariate_normal
you are actually calling __call__
of the multivariate_normal_gen
class (source at row 555). Which since it is a method takes itself, self
, as an argument which always is the first argument. When you then add three more arguments the total number of arguments is four.
Regarding your question, you evaluate the probability density function at given point(s) by calling pdf
of multivariate_normal
. Example:
from scipy.stats import multivariate_normal
import numpy as np
x = np.array([[1,2], [3,4]])
multivariate_normal.pdf(x, mean=[0, 1], cov=[5, 2])
Which prints out:
Out[44]: array([ 0.0354664 , 0.00215671])
Upvotes: 7