demo_semitiedGMM01.m 3.16 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 23 24
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/
% Written by Ajay Tanwani and Sylvain Calinon
%
25 26
% Correspondence: Ajay Tanwani <http://www.ajaytanwani.com>
%
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
% 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/');


44
%% Parameters
45
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 47 48 49
model.nbStates = 3; %Number of states in the GMM
model.nbVar = 3; %Number of variables [x1,x2,x3]
model.nbSamples = 5; %Number of demonstrations
model.params_Bsf = 5E-2; %Initial variance of B in semi-tied GMM
50
model.params_alpha = 1.0; % tying factor for the basis functions
51
nbData = 300; %Length of each trajectory
52 53 54 55


%% Learning
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 57
load('data/Zshape3D.mat'); %Load 'Data' 
model = init_GMM_kbins(Data, model, nbData);
58 59 60 61 62
model = EM_semitiedGMM(Data, model);


%% Plot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63 64 65 66
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]);
67 68
end
for i=1:model.nbVar
69
	mArrow3(zeros(model.nbVar,1), model.H(:,i), 'color',clrmap(i,:),'stemWidth',0.75, 'tipWidth',1.0, 'facealpha',0.75);
70
end
71
plotGMM3D(model.Mu, model.Sigma+repmat(eye(model.nbVar)*2E0,[1,1,model.nbStates]), [0 .6 0], .4, 2);
72 73
for i=1:model.nbStates
	for j=1:model.nbVar
74 75 76 77
		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
78 79 80 81
	end
end
view(-40,6); axis equal;

82

83 84 85 86
%print('-dpng','graphs/demo_semitiedGMM01.png');
pause;
close all;