demo_semitiedGMM01.m 3.02 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
function demo_semitiedGMM01
% Semi-tied Gaussian Mixture Model by tying the covariance matrices of a
% Gaussian mixture model with a set of common basis vectors.
%
% 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.
%
% @article{Tanwani16RAL,
%   author="Tanwani, A. K. and Calinon, S.",
%   title="Learning Robot Manipulation Tasks with Task-Parameterized Semi-Tied Hidden Semi-{M}arkov Model",
%   journal="{IEEE} Robotics and Automation Letters ({RA-L})",
%   year="2016",
%   month="January",
%   volume="1",
%   number="1",
%   pages="235--242",
% 	doi="10.1109/LRA.2016.2517825"
% }
%
% Copyright (c) 2015 Idiap Research Institute, http://idiap.ch/
23
% Written by Ajay Tanwani (http://www.ajaytanwani.com) and Sylvain Calinon (http://calinon.ch)
24
%
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
% 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/>.

addpath('./m_fcts/');


42
%% Parameters
43
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 45 46 47
model.nbStates = 3; %Number of states in the GMM
model.nbVar = 3; %Number of variables [x1,x2,x3]
model.nbSamples = 5; %Number of demonstrations
nbData = 300; %Length of each trajectory
48 49 50 51


%% Learning
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 53
load('data/Zshape3D.mat'); %Load 'Data' 
model = init_GMM_kbins(Data, model, nbData);
54 55 56 57 58
model = EM_semitiedGMM(Data, model);


%% Plot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 60 61 62
figure('color',[1 1 1],'Position',[10 10 700 650]); hold on; axis off; box off;
clrmap = lines(model.nbVar);
for n=1:model.nbSamples
	plot3(Data(1,(n-1)*nbData+1:n*nbData), Data(2,(n-1)*nbData+1:n*nbData), Data(3,(n-1)*nbData+1:n*nbData),'-','linewidth',1.5,'color',[.7 .7 .7]);
63 64
end
for i=1:model.nbVar
65
	mArrow3(zeros(model.nbVar,1), model.H(:,i), 'color',clrmap(i,:),'stemWidth',0.75, 'tipWidth',1.0, 'facealpha',0.75);
66
end
67
plotGMM3D(model.Mu, model.Sigma+repmat(eye(model.nbVar)*2E0,[1,1,model.nbStates]), [0 .6 0], .4, 2);
68 69
for i=1:model.nbStates
	for j=1:model.nbVar
70 71 72 73
		w = model.SigmaDiag(j,j,i).^0.5;
		if w>5E-1
			mArrow3(model.Mu(:,i), model.Mu(:,i)+model.H(:,j)*w, 'color',clrmap(j,:),'stemWidth',0.75, 'tipWidth',1.25, 'facealpha',1);
		end
74 75 76 77
	end
end
view(-40,6); axis equal;

78

79
%print('-dpng','graphs/demo_semitiedGMM01.png');
80 81
%pause;
%close all;
82