7

Is there any built in function calculating the value of a gradient of multivariate normal probability density function for a given point?

Edit: found this how to evaluate derivative of function in matlab? but that is not what I am looking for

Edit2: owkay, that's what I'm using http://www.mathworks.co.uk/help/stats/mvnpdf.html case 3, looking for value of derivative with respect to X

Community
  • 1
  • 1
Karusmeister
  • 871
  • 2
  • 12
  • 25
  • I've found this [page](http://www.mathworks.com/help/stats/mvnpdf.html). Is that what you're looking for? – Yamaneko Nov 08 '12 at 23:24
  • Your title and post contradict eachother; are you looking for the pdf, or the gradient of the pdf? – Isaac Nov 08 '12 at 23:28
  • value of gradient of pdf at point X – Karusmeister Nov 08 '12 at 23:28
  • 1
    The gradient with respect to which variable/parameter? It has more than one... – Colin T Bowers Nov 08 '12 at 23:35
  • @Karusmeister Can you provide more details about your input data? Is your PDF represented by a matrix, or by a function? And if it's a function, does it accept a vector as input (_i.e_ `f(X)`), or does it have to accept explicit components (_i.e_ `f(x1, x2, x3, ...)`)? – Eitan T Nov 08 '12 at 23:44
  • @EitanT, OP already said that it's a multivariate normal pdf, so the derivative can be calculated from just the mean, covariance matrix, and the point at which we're evaluating the gradient. – Isaac Nov 08 '12 at 23:53
  • Does this help? http://www.mathworks.com/matlabcentral/fileexchange/38704-multi-dimensional-n-dimensional-gaussian-and-gaussian-derivative-filters – Bitwise Nov 08 '12 at 23:59
  • @Bitwise I'll have a look. Looks interesting – Karusmeister Nov 09 '12 at 00:02

1 Answers1

6

Might I suggest you check The Matrix Cookbook by Peterson and Pedersen (available for free online - just google it). The analytical solution to your problem is on p39, equation 325 (2008 edition).

We didn't even need Matlab for this one!

EDIT: As YBE implies, perhaps I should include the solution in my answer. So, let p(x) denote the multivariate Gaussian pdf, characterized by mean vector m and covariance matrix S. Then:

dp(x) / dx = -p(x) * S^(-1) * (x - m)

and

d^2p / dx dx' = p(x) * (S^(-1) (x - m)(x - m)' S^(-1) - S^(-1))

If you want a Matlab function, then:

function Gradient = MultNormD1(x, Mu, Sigma)
Gradient = -1 * mvnpdf(x, Mu, Sigma) * (Sigma \ (x - Mu));
Colin T Bowers
  • 18,106
  • 8
  • 61
  • 89
  • +1, just to make it complete here: d/dx x^T.\Sigma. x = 2\Sigma x (\Sigma hermitian and psd) and d/dx(a^T.x)= a – jkt Nov 09 '12 at 01:36