-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdemo_loadData.m
108 lines (99 loc) · 5.67 KB
/
demo_loadData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Demo Script for GMM Learning for paper: %
% "A Physically-Consistent Bayesian Non-Parametric Mixture Model for %
% Dynamical System Learning."; N. Figueroa and A. Billard; CoRL 2018 %
% %
% With this script you can load 2D toy trajectories or even real-world %
% trajectories acquired via kinesthetic taching and test the different %
% GMM fitting approaches. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (C) 2018 Learning Algorithms and Systems Laboratory, %
% EPFL, Switzerland %
% Author: Nadia Figueroa %
% email: nadia.figueroafernandez@epfl.ch %
% website: http://lasa.epfl.ch %
% %
% This work was supported by the EU project Cogimon H2020-ICT-23-2014. %
% %
% Permission is granted to copy, distribute, and/or modify this program %
% under the terms of the GNU General Public License, version 2 or any %
% later version published by the Free Software Foundation. %
% %
% This program 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 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Step 1 (DATA LOADING): Load Datasets %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all; clear all; clc
%%%%%%%%%%%%%%%%%%%%%%%%% Select a Dataset %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1: Concentric Circle Dataset (2D)
% 2: Opposing Motions Dataset (2D)
% 3: Multiple Target Dataset (2D)
% 4: Snake Dataset (2D)
% 5: Messy Snake Dataset (2D)
% 6: Via-Point Dataset (2D)
% 7: L-shape Dataset (2D)
% 8: A-shape Dataset (2D)
% 9: S-shape Dataset (2D)
% 10: Multi-Behavior Dataset (2D)
% 11: Via-point Dataset (test) (3D) -- 15 trajectories recorded at 100Hz
% 12: Sink Dataset (test) (3D) -- 21 trajectories recorded at 100Hz
% 13: Bumpy-Snake Dataset (test)(3D) -- 10 trajectories recorded at 100Hz
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
pkg_dir = pwd;
chosen_dataset = 1;
sub_sample = 1; % '>2' for real 3D Datasets, '1' for 2D toy datasets
nb_trajectories = 7; % For real 3D data
Data = load_dataset(pkg_dir, chosen_dataset, sub_sample, nb_trajectories);
%% Position/Velocity Trajectories
vel_samples = 15; vel_size = 0.75;
[h_data, h_vel] = plot_reference_trajectories(Data, vel_samples, vel_size);
% Extract Position and Velocities
[M,N] = size(Data);
M = M/2;
Xi_ref = Data(1:M,:);
Xi_dot_ref = Data(M+1:end,:);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Step 2 (GMM FITTING): Fit GMM to Trajectory Data %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%% GMM Estimation Algorithm %%%%%%%%%%%%%%%%%%%%%%
% 0: Physically-Consistent Non-Parametric (Collapsed Gibbs Sampler)
% 1: GMM-EM Model Selection via BIC
% 2: CRP-GMM (Collapsed Gibbs Sampler)
est_options = [];
est_options.type = 0; % GMM Estimation Algorithm Type
% If algo 1 selected:
est_options.maxK = 15; % Maximum Gaussians for Type 1
est_options.fixed_K = round(N/2); % Fix K and estimate with EM for Type 1
% If algo 0 or 2 selected:
est_options.samplerIter = 40; % Maximum Sampler Iterations
% For type 0: 20-50 iter is sufficient
% For type 2: >100 iter are needed
est_options.do_plots = 1; % Plot Estimation Statistics
est_options.sub_sample = 2; % Size of sub-sampling of trajectories
% Metric Hyper-parameters
est_options.estimate_l = 1; % 0/1 Estimate the lengthscale, if set to 1
est_options.l_sensitivity = 5; % lengthscale sensitivity [1-10->>100]
% Default value is set to '2' as in the
% paper, for very messy, close to
% self-interescting trajectories, we
% recommend a higher value
est_options.length_scale = []; % if estimate_l=0 you can define your own
% l, when setting l=0 only
% directionality is taken into account
% Fit GMM to Trajectory Data
tic;
[Priors, Mu, Sigma] = fit_gmm(Xi_ref, Xi_dot_ref, est_options);
toc;
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Step 3: Visualize Gaussian Components and labels on clustered trajectories %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Extract Cluster Labels
est_K = length(Priors);
[~, est_labels] = my_gmm_cluster(Xi_ref, Priors, Mu, Sigma, 'hard', []);
% Visualize Estimated Parameters
[h_gmm] = visualizeEstimatedGMM(Xi_ref, Priors, Mu, Sigma, est_labels, est_options);