主要内容

mvnpdf.

Multivariate normal probability density function

描述

example

y= mvnpdf(X)returns ann-通过-1向量ycontaining the probability density function (pdf) values for thed-dimensional multivariate normal distribution with zero mean and identity covariance matrix, evaluated at each row of then-通过-dmatrixX。有关更多信息,请参阅Multivariate Normal Distribution

example

y= mvnpdf(X,mu)returns pdf values of points inX,在哪里mu确定每个相关多变量正态分布的平均值。

example

y= mvnpdf(X,mu,Sigma.)returns pdf values of points inX,在哪里Sigma.determines the covariance of each associated multivariate normal distribution.

指定[]formuto use its default value of zero when you want to specify onlySigma.

例子

collapse all

评估一组随机点的标准五维正态分布的PDF。

从标准的五维正常分布中随机示例八点。

mu =零(1,5);西格玛=眼睛(5);RNG('default')重复性的%x = mvnrnd(mu,sigma,8)
X =8×50.5377 3.5784 -0.1241 0.4889 -1.0689 1.8339 2.7694 1.4897 1.0347 -0.8095 -2.2588 -1.3499 1.4090 0.7269 -2.9443 0.8622 3.0349 1.4172 -0.3034 1.4384 0.3188 0.7254 0.6715 0.2939 0.3252 -1.3077 -0.0631 -1.2075 -0.7873 -0.7549 -0.4336 0.7147 0.7172 0.8884 1.3703 0.3426 -0.2050 1.6302 -1.1471 -1.7115

Evaluate the pdf of the distribution at the points inX

y = mvnpdf(x)
y =8×10.0000 0.0000 0.0000 0.0000 0.0054 0.0011 0.0015 0.0003

找到点X具有最大的PDF值。

[maxpdf,idx] = max(y)
maxpdf = 0.0054
Idx = 5.
maxPoint = X(idx,:)
maxPoint =1×50.3188 0.7254 0.6715 0.2939 0.3252

第五点Xhas a greater pdf value than any of the other randomly selected points.

Create six three-dimensional normal distributions, each with a distinct mean. Evaluate the pdf of each distribution at a different random point.

指定the meansmu和协方差Sigma.分布。每个分布具有相同的协方差矩阵 - 标识矩阵。

Firstdim =(1:6)';Mu = Repmat(Firstdim,1,3)
mu =6×31 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6
西格玛=eye(3)
西格玛=3×31 0 0 0 1 0 0 0 1

从六个分布中的每一个随机采样一次。

RNG('default')重复性的%x = mvnrnd(mu,sigma)
X =6×31.5377 0.5664 1.7254 3.8339 2.3426 1.9369 0.7412 6.5784 3.7147 4.8622 6.7694 3.7950 5.3188 3.6501 4.8759 4.6923 9.0349 7.4897

Evaluate the pdfs of the distributions at the points inX。在该点评估第一个分布的PDFX(1,:),在点处评估第二分布的PDFx(2,:), 等等。

y =mvnpdf.(X,mu)
y =6×10.0384 0.0111 0.0000 0.0009 0.0241 0.0001

Evaluate the pdf of a two-dimensional normal distribution at a set of given points.

指定the meanmu和协方差Sigma.of the distribution.

mu = [1 -1];Sigma = [0.9 0.4;0.4 0.3];

Randomly sample from the distribution 100 times. SpecifyXas the matrix of sampled points.

RNG('default')重复性的%x = mvnrnd(mu,sigma,100);

Evaluate the pdf of the distribution at the points inX

y = mvnpdf(x,mu,sigma);

绘制概率密度值。

scatter3(X(:,1),X(:,2),y) xlabel('x1')ylabel('x2') zlabel('概率密度')

创建十个不同的五维正常分布,并将其PDF的值与指定点进行比较。

Set the dimensionsnd等于10和5。

n = 10; d = 5;

指定the meansmu和协方差Sigma.多元正常分布。让所有分布具有相同的平均矢量,但改变协方差矩阵。

mu = sones(1,d)
mu =1×51 1 1 1 1
mat = eye(d); nMat = repmat(mat,1,1,n); var = reshape(1:n,1,1,n); Sigma = nMat.*var;

显示前两个协方差矩阵Sigma.

