多元高斯分布公式的实现 [英] Multivariate Gaussian distribution formula implementation
问题描述
在实现用于检测异常的多元高斯分布时,我遇到了一个问题.
I have a certain problem while implementing multivariate Gaussian distribution for anomaly detection.
我已经参考了吴国栋笔记中的公式
I have referred the formula from Andrew Ng notes
http://www.holehouse.org/mlclass/15_Anomaly_Detection.html
以下是我面临的问题
假设我有一个具有2个特征和m个训练集的数据集,即n = 2,并且想确定我的多元高斯概率p(x; mu; sigma),它应该是[m * 1]矩阵,因为通过特征相关产生估计的高斯值.
Suppose I have a data set with 2 features and m number of training set i.e n=2 and wants to determine my multivariate Gaussian probability p(x;mu;sigma) which should be a [m*1] matrix because it produces estimated Gaussian value by feature correlation.
我面临的问题是我无法使用公式来生成矩阵[m * 1].
The problem I face is I am unable to use the formula to produce the matrix [m*1].
我正在使用Octave作为IDE来开发算法.
I am using Octave as IDE to develop the algorithm.
下面是展示我的问题的快照
Below is a snapshot showcasing my problem
考虑红色边界方程的乘法,因为红色边界的LHS只是一个实数
Considering the multiplication of the Red boundary equation because the LHS of the red boundary is just a real number
请帮助我理解我错误的地方
PLEASE HELP ME UNDERSTAND WHERE AM I GOING WRONG
谢谢
推荐答案
我认为尺寸不正确.
让我们假设您有一个 m
个实例的二维( n = 2
)数据.我们可以在MATLAB中将这些数据存储为 n-by-m
矩阵(列是数据实例,行代表要素/维度).在这种情况下,我们有:
Let's assume you have a 2-dimensional (n=2
) data of m
instances. We can store this data as a n-by-m
matrix in MATLAB (columns are data instances, rows represent features/dimensions). In this case we have:
-
X
大小为nxm
的数据矩阵,每个实例x = X(:,i)
是大小为的向量nx1
(在我们的惯例中为列向量). -
mu
是均值向量(mu = mean(X,2)
).这也是与实例nx1
大小相同的列向量. -
sigma
是协方差矩阵(sigma = cov(X.')
).它的大小为nxn
(描述每个维度如何彼此变化).
X
the data matrix of sizenxm
, each instancex = X(:,i)
is a vector of sizenx1
(column vector in our convention).mu
is the mean vector (mu = mean(X,2)
). This is also a column vector of same size as an instancenx1
.sigma
is the covariance matrix (sigma = cov(X.')
). It has sizenxn
(it describes how each dimensions co-vary with each other dimension).
因此,以红色突出显示的部分涉及以下尺寸的表达式:
So the part that you highlighted in red involves expressions of the following sizes:
= ([nx1] - [nx1])' * [nxn] * ([nx1] - [nx1])
= [1xn] * [nxn] * [nx1]
= 1x1
这篇关于多元高斯分布公式的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!