Clear Filters
Clear Filters

How to choose initial component parameters with ?

9 views (last 30 days)
I am training a Gaussian Mixture Model through However, as far as I am concerned my initial component parameters are random values. Well I would like to change this and instead of random values to initialize my component parameters through K-Means method. Any idea on how to solve this?
The code for training my model is :
options = statset('MaxIter',500,'Display','final');
models(BrandId).gmm =',3,'CovType',...

Accepted Answer

Jonathan LeSage
Jonathan LeSage on 15 Oct 2013
Once you have clustered your data via the k-means algorithm, you can definitely use the cluster centers as initial conditions for your Gaussian mixture clustering. The trick is that the initial condition inputs to the functions must be in the proper form (a structure). More information on the function can be found in the documentation, here:
The other trick here is that the Gaussian mixture clustering routine requires three initial conditions. The initial cluster means (which you are providing from k-means), the initial cluster covariances (you can randomly initialize this), and the initial cluster weights (same as the initial covariances).
To help get you started, here is some example code:
% Arbitrary 1-d data vector
dataLength = 5000;
muData = [5 30];
stdData = [4 10];
dataVec = [muData(1) + stdData(1)*randn(dataLength/2,1); ...
muData(2) + stdData(2)*randn(dataLength/2,1)];
% K-means to initially cluster data
% The second output of the k-means function are the cluster center values
numberOfClusters = 2;
[~,kMeansClusters] = kmeans(dataVec,numberOfClusters);
% Fit GMM using the k-means centers as the initial conditions
% We only have mean initial conditions from the k-means algorithm, so we
% can specify some arbitrary initial variance and mixture weights.
gmInitialVariance = 0.1;
initialSigma = cat(3,gmInitialVariance,gmInitialVariance);
% Initial weights are set at 50%
initialWeights = [0.5 0.5];
% Initial condition structure for the function = kMeansClusters;
S.Sigma = initialSigma;
S.PComponents = initialWeights;
gmmOfData =,numberOfClusters,'Start',S);
Hope this helps and good luck!
  1 Comment
Stamatis Samaras
Stamatis Samaras on 15 Oct 2013
This is definetely something to get started and its really close to what i am looking for , thanks !

Sign in to comment.

More Answers (0)


Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!