-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdemo_drawData.m
97 lines (86 loc) · 4.86 KB
/
demo_drawData.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Demo Code 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 draw 2D toy trajectories and test 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): Draw 2D Trajectories with GUI %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all; clear all; clc
fig1 = figure('Color',[1 1 1]);
limits = [-4 4 -4 4];
axis(limits)
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0.25, 0.55, 0.2646 0.4358]);
grid on
% Draw Reference Trajectories
data = draw_mouse_data_on_fig(fig1, limits);
Data = [];
for l=1:length(data)
% Gather Data
data_ = data{l};
Data = [Data data_];
end
% Visualize Position/Velocity Trajectories
close;
Xi_ref = Data(1:2,:);
Xi_dot_ref = Data(3:end,:);
vel_samples = 15; vel_size = 0.85;
[h_data, h_vel] = plot_reference_trajectories(Data, vel_samples, vel_size);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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 = []; % Fix K and estimate with EM for Type 1
% If algo 0 or 2 selected:
est_options.samplerIter = 100; % 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 = 1; % Size of sub-sampling of trajectories
% Metric Hyper-parameters
est_options.estimate_l = 1; % Estimate the lengthscale, if set to 1
est_options.l_sensitivity = 10; % 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
[Priors, Mu, Sigma] = fit_gmm(Xi_ref, Xi_dot_ref, est_options);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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);