Sigma.(:,:,1:2)
ans = ans(:,:,1) = 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 ans(:,:,2) = 2 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 0 2

Setxto be a random point in five-dimensional space.

RNG('default')重复性的%X =normrnd(0,1,1,5)
X =1×50.5377 1.8339 -2.2588 0.8622 0.3188

评估PDFxfor each of the ten distributions.

y = mvnpdf(x,mu,sigma)
y =10.×110.-4×0.2490 0.8867 0.8755 0.7035 0.5438 0.4211 0.3305 0.2635 0.2134 0.1753

绘制结果。

散射(1:N,Y,'filled')Xlabel('Distribution Index')ylabel('x'处的概率密度)

Input Arguments

collapse all

评估点, specified as a1-通过-d数字矢量或n-通过-d数字矩阵,其中n是一个正标量整数和d是单个多变量正态分布的尺寸。行的行X对应于观察(或点),并且列对应于变量(或坐标)。

IfX是矢量, thenmvnpdf.replicates it to match the leading dimension ofmu或尾随维度Sigma.

数据类型:|

多元正常分布的手段,指定为a1-通过-d数字矢量或n-通过-dnumeric matrix.

  • Ifmu是矢量, thenmvnpdf.复制向量以匹配尾随维度Sigma.

  • Ifmu是一个矩阵, then each row ofmuis the mean vector of a single multivariate normal distribution.

数据类型:|

多变量正常分布的协方差,指定为ad-通过-d对称,正定矩阵或ad-通过-d-通过-n数字数组。

  • IfSigma.是一个矩阵, thenmvnpdf.复制矩阵匹配的行数inmu

  • IfSigma.是一个数组,然后是每个页面Sigma.,西格玛(:,:我), is the covariance matrix of a single multivariate normal distribution and, therefore, is a symmetric, positive definite matrix.

If the covariance matrices are diagonal, containing variances along the diagonal and zero covariances off it, then you can also specifySigma.as a1-通过-d向量or a1-通过-d-通过-narray containing just the diagonal entries.

数据类型:|

输出参数

collapse all

PDF值,作为一个返回n-通过-1numeric vector, wheren是以下之一:

  • 行数XifX是一个矩阵

  • Number of timesXis replicated ifX是矢量

IfX是一个矩阵,mu是一个矩阵,和Sigma.是一个数组,然后是mvnpdf.计算y(i)使用x(我,:),穆(我,:), and西格玛(:,:我)

数据类型:

More About

collapse all

Multivariate Normal Distribution

The multivariate normal distribution is a generalization of the univariate normal distribution to two or more variables. It has two parameters, a mean vectorμ.和a covariance matrixσ., that are analogous to the mean and variance parameters of a univariate normal distribution. The diagonal elements ofσ.contain the variances for each variable, and the off-diagonal elements ofσ.包含变量之间的协方差。

概率密度函数(PDF)d-dimensional multivariate normal distribution is

y = f ( x , μ. , σ. ) = 1 | σ. | (2 π ) d exp. ( - 1 2 ( x - μ. ) σ. -1 ( x - μ. )' )

哪里xμ.是1-by-dvectors和σ.是A.d-通过-d对称的,正定的矩阵。只要mvnrnd.允许积极的半定σ.matrices, which can be singular. The pdf cannot have the same form whenσ.is singular.

The multivariate normal cumulative distribution function (cdf) evaluated atxis the probability that a random vectorv,分布为多变量正常,位于半无限矩形内,其中限制了上限x:

PR. { v ( 1 ) ≤. x ( 1 ) , v ( 2 ) ≤. x ( 2 ) , ...... , v ( d ) ≤. x ( d ) }

虽然多变量正常CDF没有封闭形式,但mvncdf.可以在数字上计算CDF值。

提示

  • In the one-dimensional case,Sigma.is the variance, not the standard deviation. For example,mvnpdf.(1,0,4)is the same asnormpdf(1,0,2),在哪里4是方差和2是标准偏差。

References

[1] Kotz,S.,N. Balakrishnan和N. L. Johnson。连续多变量分布:第1卷:型号和应用。2nd ed. New York: John Wiley & Sons, Inc., 2000.

扩展能力

Introduced before R2006a