Commit 2d33bc80 authored by Sylvain Calinon's avatar Sylvain Calinon

Simplification of GMR function

parent bc2b5f28
function [expData, expSigma, H] = GMR(model, DataIn, in, out)
%Gaussian mixture regression (GMR)
%Sylvain Calinon, Danilo Bruno, 2014
% Gaussian mixture regression (GMR)
%
% Authors: Sylvain Calinon, Danilo Bruno, 2014
% http://programming-by-demonstration.org/lib/
%
% This source code is given for free! In exchange, we would be grateful if you 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",
% }
nbData = size(DataIn,2);
nbVarOut = length(out);
......@@ -8,6 +23,8 @@ nbVarOut = length(out);
MuTmp = zeros(nbVarOut,model.nbStates);
expData = zeros(nbVarOut,nbData);
expSigma = zeros(nbVarOut,nbVarOut,nbData);
expSigma2 = zeros(nbVarOut,nbVarOut,nbData);
expSigma3 = zeros(nbVarOut,nbVarOut,nbData);
for t=1:nbData
%Compute activation weight
%See Eq. (3.0.5) in doc/TechnicalReport.pdf
......@@ -16,19 +33,17 @@ for t=1:nbData
end
H(:,t) = H(:,t)/sum(H(:,t));
%Compute expected conditional means
%See Eq. (3.0.3) in doc/TechnicalReport.pdf
%See Eq. (3.0.8) in doc/TechnicalReport.pdf
for i=1:model.nbStates
MuTmp(:,i) = model.Mu(out,i) + model.Sigma(out,in,i)/model.Sigma(in,in,i) * (DataIn(:,t)-model.Mu(in,i));
expData(:,t) = expData(:,t) + H(i,t) * MuTmp(:,i);
end
%Compute expected conditional covariances
%See Eq. (3.0.4) in doc/TechnicalReport.pdf
%See Eq. (3.0.14) in doc/TechnicalReport.pdf
for i=1:model.nbStates
SigmaTmp = model.Sigma(out,out,i) - model.Sigma(out,in,i)/model.Sigma(in,in,i) * model.Sigma(in,out,i);
expSigma(:,:,t) = expSigma(:,:,t) + H(i,t) * (SigmaTmp + MuTmp(:,i)*MuTmp(:,i)');
for j=1:model.nbStates
expSigma(:,:,t) = expSigma(:,:,t) - H(i,t)*H(j,t) * (MuTmp(:,i)*MuTmp(:,j)');
end
end
expSigma(:,:,t) = expSigma(:,:,t) - expData(:,t)*expData(:,t)';
end
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