multivariate normal distribution given mean vector and covariance matrix

浪尽此生 提交于 2019-12-13 18:12:17

问题


I admit I am being lazy here but is anyone aware of a free math .net library which gives me the output of a normal distribution given a mean vector and a covariance matrix? Thanks.


回答1:


Math.NET might work for you.

http://www.mathdotnet.com/

http://numerics.mathdotnet.com/probability-distributions/

Multivariate Distributions

Dirichlet
Inverse Wishart
Matrix Normal
Multinomial
NormalGamma
Wishart

Function Reference:

http://api.mathdotnet.com/Numerics/MathNet.Numerics.Distributions/MatrixNormal.htm

EDIT : Note that you have to download from here

http://mathnetnumerics.codeplex.com/releases/view/56448

other links on mathdotnet.com are out of date.




回答2:


In the bivariate case, you can express the covariance matrix as a single parameter rho. Here is a method that implements this directly:

[Pure]
public static double GetBivariateGuassian(double muX, double sigmaX, double muY, double sigmaY, double x, double y, double rho = 0)
{
    var sigmaXSquared = Math.Pow(sigmaX, 2);
    var sigmaYSquared = Math.Pow(sigmaY, 2);

    var dX = x - muX;
    var dY = y - muY;

    var exponent = -0.5;
    var normaliser = 2 * Math.PI * sigmaX * sigmaY;
    if (rho != 0)
    {
        normaliser *= Math.Sqrt(1 - Math.Pow(rho, 2));
        exponent /= 1 - Math.Pow(rho, 2);
    }

    var sum = Math.Pow(dX, 2)/sigmaXSquared;
    sum += Math.Pow(dY, 2)/sigmaYSquared;
    sum -= 2*rho*dX*dY/(sigmaX*sigmaY);

    exponent *= sum;

    return Math.Exp(exponent) / normaliser;
}

See Bivariate Normal Distributions on Wikipedia for reference.



来源:https://stackoverflow.com/questions/9398331/multivariate-normal-distribution-given-mean-vector-and-covariance-matrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!