%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [GMMs,errLog,options,time] = trGmms(data,feat_type,feat_sel,m)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%train one type GMMs corresponding to selected features.
%input:
% data = train data with labels;
% feat_type = feature type;
% m = mix number
%output:
% GMMs = gauss mix models;
% errlog = log likehood of each iteration;
% time = run time.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Written by Qianyong Gao %%
%% Data:May 11,2006 %%
%% Update:June 27,2006 by Qianyong Gao %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
tic;
if nargin < 3
m = 32;
end
label = unique(data(:,end));
if length(label) > 1
error('data belong to different kind of audio');
end
options = foptions;
options(14) = 12;
options(1) = 1.0;
GMMs = opt_gmm_init(data,m,options);
data(:,end) = [];
options(14) = 128;
[GMMs.centres,post] = mykmeans(GMMs.centres,data,options);
cluster_size = sum(post,1);
GMMs.priors = cluster_size / sum(cluster_size);
GMM_WIDTH = eps;
GMMs.covars = [];
%ncentres = GMMs.ncentres;
%centres = GMMs.centres;
%temp_data = data;
for j = 1:GMMs.ncentres
% Pick out data points belonging to this centre
c = data(find(post(:,j)),:);
if size(c,1) == 0% (size(data,1)/GMMs.ncentres)*1E-1
warning(['the ',num2str(j),'th is zero cluster']);
%GMMs.priors(j) = [];
%centres(j,:) = [];
%ncentres = ncentres - 1;
%temp_data(find(post(:,j)),:) = [];
GMMs.covars = [GMMs.covars;eps*ones(1,GMMs.nin)];
else
diffs = c - (ones(size(c,1),1)*GMMs.centres(j,:));
covj = sum((diffs.*diffs),1)/size(c,1);
%if ~any(covj>eps)
% warning('some identical input train data')
% centres(j,:) = [];
% GMMs.priors(j) = [];
% ncentres = ncentres - 1;
% temp_data(find(post(:,j)),:) = [];
%elseif any(covj>eps)
% GMMs.covars = [GMMs.covars;covj];
if any(covj<eps^2)
warning('some bad input train data');
covj = covj + GMM_WIDTH*(covj<eps);
GMMs.covars = [GMMs.covars;covj];
else
GMMs.covars = [GMMs.covars;covj];
end
end
end
%GMMs.ncentres = ncentres;
%GMMs.centres = centres;
%GMMs.priors = GMMs.priors/sum(GMMs.priors);
%data = temp_data;
options(5) = 1.0;
options(14) = 30;
[GMMs,options,errLog] = gmmem(GMMs,data,options);
GMMs.feat = feat_type;
GMMs.fd = feat_sel;
time = toc;
- 1
- 2
- 3
前往页