Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
pbdlib-matlab
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rli
pbdlib-matlab
Commits
168c56ef
Commit
168c56ef
authored
Oct 17, 2014
by
Sylvain Calinon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New GMR example added
parent
b196c8ba
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
22 deletions
+25
-22
m_fcts/EM_GMM.m
m_fcts/EM_GMM.m
+14
-1
m_fcts/init_GMM_kmeans.m
m_fcts/init_GMM_kmeans.m
+6
-11
m_fcts/init_GMM_timeBased.m
m_fcts/init_GMM_timeBased.m
+5
-10
No files found.
m_fcts/EM_GMM.m
View file @
168c56ef
...
...
@@ -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
...
...
m_fcts/init_GMM_kmeans.m
View file @
168c56ef
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
);
m_fcts/init_GMM_timeBased.m
View file @
168c56ef
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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment