Hello stack overflow fam. I have been trying to figure out how to use this pesty fitgmdist on MATLAB for fitting Gaussian Mixture models. I have made progress, but I am still getting an error when trying to set initial parameters. I get the following mistake:
Initial covariance must be a 3D array with K pages when 'SharedCovariance' is false. Each page must be a square matrix with the same number of columns as X if 'CovarianceType' is 'full', or a vector with length equal to the number of columns in X if 'CovarianceType' is 'diagonal'.
Code:
x=rand(5,1);
x=transpose(transpose(x));
y= sum (x);
x=x./y;
a=zeros(10000,1);
b=[1;2;3;4;5];
c=[1;2;4;8;16];
i=1;
for i=1:10000
a(i,1)=rand();
end
S = struct('mu',b,'Sigma',c,'ComponentProportion',x)
GMModel=fitgmdist(a,5,'Start', S)
I am using a random data set of 10000 numbers generated from a unif(0,1) distribution, with supposed initial proportions also generated from 5 random numbers, means 1, 2, 3, 4 and 5 as well as sigmas 1,2,4,8,16. Thank you!
Problem is in your struct S, covariance matrix is supposed to have 5 pages as stated in the error message. Example of solution:
...
c=zeros(1,1,5);
c(1,1,:) = [1;2;4;8;16];
...