mvnpdf
多变量正常概率密度函数
Description
Examples
Standard Multivariate Normal pdf
Evaluate the pdf of a standard five-dimensional normal distribution at a set of random points.
Randomly sample eight points from the standard five-dimensional normal distribution.
亩=zeros(1,5); Sigma = eye(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
评估点的分布的PDFX
。
y=mvnpdf(X)
y=8×10.0000 0.0000 0.0000 0.0000 0.0054 0.0011 0.0015 0.0003
Find the point inX
with the greatest pdf value.
[maxpdf,idx] = max(y)
maxpdf = 0.0054.
idx = 5
maxpoint = x(idx,:)
maxpoint =1×50.3188 0.7254 0.6715 0.2939 0.3252
The fifth point inX
具有比任何其他随机选择的点的PDF值更大。
多变量正常PDF.s Evaluated at Different Points
创建六个三维正常分布,每个分布都有明显的含义。评估不同随机点处的每个分布的PDF。
指定均值s亩
and covariancesSigma
of the distributions. Each distribution has the same covariance matrix—the identity matrix.
FirstDim = (1:6)'; mu = repmat(firstDim,1,3)
亩=6×31112223 3 3 4 4 4 5 5 5 6 6 6
Sigma = Eye(3)
Sigma =3×31 0 0 0 1 0 0 0 1
Randomly sample once from each of the six distributions.
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 3.7950 5.3188 3.6501 4.8759 4.6923 7.6923 7.6923 7.6923 7.6923 7.6929 7.4897 7.4897
评估点的分布的PDFX
。The pdf of the first distribution is evaluated at the pointx(1,:)
那the pdf of the second distribution is evaluated at the pointX(2那:的)
, 和so on.
y = mvnpdf (X,μ的)
y=6×10.0384 0.0111 0.0000 0.0009 0.0241 0.0001
多变量正常PDF.
评估一组给定点的二维正态分布的PDF。
指定均值亩
and covarianceSigma
分布。
亩=[1 -1]; Sigma = [0.9 0.4; 0.4 0.3];
随机样本从分布100次。指定X
作为采样点的矩阵。
rng('default'的)%的再现性X=mvnrnd(mu,Sigma,100);
评估点的分布的PDFX
。
y = mvnpdf (X,μ那Sigma);
Plot the probability density values.
散射3(x(:,1),x(:,2),y)xlabel('X1'的)ylabel('X2')Zlabel('Probability Density'的)
多变量正常PDF在相同点评估
Create ten different five-dimensional normal distributions, and compare the values of their pdfs at a specified point.
设置尺寸N.
andD.
equal to 10 and 5, respectively.
n = 10;d = 5;
指定均值s亩
and the covariancesSigma
of the multivariate normal distributions. Let all the distributions have the same mean vector, but vary the covariance matrices.
亩=ones(1,d)
亩=1×511111
mat =眼睛(d);nmat = repmat(mat,1,1,n);var =重塑(1:n,1,1,n);sigma = nmat。* var;
Display the first two covariance matrices inSigma
。
西格玛(::,1:2)
ans = ans(:,:,1)= 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 ans(:,2)= 2 0 0 0 00 2 0 0 0 0 0 2 0 0 0 0 0 2 0 0 0 0 0 2
放X
在五维空间中是一个随机点。
rng('default'的)%的再现性X=N.ormrnd(0,1,1,5)
X=1×50.5377 1.8339 -2.2588 0.8622 0.3188
Evaluate the pdf atX
为每个十分布。
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
Plot the results.
scatter(1:n,y,'填充'的)Xlabel('Distribution Index'的)ylabel('Probability Density at x'的)
输入参数
X
-Evaluation points
数字矢量|数字矩阵
评估点,指定为a1
-by-D.数字矢量or anN.-by-D.数字矩阵那whereN.is a positive scalar integer andD.is the dimension of a single multivariate normal distribution. The rows ofX
correspond to observations (or points), and the columns correspond to variables (or coordinates).
如果X
是一个矢量,然后mvnpdf
复制它以匹配领先的维度亩
or the trailing dimension ofSigma
。
Data Types:single
|D.ouble
亩
-Means of multivariate normal distributions
零矢量(D.efault) |数字矢量|数字矩阵
Means of multivariate normal distributions, specified as a1
-by-D.数字矢量or anN.-by-D.数字矩阵。
如果
亩
是一个矢量,然后mvnpdf
replicates the vector to match the trailing dimension ofSigma
。如果
亩
是一个矩阵,然后是每行亩
是单个多变量正态分布的平均矢量。
Data Types:single
|D.ouble
Sigma
-多元正态分布的协方差
身份矩阵(D.efault) |对称,正定的矩阵|N.umeric array
多元正态分布的协方差那specified as aD.-by-D.对称,正定的矩阵or aD.-by-D.-by-N.数字数组。
如果
Sigma
是一个矩阵,thenmvnpdf
replicates the matrix to match the number of rows in亩
。如果
Sigma
is an array, then each page ofSigma
那Sigma(:,:,i)
,是单个多变量正态分布的协方差矩阵,因此,是对称的正定矩阵。
如果协方差矩阵是对角线的,则沿着对角线和零考核的差异,那么您还可以指定Sigma
as a1
-by-D.矢量或a1
-by-D.-by-N.array containing just the diagonal entries.
Data Types:single
|D.ouble
Output Arguments
更多关于
多变量正态分布
多变量正态分布是单变量正常分布到两个或多个变量的概括。它有两个参数,平均矢量μ和协方差矩阵Σ,这类似于单变量正态分布的平均值和方差参数。对角线元素Σ包含每个变量的差异,以及偏差元素Σcontain the covariances between variables.
The probability density function (pdf) of theD.- 多维多元正态分布是
whereXandμare 1-by-D.V.ectors andΣis aD.-by-D.对称,正定的矩阵。Onlymvnrnd
allows positive semi-definiteΣ矩阵,可以是单数。PDF不能有相同的形式Σ是单数的。
The multivariate normal cumulative distribution function (cdf) evaluated atX是随机矢量的概率V.那D.istributed as multivariate normal, lies within the semi-infinite rectangle with upper limits defined byX:
Although the multivariate normal cdf does not have a closed form,mvncdf
can compute cdf values numerically.
Tips
在一维案例中,
Sigma
是方差,而不是标准偏差。例如,mvnpdf(1,0,4)
是相同的诺普德夫(1,0,2)
那where4.
is the variance and2
is the standard deviation.
References
[1] Kotz, S., N. Balakrishnan, and N. L. Johnson.Continuous Multivariate Distributions: Volume 1: Models and Applications.第二辑。纽约:2000年John Wiley&Sons,Inc。
Extended Capabilities
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see在GPU上运行matlab函数(Parallel Computing Toolbox)。
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
您单击了与此MATLAB命令对应的链接:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
选择中国网站(以中文或英文)以获得最佳网站性能。其他MathWorks国家网站未优化您所在地的访问。
美洲
- América Latina(Español)
- 加拿大(English)
- 美国(English)
欧洲
- Netherlands(English)
- Norway(English)
- Österreich.(德意志)
- 葡萄牙(English)
- Sweden(English)
- 瑞士
- United Kingdom(English)