Commit 4522d23a authored by Sylvain Calinon's avatar Sylvain Calinon

Use of a common 2D handwriting movement dataset in all examples

parent 37aaafb8
...@@ -2,17 +2,7 @@ ...@@ -2,17 +2,7 @@
PbDlib is a set of tools combining statistical learning, dynamical systems and optimal control approaches for programming-by-demonstration applications (see http://www.idiap.ch/software/pbdlib/ for details). PbDlib is a set of tools combining statistical learning, dynamical systems and optimal control approaches for programming-by-demonstration applications (see http://www.idiap.ch/software/pbdlib/ for details).
The Matlab/GNU Octave version is currently maintained by Sylvain Calinon, Idiap Research Institute. The Matlab/GNU Octave version is currently maintained by Sylvain Calinon, Idiap Research Institute. A C++ version of the library (with currently fewer functionalities) is available at https://gitlab.idiap.ch/rli/pbdlib
A C++ version of the library (with currently fewer functionalities) is available at https://gitlab.idiap.ch/rli/pbdlib
### Compatibility
The codes are compatible with both Matlab and GNU Octave.
### Usage
Examples starting with `demo_` can be run from Matlab/GNU Octave.
### References ### References
...@@ -39,9 +29,13 @@ Did you find PbDLib useful for your research? Please acknowledge the authors in ...@@ -39,9 +29,13 @@ Did you find PbDLib useful for your research? Please acknowledge the authors in
} }
``` ```
### Dataset ### Compatibility
The codes are compatible with both Matlab and GNU Octave.
The folder "data" contains a dataset of 2D handwriting movements from LASA-EPFL (http://lasa.epfl.ch), collected within the context of the AMARSI European Project. Reference: S.M. Khansari-Zadeh and A. Billard, "Learning Stable Non-Linear Dynamical Systems with Gaussian Mixture Models", IEEE Transaction on Robotics, 2011. ### Usage
Examples starting with `demo_` can be run from Matlab/GNU Octave.
### License ### License
......
...@@ -48,11 +48,11 @@ nbSamples = 4; %Number of demonstrations ...@@ -48,11 +48,11 @@ nbSamples = 4; %Number of demonstrations
L = [eye(model.nbVarPos)*model.kP, eye(model.nbVarPos)*model.kV]; %Feedback term L = [eye(model.nbVarPos)*model.kP, eye(model.nbVarPos)*model.kV]; %Feedback term
%% Load AMARSI data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
posId=[1:model.nbVar-1]; velId=[model.nbVar:2*(model.nbVar-1)]; accId=[2*(model.nbVar-1)+1:3*(model.nbVar-1)]; posId=[1:model.nbVar-1]; velId=[model.nbVar:2*(model.nbVar-1)]; accId=[2*(model.nbVar-1)+1:3*(model.nbVar-1)];
demos=[]; demos=[];
load('data/AMARSI/GShape.mat') load('data/2Dletters/G.mat');
sIn(1) = 1; %Initialization of decay term sIn(1) = 1; %Initialization of decay term
for t=2:nbData for t=2:nbData
sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s) sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s)
......
...@@ -50,11 +50,11 @@ nbSamples = 4; %Number of demonstrations ...@@ -50,11 +50,11 @@ nbSamples = 4; %Number of demonstrations
L = [eye(model.nbVarPos)*model.kP, eye(model.nbVarPos)*model.kV]; %Feedback term L = [eye(model.nbVarPos)*model.kP, eye(model.nbVarPos)*model.kV]; %Feedback term
%% Load AMARSI data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
posId=[1:model.nbVar-1]; velId=[model.nbVar:2*(model.nbVar-1)]; accId=[2*(model.nbVar-1)+1:3*(model.nbVar-1)]; posId=[1:model.nbVar-1]; velId=[model.nbVar:2*(model.nbVar-1)]; accId=[2*(model.nbVar-1)+1:3*(model.nbVar-1)];
demos=[]; demos=[];
load('data/AMARSI/GShape.mat'); load('data/2Dletters/G.mat');
sIn(1) = 1; %Initialization of decay term sIn(1) = 1; %Initialization of decay term
for t=2:nbData for t=2:nbData
sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s) sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s)
......
...@@ -54,10 +54,10 @@ K1d = [1, model.kV/model.kP, 1/model.kP]; ...@@ -54,10 +54,10 @@ K1d = [1, model.kV/model.kP, 1/model.kP];
K = kron(K1d,eye(model.nbVarPos)); K = kron(K1d,eye(model.nbVarPos));
%% Load AMARSI data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/GShape.mat'); load('data/2Dletters/G.mat');
sIn(1) = 1; %Initialization of decay term sIn(1) = 1; %Initialization of decay term
for t=2:nbData for t=2:nbData
sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s) sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s)
......
...@@ -56,10 +56,10 @@ K1d = [1, model.kV/model.kP, 1/model.kP]; ...@@ -56,10 +56,10 @@ K1d = [1, model.kV/model.kP, 1/model.kP];
K = kron(K1d,eye(model.nbVarPos)); K = kron(K1d,eye(model.nbVarPos));
%% Load AMARSI data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/GShape.mat'); load('data/2Dletters/G.mat');
sIn(1) = 1; %Initialization of decay term sIn(1) = 1; %Initialization of decay term
for t=2:nbData for t=2:nbData
sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s) sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s)
......
...@@ -69,10 +69,10 @@ K1d = [1, model.kV/model.kP, 1/model.kP]; ...@@ -69,10 +69,10 @@ K1d = [1, model.kV/model.kP, 1/model.kP];
K = kron(K1d,eye(model.nbVarPos)); K = kron(K1d,eye(model.nbVarPos));
%% Load AMARSI data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/GShape.mat'); load('data/2Dletters/G.mat');
sIn(1) = 1; %Initialization of decay term sIn(1) = 1; %Initialization of decay term
for t=2:nbData for t=2:nbData
sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s) sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s)
......
...@@ -53,7 +53,7 @@ model.dt = 0.01; %Duration of time step ...@@ -53,7 +53,7 @@ model.dt = 0.01; %Duration of time step
model.nbVarPos = model.nbVar-1; %Dimension of spatial variables model.nbVarPos = model.nbVar-1; %Dimension of spatial variables
model.rFactor = 1E-5; %Weighting term for the minimization of control commands in LQR model.rFactor = 1E-5; %Weighting term for the minimization of control commands in LQR
nbData = 200; %Number of datapoints in a trajectory nbData = 200; %Number of datapoints in a trajectory
nbSamples = 1; %Number of demonstrations nbSamples = 3; %Number of demonstrations
%Canonical system parameters %Canonical system parameters
A = kron([0 1; 0 0], eye(model.nbVarPos)); %See Eq. (5.1.1) in doc/TechnicalReport.pdf A = kron([0 1; 0 0], eye(model.nbVarPos)); %See Eq. (5.1.1) in doc/TechnicalReport.pdf
...@@ -71,10 +71,10 @@ K1d = [1, model.kV/model.kP, 1/model.kP]; ...@@ -71,10 +71,10 @@ K1d = [1, model.kV/model.kP, 1/model.kP];
K = kron(K1d,eye(model.nbVarPos)); K = kron(K1d,eye(model.nbVarPos));
%% Load AMARSI data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/Line.mat'); load('data/2Dletters/I.mat');
sIn(1) = 1; %Initialization of decay term sIn(1) = 1; %Initialization of decay term
for t=2:nbData for t=2:nbData
sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s) sIn(t) = sIn(t-1) - model.alpha * sIn(t-1) * model.dt; %Update of decay term (ds/dt=-alpha s)
...@@ -133,21 +133,22 @@ Fpert = zeros(model.nbVarPos,nbData); ...@@ -133,21 +133,22 @@ Fpert = zeros(model.nbVarPos,nbData);
%Fpert(:,5) = [4E4; 0]; %Impulse perturbation force at the beginning of the motion %Fpert(:,5) = [4E4; 0]; %Impulse perturbation force at the beginning of the motion
%Motion retrieval %Motion retrieval
x = Data(1:model.nbVarPos,1) + [-10; 10]; %Offset for the starting point x = Data(1:model.nbVarPos,1) + [-5; -2]; %Offset for the starting point
dx = zeros(model.nbVarPos,1); dx = zeros(model.nbVarPos,1);
for t=1:nbData for t=1:nbData
r(1).Data(:,t) = x;
K = (Bd' * P(:,:,t) * Bd + R) \ Bd' * P(:,:,t) * Ad; K = (Bd' * P(:,:,t) * Bd + R) \ Bd' * P(:,:,t) * Ad;
ddx = K * ([r(1).currTar(:,t); zeros(model.nbVarPos,1)] - [x; dx]) + Fpert(:,t); ddx = K * ([r(1).currTar(:,t); zeros(model.nbVarPos,1)] - [x; dx]) + Fpert(:,t);
dx = dx + ddx * model.dt; dx = dx + ddx * model.dt;
x = x + dx * model.dt; x = x + dx * model.dt;
r(1).Data(:,t) = x;
r(1).detKp(t) = det(K(:,1:model.nbVarPos)); r(1).detKp(t) = det(K(:,1:model.nbVarPos));
end end
%Motion retrieval %Motion retrieval
x = Data(1:model.nbVarPos,1) + [-10; 10]; %Offset for the starting point x = Data(1:model.nbVarPos,1) + [-5; -2]; %Offset for the starting point
dx = zeros(model.nbVarPos,1); dx = zeros(model.nbVarPos,1);
for t=1:nbData for t=1:nbData
r(2).Data(:,t) = x;
K = (Bd' * P(:,:,t) * Bd + R) \ Bd' * P(:,:,t) * Ad; K = (Bd' * P(:,:,t) * Bd + R) \ Bd' * P(:,:,t) * Ad;
%Corresponding scalar stiffness and damping gains (for comparison purpose) %Corresponding scalar stiffness and damping gains (for comparison purpose)
K(:,1:model.nbVarPos) = eye(model.nbVarPos) * det(K(:,1:model.nbVarPos))^(1/model.nbVarPos); K(:,1:model.nbVarPos) = eye(model.nbVarPos) * det(K(:,1:model.nbVarPos))^(1/model.nbVarPos);
...@@ -156,7 +157,6 @@ for t=1:nbData ...@@ -156,7 +157,6 @@ for t=1:nbData
ddx = K * ([r(1).currTar(:,t); zeros(model.nbVarPos,1)] - [x; dx]) + Fpert(:,t); ddx = K * ([r(1).currTar(:,t); zeros(model.nbVarPos,1)] - [x; dx]) + Fpert(:,t);
dx = dx + ddx * model.dt; dx = dx + ddx * model.dt;
x = x + dx * model.dt; x = x + dx * model.dt;
r(2).Data(:,t) = x;
end end
...@@ -185,14 +185,14 @@ axis equal; ...@@ -185,14 +185,14 @@ axis equal;
%Timeline plot of the nonlinear perturbing force %Timeline plot of the nonlinear perturbing force
subplot(2,4,[2:4]); hold on; subplot(2,4,[2:4]); hold on;
for n=1:nbSamples for n=1:nbSamples
plot(sIn, DataDMP(2,(n-1)*nbData+1:n*nbData), '-','linewidth',2,'color',[.7 .7 .7]); plot(sIn, DataDMP(3,(n-1)*nbData+1:n*nbData), '-','linewidth',2,'color',[.7 .7 .7]);
end end
for i=1:model.nbStates for i=1:model.nbStates
plotGMM(model.Mu(1:2,i), model.Sigma(1:2,1:2,i), clrmap(i,:), .7); plotGMM(model.Mu([1,3],i), model.Sigma([1,3],[1,3],i), clrmap(i,:), .7);
end end
plot(sIn, r(1).currTar(1,:), '-','linewidth',2,'color',[.8 0 0]); plot(sIn, r(1).currTar(2,:), '-','linewidth',2,'color',[.8 0 0]);
axis([0 1 min(DataDMP(2,:)) max(DataDMP(2,:))]); %axis([0 1 min(DataDMP(3,:)) max(DataDMP(3,:))]);
ylabel('$\hat{x}_1$','fontsize',16,'interpreter','latex'); ylabel('$\hat{x}_2$','fontsize',16,'interpreter','latex');
view(180,-90); view(180,-90);
%Timeline plot of the evolution of stiffness %Timeline plot of the evolution of stiffness
......
...@@ -48,7 +48,7 @@ nbVarOut = model.nbVar-1; %Dimension of spatial variables ...@@ -48,7 +48,7 @@ nbVarOut = model.nbVar-1; %Dimension of spatial variables
L = [eye(nbVarOut)*model.kP, eye(nbVarOut)*model.kV]; %Feedback term L = [eye(nbVarOut)*model.kP, eye(nbVarOut)*model.kV]; %Feedback term
%% Load AMARSI data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sIn(1) = 1; %Initialization of decay term sIn(1) = 1; %Initialization of decay term
for t=2:nbData for t=2:nbData
...@@ -61,7 +61,7 @@ end ...@@ -61,7 +61,7 @@ end
% D = (diag(ones(1,nbData-1),-1)-eye(nbData)) / model.dt; % D = (diag(ones(1,nbData-1),-1)-eye(nbData)) / model.dt;
% D(end,end) = 0; % D(end,end) = 0;
load('data/AMARSI/GShape.mat'); load('data/2Dletters/G.mat');
Data=[]; Data0=[]; Data=[]; Data0=[];
for n=1:nbSamples for n=1:nbSamples
DataTmp = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling DataTmp = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling
......
...@@ -41,10 +41,10 @@ nbSamples = 5; %Number of demonstrations ...@@ -41,10 +41,10 @@ nbSamples = 5; %Number of demonstrations
nbVar = 2; %Number of dimensions (max 2 for AMARSI data) nbVar = 2; %Number of dimensions (max 2 for AMARSI data)
%% Load AMARSI handwriting data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/GShape.mat'); load('data/2Dletters/G.mat');
for n=1:nbSamples for n=1:nbSamples
s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos(1:nbVar,:), linspace(1,size(demos{n}.pos,2),nbData)); %Resampling s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos(1:nbVar,:), linspace(1,size(demos{n}.pos,2),nbData)); %Resampling
end end
......
...@@ -38,13 +38,13 @@ addpath('./m_fcts/'); ...@@ -38,13 +38,13 @@ addpath('./m_fcts/');
model.nbStates = 5; %Number of states in the GMM model.nbStates = 5; %Number of states in the GMM
model.nbVar = 2; %Number of variables [x1,x2] model.nbVar = 2; %Number of variables [x1,x2]
nbData = 200; %Length of each trajectory nbData = 200; %Length of each trajectory
nbSamples = 5; %Number of demonstrations
%% Load handwriting data
%% Load AMARSI data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/GShape.mat'); load('data/2Dletters/G.mat');
nbSamples = length(demos); %nbSamples = length(demos);
Data=[]; Data=[];
for n=1:nbSamples for n=1:nbSamples
s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling
...@@ -60,9 +60,9 @@ model = EM_GMM(Data, model); ...@@ -60,9 +60,9 @@ model = EM_GMM(Data, model);
%% Plots %% Plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure('position',[10,10,1000,500]); hold on; box on; figure('position',[10,10,700,500]); hold on; box on;
plotGMM(model.Mu, model.Sigma, [.8 0 0]);
plot(Data(1,:),Data(2,:),'.','markersize',8,'color',[.7 .7 .7]); plot(Data(1,:),Data(2,:),'.','markersize',8,'color',[.7 .7 .7]);
plotGMM(model.Mu, model.Sigma, [.8 0 0],.5);
axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]); axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]);
%print('-dpng','graphs/demo_GMM01.png'); %print('-dpng','graphs/demo_GMM01.png');
......
...@@ -43,10 +43,10 @@ nbData = 200; %Length of each trajectory ...@@ -43,10 +43,10 @@ nbData = 200; %Length of each trajectory
nbSamples = 5; %Number of demonstrations nbSamples = 5; %Number of demonstrations
%% Load AMARSI handwriting data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/CShape.mat'); load('data/2Dletters/G.mat');
Data=[]; Data=[];
for n=1:nbSamples for n=1:nbSamples
s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling
...@@ -64,16 +64,16 @@ model = EM_GMM(Data, model); ...@@ -64,16 +64,16 @@ model = EM_GMM(Data, model);
%% Plots %% Plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure('position',[10,10,1000,500]); figure('position',[10,10,1300,500]);
%Plot GMM %Plot GMM
subplot(1,2,1); hold on; box on; title('GMM'); subplot(1,2,1); hold on; box on; title('GMM');
plotGMM(model.Mu(2:model.nbVar,:), model.Sigma(2:model.nbVar,2:model.nbVar,:), [.8 0 0]);
plot(Data(2,:),Data(3,:),'.','markersize',8,'color',[.7 .7 .7]); plot(Data(2,:),Data(3,:),'.','markersize',8,'color',[.7 .7 .7]);
plotGMM(model.Mu(2:model.nbVar,:), model.Sigma(2:model.nbVar,2:model.nbVar,:), [.8 0 0], .5);
axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]); axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]);
%Plot GMR %Plot GMR
subplot(1,2,2); hold on; box on; title('GMR'); subplot(1,2,2); hold on; box on; title('GMR');
plotGMM(DataOut, SigmaOut, [0 .8 0]);
plot(Data(2,:),Data(3,:),'.','markersize',8,'color',[.7 .7 .7]); plot(Data(2,:),Data(3,:),'.','markersize',8,'color',[.7 .7 .7]);
plotGMM(DataOut, SigmaOut, [0 .8 0], .03);
plot(DataOut(1,:),DataOut(2,:),'-','linewidth',2,'color',[0 .4 0]); plot(DataOut(1,:),DataOut(2,:),'-','linewidth',2,'color',[0 .4 0]);
axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]); axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]);
......
...@@ -52,15 +52,15 @@ nbData = 200; %Length of each trajectory ...@@ -52,15 +52,15 @@ nbData = 200; %Length of each trajectory
nbSamples = 5; %Number of demonstrations nbSamples = 5; %Number of demonstrations
%% Load AMARSI handwriting data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/GShape.mat'); %Load x1,x2 variables load('data/2Dletters/C.mat'); %Load x1,x2 variables
for n=1:nbSamples for n=1:nbSamples
s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling
end end
demos=[]; demos=[];
load('data/AMARSI/CShape.mat'); %Load x3,x4 variables load('data/2Dletters/D.mat'); %Load x3,x4 variables
Data=[]; Data=[];
for n=1:nbSamples for n=1:nbSamples
s(n).Data = [s(n).Data; spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData))]; %Resampling s(n).Data = [s(n).Data; spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData))]; %Resampling
...@@ -77,12 +77,12 @@ model = EM_HDGMM(Data, model); ...@@ -77,12 +77,12 @@ model = EM_HDGMM(Data, model);
%% Plots %% Plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure('position',[10,10,1000,500]); figure('position',[10,10,1300,500]);
for i=1:2 for i=1:2
subplot(1,2,i); hold on; box on; subplot(1,2,i); hold on; box on;
plotGMM(model0.Mu((i-1)*2+1:i*2,:), model0.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 .8 .8]);
plotGMM(model.Mu((i-1)*2+1:i*2,:), model.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 0 0]);
plot(Data((i-1)*2+1,:),Data(i*2,:),'.','markersize',8,'color',[.7 .7 .7]); plot(Data((i-1)*2+1,:),Data(i*2,:),'.','markersize',8,'color',[.7 .7 .7]);
plotGMM(model0.Mu((i-1)*2+1:i*2,:), model0.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 .8 .8], .5);
plotGMM(model.Mu((i-1)*2+1:i*2,:), model.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 0 0], .5);
axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]); axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]);
xlabel(['x_' num2str((i-1)*2+1)]); ylabel(['x_' num2str(i*2)]); xlabel(['x_' num2str((i-1)*2+1)]); ylabel(['x_' num2str(i*2)]);
end end
......
...@@ -42,15 +42,15 @@ nbData = 200; %Length of each trajectory ...@@ -42,15 +42,15 @@ nbData = 200; %Length of each trajectory
nbSamples = 5; %Number of demonstrations nbSamples = 5; %Number of demonstrations
%% Load AMARSI handwriting data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/GShape.mat'); %Load x1,x2 variables load('data/2Dletters/C.mat'); %Load x1,x2 variables
for n=1:nbSamples for n=1:nbSamples
s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling
end end
demos=[]; demos=[];
load('data/AMARSI/CShape.mat'); %Load x3,x4 variables load('data/2Dletters/D.mat'); %Load x3,x4 variables
Data=[]; Data=[];
for n=1:nbSamples for n=1:nbSamples
s(n).Data = [s(n).Data; spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData))]; %Resampling s(n).Data = [s(n).Data; spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData))]; %Resampling
...@@ -67,12 +67,12 @@ model = EM_MFA(Data, model); ...@@ -67,12 +67,12 @@ model = EM_MFA(Data, model);
%% Plots %% Plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure('position',[10,10,1000,500]); figure('position',[10,10,1300,500]);
for i=1:2 for i=1:2
subplot(1,2,i); hold on; box on; subplot(1,2,i); hold on; box on;
plotGMM(model0.Mu((i-1)*2+1:i*2,:), model0.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 .8 .8]);
plotGMM(model.Mu((i-1)*2+1:i*2,:), model.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 0 0]);
plot(Data((i-1)*2+1,:),Data(i*2,:),'.','markersize',8,'color',[.7 .7 .7]); plot(Data((i-1)*2+1,:),Data(i*2,:),'.','markersize',8,'color',[.7 .7 .7]);
plotGMM(model0.Mu((i-1)*2+1:i*2,:), model0.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 .8 .8], .5);
plotGMM(model.Mu((i-1)*2+1:i*2,:), model.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 0 0], .5);
axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]); axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]);
xlabel(['x_' num2str((i-1)*2+1)]); ylabel(['x_' num2str(i*2)]); xlabel(['x_' num2str((i-1)*2+1)]); ylabel(['x_' num2str(i*2)]);
end end
......
...@@ -42,15 +42,15 @@ nbData = 200; %Length of each trajectory ...@@ -42,15 +42,15 @@ nbData = 200; %Length of each trajectory
nbSamples = 5; %Number of demonstrations nbSamples = 5; %Number of demonstrations
%% Load AMARSI handwriting data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
demos=[]; demos=[];
load('data/AMARSI/GShape.mat'); %Load x1,x2 variables load('data/2Dletters/C.mat'); %Load x1,x2 variables
for n=1:nbSamples for n=1:nbSamples
s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling s(n).Data = spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData)); %Resampling
end end
demos=[]; demos=[];
load('data/AMARSI/CShape.mat'); %Load x3,x4 variables load('data/2Dletters/D.mat'); %Load x3,x4 variables
Data=[]; Data=[];
for n=1:nbSamples for n=1:nbSamples
s(n).Data = [s(n).Data; spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData))]; %Resampling s(n).Data = [s(n).Data; spline(1:size(demos{n}.pos,2), demos{n}.pos, linspace(1,size(demos{n}.pos,2),nbData))]; %Resampling
...@@ -67,12 +67,12 @@ model = EM_MPPCA(Data, model); ...@@ -67,12 +67,12 @@ model = EM_MPPCA(Data, model);
%% Plots %% Plots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure('position',[10,10,1000,500]); figure('position',[10,10,1300,500]);
for i=1:2 for i=1:2
subplot(1,2,i); hold on; box on; subplot(1,2,i); hold on; box on;
plotGMM(model0.Mu((i-1)*2+1:i*2,:), model0.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 .8 .8]);
plotGMM(model.Mu((i-1)*2+1:i*2,:), model.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 0 0]);
plot(Data((i-1)*2+1,:),Data(i*2,:),'.','markersize',8,'color',[.7 .7 .7]); plot(Data((i-1)*2+1,:),Data(i*2,:),'.','markersize',8,'color',[.7 .7 .7]);
plotGMM(model0.Mu((i-1)*2+1:i*2,:), model0.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 .8 .8], .5);
plotGMM(model.Mu((i-1)*2+1:i*2,:), model.Sigma((i-1)*2+1:i*2,(i-1)*2+1:i*2,:), [.8 0 0], .5);
axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]); axis equal; set(gca,'Xtick',[]); set(gca,'Ytick',[]);
xlabel(['x_' num2str((i-1)*2+1)]); ylabel(['x_' num2str(i*2)]); xlabel(['x_' num2str((i-1)*2+1)]); ylabel(['x_' num2str(i*2)]);
end end
......
...@@ -36,7 +36,7 @@ addpath('./m_fcts/'); ...@@ -36,7 +36,7 @@ addpath('./m_fcts/');
%% Parameters %% Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nbSamples = 3; %Number of demonstrations nbSamples = 5; %Number of demonstrations
nbRepros = 5; %Number of reproductions nbRepros = 5; %Number of reproductions
nbData = 100; %Number of datapoints nbData = 100; %Number of datapoints
...@@ -68,9 +68,9 @@ for n=2:nbData ...@@ -68,9 +68,9 @@ for n=2:nbData
M = [A*M(:,1:model.nbVarPos), M]; M = [A*M(:,1:model.nbVarPos), M];
end end
%% Load AMARSI handwriting data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('data/AMARSI/GShape.mat') load('data/2Dletters/G.mat');
Data=[]; Data=[];
for n=1:nbSamples for n=1:nbSamples
s(n).Data=[]; s(n).Data=[];
......
...@@ -36,7 +36,7 @@ addpath('./m_fcts/'); ...@@ -36,7 +36,7 @@ addpath('./m_fcts/');
%% Parameters %% Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nbSamples = 3; %Number of demonstrations nbSamples = 5; %Number of demonstrations
nbRepros = 5; %Number of reproductions nbRepros = 5; %Number of reproductions
nbData = 100; %Number of datapoints nbData = 100; %Number of datapoints
...@@ -69,9 +69,9 @@ for n=2:nbData ...@@ -69,9 +69,9 @@ for n=2:nbData
end end
%% Load AMARSI handwriting data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('data/AMARSI/GShape.mat') load('data/2Dletters/G.mat');
Data=[]; Data=[];
for n=1:nbSamples for n=1:nbSamples
s(n).Data=[]; s(n).Data=[];
......
...@@ -61,14 +61,13 @@ model.dt = 0.01; %Time step duration ...@@ -61,14 +61,13 @@ model.dt = 0.01; %Time step duration
%Dynamical System settings (discrete version) %Dynamical System settings (discrete version)
A = kron([1, model.dt; 0, 1], eye(model.nbVarPos)); A = kron([1, model.dt; 0, 1], eye(model.nbVarPos));
B = kron([0; model.dt], eye(model.nbVarPos)); B = kron([0; model.dt], eye(model.nbVarPos));
C = kron([1, 0], eye(model.nbVarPos));
%Control cost matrix %Control cost matrix
R = eye(model.nbVarPos) * model.rfactor; R = eye(model.nbVarPos) * model.rfactor;
%% Load Data %% Load handwriting data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%