Why do I receive this error while classifying by GMM? (gmdistribution.fit)

1 次查看(过去 30 天)
I am trying to classify the data set of handwritten digits (0-9) by Gaussian mixture models, with 2 mixtures. The training data consists of 60000 examples of dimension 874 ( each example corresponding to 28X28 pixels, containing the gray level value of the image) . In the training phase, I try to fit the data to 10 classes, as follows:
clc
clear all
close all
load data_all
numMix = 2;
for i = 1:10
% arange the training set corresponding to each class
x{i} =trainv(trainlab==(i-1),:);
a = x{i};
% Initialize means, using Kmeans
a(:, find(sum(abs(a)) == 0)) = [];
[IDX,initMu] = kmeans(a,numMix);
% Initialize variance and mixture weights by arbitrary values.
initCov = eye(size(a,2));
initVar= cat(3,initCov,initCov) ;
initWeight = ones(1,2)/2;
% Initial structure for the gmdistribution.fit function
S.mu = initMu;
S.Sigma = initVar;
S.PComponents = initWeight;
% Create models by implementing EM algorithm
g{i} = gmdistribution.fit(a,numMix,'Start',S);
end
But when running the code, I receive this error:
Error using gmdistribution.fit (line 136)
The following column(s) of data are effectively constant: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 43 47 48 49 50 51 52 53 54 55 56 57 58 59 62 66 67 77 78 79
80 81 82 83 84 85 86 87 111 112 113 114 115 139 140 141 142 143 167 168 169 170 171 172 197 198 199 226 251 252 253 254 279 280 281
282 307 308 309 311 336 337 364 365 392 393 394 395 419 420 421 422 423 447 448 449 450 451 475 477 478 479 503 505 506 507 531 532 533 559
560 561 588 589 590 617 618 619 645 646 647 671 672 673 674 675 676 699 700 701 702 703 704 705 706 720 721 722 723 724 725 726 727 728 729
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784.
I tried to discard the zeros collumns. (Wondering if this would affect the final models?) I didn´t receive that error anymore, but this time I got the following error:
Error using gmcluster (line 180)
Ill-conditioned covariance created at iteration 2.
Error in gmdistribution.fit (line 174) [S,NlogL,optimInfo] =...
Error in digits_gmm (line 33) g{i} = gmdistribution.fit(a,numMix,'Start',S); I think this error has something to do with the way I initialize the covariance matrix. But couldn't figure out a better choice for that. Is there any workaround to this?

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by