MATLAB GMM by fitgmdist gives different values even after initializing using kmeans
Mostrar comentarios más antiguos
So I am trying to compare two Gaussian Mixture Models with two distributions every time I run the program i get different values even after initializing using k-means. Am I missing something??
X = mat_cell;
[counts,binLocations] = imhist(X);
stem(binLocations, counts, 'MarkerSize', 1 );
xlim([-1 1]);
% inital kmeans step used to initialize EM
K = 2; % number of mixtures/clusters
cInd = kmeans(X(:), K,'MaxIter', 75536);
% fit a GMM model
options = statset('MaxIter', 75536);
gmm = fitgmdist(X(:),K,'Start',cInd,'CovarianceType','diagonal','Regularize',1e-5,'Options',options);
5 comentarios
Adam
el 23 de Jun. de 2017
kmeans is not a deterministic function so it will give different results each time.
A. P. B.
el 23 de Jun. de 2017
Adam
el 23 de Jun. de 2017
You can use
doc rng
before kmeans to force it to always use the same 'random' values and return the same result each time. It doesn't make it deterministic, but it makes it repeatable at least.
Or you can use any method you want that gives you some initial clusters. I used hierarchical clustering when I used a GMM a few years ago.
SAFAA ALQAYSI
el 13 de Sept. de 2017
Adem would you please let me know the way you did with GMM and the hierarchical clustering ????
Thanks
Catherine Davey
el 7 de Mayo de 2023
K-means is not deterministic. Given that K-means will give a different result each time it is run, you cannot use it to ensure identical runs for the GMM algorithm.
Respuestas (1)
the cyclist
el 23 de Jun. de 2017
Set the seed for the pseudorandom number generation in your code. For example, put the line
rng 'default'
as the first line.
This will give you a pseudorandom sequence, but it will be reproducible.
Categorías
Más información sobre Statistics and Machine Learning Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!