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
edcab51a
Commit
edcab51a
authored
Jul 30, 2014
by
Sylvain Calinon
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab.idiap.ch:rli/task-parameterized-tensor-gmm-with-lqr
parents
878c14e4
b2adef22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
0 deletions
+78
-0
init_tensorGMM_kmeans.m
init_tensorGMM_kmeans.m
+32
-0
kmeansClustering.m
kmeansClustering.m
+46
-0
No files found.
init_tensorGMM_kmeans.m
0 → 100644
View file @
edcab51a
function
model
=
init_tensorGMM_kmeans
(
Data
,
model
)
% Author: Leonel Rozo, 2014
% http://programming-by-demonstration.org/LeonelRozo
%
diagRegularizationFactor
=
1E-4
;
%Matricization/flattening of tensor
DataAll
=
reshape
(
Data
,
size
(
Data
,
1
)
*
size
(
Data
,
2
),
size
(
Data
,
3
));
%The function 'kmeans' below is from the Matlab Statistics Toolbox (see note above)
[
Data_id
,
Centers
]
=
kmeans
(
DataAll
'
,
model
.
nbStates
);
% Setting means and covariance matrices
Mu
=
Centers
'
;
Sigma
=
zeros
(
model
.
nbFrames
*
model
.
nbVar
,
model
.
nbFrames
*
model
.
nbVar
,
model
.
nbStates
);
for
i
=
1
:
model
.
nbStates
idtmp
=
find
(
Data_id
==
i
);
model
.
Priors
(
i
)
=
length
(
idtmp
);
Sigma
(:,:,
i
)
=
cov
(
DataAll
(:,
idtmp
)
'
)
+
eye
(
size
(
DataAll
,
1
))
*
diagRegularizationFactor
;
end
model
.
Priors
=
model
.
Priors
/
sum
(
model
.
Priors
);
%Reshape GMM parameters into a tensor
for
m
=
1
:
model
.
nbFrames
for
i
=
1
:
model
.
nbStates
model
.
Mu
(:,
m
,
i
)
=
Mu
((
m
-
1
)
*
model
.
nbVar
+
1
:
m
*
model
.
nbVar
,
i
);
model
.
Sigma
(:,:,
m
,
i
)
=
Sigma
((
m
-
1
)
*
model
.
nbVar
+
1
:
m
*
model
.
nbVar
,(
m
-
1
)
*
model
.
nbVar
+
1
:
m
*
model
.
nbVar
,
i
);
end
end
kmeansClustering.m
0 → 100644
View file @
edcab51a
function
[
idList
,
Mu
]
=
kmeansClustering
(
Data
,
nbStates
)
% Initialization of the model with k-means.
% Author: Sylvain Calinon, Tohid Alizadeh, 2013
% http://programming-by-demonstration.org/
%Criterion to stop the EM iterative update
cumdist_threshold
=
1e-10
;
maxIter
=
100
;
%Initialization of the parameters
[
nbVar
,
nbData
]
=
size
(
Data
);
cumdist_old
=
-
realmax
;
nbStep
=
0
;
idTmp
=
randperm
(
nbData
);
Mu
=
Data
(:,
idTmp
(
1
:
nbStates
));
%k-means iterations
while
1
%E-step %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for
i
=
1
:
nbStates
%Compute distances
distTmp
(:,
i
)
=
sum
((
Data
-
repmat
(
Mu
(:,
i
),
1
,
nbData
))
.^
2
);
end
[
vTmp
,
idList
]
=
min
(
distTmp
,[],
2
);
cumdist
=
sum
(
vTmp
);
%M-step %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for
i
=
1
:
nbStates
%Update the centers
Mu
(:,
i
)
=
mean
(
Data
(:,
idList
==
i
),
2
);
end
%Stopping criterion %%%%%%%%%%%%%%%%%%%%
if
abs
(
cumdist
-
cumdist_old
)
<
cumdist_threshold
break
;
end
cumdist_old
=
cumdist
;
nbStep
=
nbStep
+
1
;
% if nbStep>maxIter
% disp(['Maximum number of iterations, ' num2str(maxIter) 'is reached']);
% break;
% end
end
%disp(['Kmeans stopped after ' num2str(nbStep) ' steps.']);
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