-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmm_sample_traning.m
69 lines (66 loc) · 2.35 KB
/
gmm_sample_traning.m
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function Status = gmm_sample_traning()
file=load ('speech');
frquency = file.frequency;
time = transpose (1/frquency);
X=[frquency,time];
%Fit a Gaussian mixture model to the data using default initial values. There are three iris species, so specify k = 3 components.
rng(4); % For reproducibility
GMModel1 = fitgmdist(X,2);
%Fit a Gaussian mixture model by connecting each observation to its label.
y = ones(size(X,1),1);
y(strcmp(file.categories,'Normal')) = 1;
y(strcmp(file.categories,'Special')) = 2;
%y(strcmp(file.emotions,'Neutral')) = 3;
%y(strcmp(file.emotions,'Sad')) = 4;
rng(1); % For reproducibility
GMModel2 = fitgmdist(X,2,'Start',file.categories_nn);
%Fit a Gaussian mixture model by explicitly specifying the initial means, covariance matrices, and mixing proportions.
Mu = [1 1; 2 2];
Sigma(:,:,1) = [1 1; 1 2];
Sigma(:,:,2) = 2*[1 1; 1 2];
PComponents = [1/2,1/4];
S = struct('mu',Mu,'Sigma',Sigma,'ComponentProportion',PComponents);
rng(1); % For reproducibility
GMModel3 = fitgmdist(X,2,'Start',S);
%Use gscatter to plot a scatter diagram that distinguishes between the iris species. For each model, plot the fitted Gaussian mixture model contours.
time=1/X;
figure
subplot(2,2,1)
h = gscatter(X,time,file.categories,[],'o',2);
haxis = gca;
xlim = haxis.XLim;
ylim = haxis.YLim;
d = (max([xlim ylim])-min([xlim ylim]))/1000;
[X1Grid,X2Grid] = meshgrid(xlim(1):d:xlim(2),ylim(1):d:ylim(2));
hold on
contour(X1Grid,X2Grid,reshape(pdf(GMModel1,[X1Grid(:) X2Grid(:)]),...
size(X1Grid,1),size(X1Grid,2)),20)
uistack(h,'top')
title('{\bf Random Initial Values}');
xlabel('Sepal length');
ylabel('Sepal width');
legend off;
hold off
subplot(2,2,2)
h = gscatter(X,time,file.emotions,[],'o',2);
hold on
contour(X1Grid,X2Grid,reshape(pdf(GMModel2,[X1Grid(:) X2Grid(:)]),...
size(X1Grid,1),size(X1Grid,2)),20)
uistack(h,'top')
title('{\bf Initial Values from Labels}');
xlabel('Sepal length');
ylabel('Sepal width');
legend off
hold off
subplot(2,2,3)
h = gscatter(X,time,file.emotions,[],'o',4);
hold on
contour(X1Grid,X2Grid,reshape(pdf(GMModel3,[X1Grid(:) X2Grid(:)]),...
size(X1Grid,1),size(X1Grid,2)),20)
uistack(h,'top')
title('{\bf Initial Values from the Structure}');
xlabel('Sepal length');
ylabel('Sepal width');
legend('Location',[0.7,0.25,0.1,0.1]);
hold off
Status='GMM Model Has been Trained';