demo_HDDC01.m 3.49 KB
Newer Older
1
function demo_HDDC01
2
% High Dimensional Data Clustering (HDDC, or HD-GMM) encoding.
Sylvain Calinon's avatar
Sylvain Calinon committed
3
% 
4 5 6 7
% Writing code takes time. Polishing it and making it available to others takes longer! 
% If some parts of the code were useful for your research of for a better understanding 
% of the algorithms, please reward the authors by citing the related publications, 
% and consider making your own research available in this way.
Sylvain Calinon's avatar
Sylvain Calinon committed
8
%
9
% @article{Calinon16JIST,
Sylvain Calinon's avatar
Sylvain Calinon committed
10
%   author="Calinon, S.",
11 12
%   title="A Tutorial on Task-Parameterized Movement Learning and Retrieval",
%   journal="Intelligent Service Robotics",
13 14 15 16 17 18
%		publisher="Springer Berlin Heidelberg",
%		doi="10.1007/s11370-015-0187-9",
%		year="2016",
%		volume="9",
%		number="1",
%		pages="1--29"
19 20 21 22 23 24 25 26 27 28
% }
% 
% @article{Bouveyron07,
% 	author = "Bouveyron, C. and Girard, S. and Schmid, C.",
% 	title = "High-dimensional data clustering",
% 	journal = "Computational Statistics and Data Analysis",
% 	year = "2007",
% 	volume = "52",
% 	number = "1",
% 	pages = "502--519"
Sylvain Calinon's avatar
Sylvain Calinon committed
29
% }
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
% 
% Copyright (c) 2015 Idiap Research Institute, http://idiap.ch/
% Written by Sylvain Calinon, http://calinon.ch/
% 
% This file is part of PbDlib, http://www.idiap.ch/software/pbdlib/
% 
% PbDlib is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License version 3 as
% published by the Free Software Foundation.
% 
% PbDlib is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with PbDlib. If not, see <http://www.gnu.org/licenses/>.
47 48 49

addpath('./m_fcts/');

Sylvain Calinon's avatar
Sylvain Calinon committed
50

51 52 53 54 55 56 57 58 59
%% Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
model.nbStates = 4; %Number of states in the GMM
model.nbVar = 4; %Number of variables [x1,x2,x3,x4]
model.nbFA = 1; %Dimension of the subspace
nbData = 200; %Length of each trajectory
nbSamples = 5; %Number of demonstrations


60
%% Load handwriting data
61 62
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[];
63
load('data/2Dletters/C.mat'); %Load x1,x2 variables
64 65 66 67
for n=1:nbSamples
	s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling
end
demos=[];
68
load('data/2Dletters/D.mat'); %Load x3,x4 variables
69 70 71 72 73 74 75 76 77 78 79
Data=[];
for n=1:nbSamples
	s(n).Data = [s(n).Data; spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData))]; %Resampling
	Data = [Data s(n).Data]; 
end


%% Parameters estimation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
model = init_GMM_kmeans(Data, model);
model0 = EM_GMM(Data, model); %for comparison
Sylvain Calinon's avatar
Sylvain Calinon committed
80 81
model = EM_HDGMM(Data, model); 

82 83 84

%% Plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85
figure('position',[10,10,1300,500]); 
86 87 88
for i=1:2
	subplot(1,2,i); hold on; box on; 
	plot(Data((i-1)*2+1,:),Data(i*2,:),'.','markersize',8,'color',[.7 .7 .7]);
89 90
	plotGMM(model0.Mu((i-1)*2+1:i*2,:), model0.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 .8 .8], .5);
	plotGMM(model.Mu((i-1)*2+1:i*2,:), model.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 0 0], .5);
91 92 93 94 95 96 97
	axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]);
	xlabel(['x_' num2str((i-1)*2+1)]); ylabel(['x_' num2str(i*2)]);
end

%print('-dpng','graphs/demo_HDDC01.png');
%pause;
%close all;