Commit 168c56ef authored by Sylvain Calinon's avatar Sylvain Calinon

New GMR example added

parent b196c8ba
......@@ -2,7 +2,20 @@ function [model, GAMMA2, LL] = EM_GMM(Data, model)
% Training of a Gaussian mixture model (GMM) with an expectation-maximization (EM) algorithm.
%
% Author: Sylvain Calinon, 2014
% http://programming-by-demonstration.org/SylvainCalinon
% http://programming-by-demonstration.org/lib/
%
% This source code is given for free! In exchange, please cite the following
% reference in any academic publication that uses this code or part of it:
%
% @article{Calinon07SMC,
% author="Calinon, S. and Guenter, F. and Billard, A. G.",
% title="On Learning, Representing and Generalizing a Task in a Humanoid Robot",
% journal="{IEEE} Trans. on Systems, Man and Cybernetics, Part {B}",
% year="2007",
% volume="37",
% number="2",
% pages="286--298",
% }
%Parameters of the EM algorithm
nbMinSteps = 5; %Minimum number of iterations allowed
......
function model = init_GMM_kmeans(Data, model)
%
% This function initializes the parameters of a Gaussian Mixture Model
% (GMM) by using k-means clustering algorithm.
%
......@@ -12,16 +11,12 @@ function model = init_GMM_kmeans(Data, model)
% o Mu: D x K array representing the centers of the K GMM components.
% o Sigma: D x D x K array representing the covariance matrices of the
% K GMM components.
% Comments ---------------------------------------------------------------
% o This function uses the 'kmeans' function from the MATLAB Statistics
% toolbox. If you are using a version of the 'netlab' toolbox that also
% uses a function named 'kmeans', please rename the netlab function to
% 'kmeans_netlab.m' to avoid conflicts.
%
% Copyright (c) 2006 Sylvain Calinon, LASA Lab, EPFL, CH-1015 Lausanne,
% Switzerland, http://lasa.epfl.ch
% Author: Sylvain Calinon, 2014
% http://programming-by-demonstration.org/lib/
[nbVar, nbData] = size(Data);
nbVar = size(Data,1);
diagRegularizationFactor = 1E-2;
[Data_id, model.Mu] = kmeansClustering(Data, model.nbStates);
......@@ -30,7 +25,7 @@ for i=1:model.nbStates
model.Priors(i) = length(idtmp);
model.Sigma(:,:,i) = cov([Data(:,idtmp) Data(:,idtmp)]');
%Regularization term to avoid numerical instability
model.Sigma(:,:,i) = model.Sigma(:,:,i) + eye(nbVar)*1E-2;
model.Sigma(:,:,i) = model.Sigma(:,:,i) + eye(nbVar)*diagRegularizationFactor;
end
model.Priors = model.Priors ./ sum(model.Priors);
model.Priors = model.Priors / sum(model.Priors);
function model = init_GMM_timeBased(Data, model)
%
% This function initializes the parameters of a Gaussian Mixture Model
% (GMM) by using k-means clustering algorithm.
%
......@@ -12,17 +11,13 @@ function model = init_GMM_timeBased(Data, model)
% o Mu: D x K array representing the centers of the K GMM components.
% o Sigma: D x D x K array representing the covariance matrices of the
% K GMM components.
% Comments ---------------------------------------------------------------
% o This function uses the 'kmeans' function from the MATLAB Statistics
% toolbox. If you are using a version of the 'netlab' toolbox that also
% uses a function named 'kmeans', please rename the netlab function to
% 'kmeans_netlab.m' to avoid conflicts.
%
% Copyright (c) 2006 Sylvain Calinon, LASA Lab, EPFL, CH-1015 Lausanne,
% Switzerland, http://lasa.epfl.ch
% Author: Sylvain Calinon, 2014
% http://programming-by-demonstration.org/lib/
[nbVar, nbData] = size(Data);
nbVar = size(Data,1);
TimingSep = linspace(min(Data(1,:)), max(Data(1,:)), model.nbStates+1);
diagRegularizationFactor = 1E-2;
for i=1:model.nbStates
idtmp = find( Data(1,:)>=TimingSep(i) & Data(1,:)<TimingSep(i+1));
......@@ -30,7 +25,7 @@ for i=1:model.nbStates
model.Mu(:,i) = mean(Data(:,idtmp)');
model.Sigma(:,:,i) = cov(Data(:,idtmp)');
%Regularization term to avoid numerical instability
model.Sigma(:,:,i) = model.Sigma(:,:,i) + eye(nbVar)*1E-2;
model.Sigma(:,:,i) = model.Sigma(:,:,i) + eye(nbVar)*diagRegularizationFactor;
end
model.Priors = model.Priors / sum(model.Priors);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment