Reputation: 2704
I am a newbie in Matlab, so sorry for a stupid question.
I want to create a sequence of 2-dimensional vectors generated from GMM that consist of three multivariate normal distributions.
so, let's start
mu = [[0 1]; [0 2]; [0 3]]
cov = cat(4, 0, 0.5)
p = [0.4 0.4 0.2]
obj = gmdistribution(mu, cov, p)
The problem is this sequence of commands doesn't work.
In addition, I want these three distribution to have a small overlap. I don't know how to evaluate mu and cov such that they will have a small overlap.
Upvotes: 0
Views: 105
Reputation: 14316
First, cov
is the name of the covariance function, so you better call your variable e.g. sigma
. Second, you create the cov
variable to be a 4-D array with value 0
at cov(1,1,1,1)
and 0.5
at cov(1,1,1,2)
.
Depending on how the covariance matrices looks, the variable sigma
can look different. Let d
be the number of dimensions (2 in your example), and k
be the number of distributions (3 in your example).
General case:
Each of the Gaussian distributions has an arbitrary covariance matrix. sigma
is of size d
xd
xn
, i.e. 2x2x3, where sigma(:,:,k)
is the k
th covariance matrix. Note that of course the covariance matrices have to be symmetric and positive semidefinite. You do that e.g. by
sigma(:,:,1) = [1.0, 0.5 ; 0.5, 2.0];
sigma(:,:,2) = [0.8, 0.1 ; 0.1, 0.2];
sigma(:,:,3) = [1.2, 0.4 ; 0.4, 0.3];
Diagonal covariance matrices If all your covariance matrices are diagonal, you can specify sigma as a 1
xd
xk
(1x2x3) matrix, where sigma(1,:,k)
are the diagonal elements of the k
th covariance matrix. E.g.
sigma(1,:,1) = [1.0, 2.0];
sigma(1,:,2) = [0.8, 0.2];
sigma(1,:,3) = [1.2, 0.3];
Identical covariance matrices If all k
covariance matrices are identical, it is enough if you specify it once
sigma = [1.0, 0.5 ; 0.5, 2.0];
Identical, diagonal covariance matrices If all k
covariance matrices are identical diagonal matrices, sigma
is a vector containing the diagonal elements
sigma = [1.0, 2.0];
Upvotes: 1