0

I am using a function to calculate a likelihood density.

I am running through two xs which are vectors of length 7.

def lhd(x0, x1, dt): #Define a function to calculate the likelihood density given two values. 
    d = len(x0) #Save the length of the inputs for the below pdf input.
    print(d)
    print(len(x1))
    lh = multivariate_normal.pdf(x1, mean=(1-dt)*x0, cov=2*dt*np.identity(d)) #Take the pdf from a multivariate normal built from x0, given x1.
    return lh #Return this pdf value.

The mean here is a vector of length 7, and the covariance is a (7,7) array.

When I run this, I get the error

ValueError: Array 'mean' must be a vector of length 49.

but looking at the formula of the pdf I do not think this is correct. Any idea what is going wrong here?

Ria Dunn
  • 21
  • 1
  • 2

1 Answers1

0

If dt is a (7,7) array, (1-dt) is also (7,7), the * operator in (1-dt)*x0 is the element-wise multiplication, if x0 is a vector of length 7 the result will be a (7,7) array.

I guess you meant to use matrix multiplication, you can that this using the x0 - dt @ x0 (where @ denotes the matrix multiplication operator).

Bob
  • 13,867
  • 1
  • 5
  • 27