Skip to content

Commit 7c764fd

Browse files
committed
Merge branch 'test_ex_singletrack'
2 parents 1a24012 + ca2ed41 commit 7c764fd

12 files changed

+252
-146
lines changed

GP.m

Lines changed: 155 additions & 130 deletions
Large diffs are not rendered by default.

Papers/kabzan2019learning.pdf

-1.32 MB
Binary file not shown.

Papers/kocijan2004gaussian.pdf

-432 KB
Binary file not shown.

Papers/ostafew2016learning.pdf

-1.58 MB
Binary file not shown.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ and it is trained (hyperparameter optimization) by maximizing the log Likelihood
3636
### Results
3737

3838

39-
| MPC controller with Gaussian Process **deactivated** | MPC controller with **TRAINED** and **ACTIVATED** Gaussian Process |
39+
| NMPC controller with unmodelled dynamics | Adaptive NMPC controller (with trained Gaussian Process) |
4040
| ------------- |-------------|
4141
| <img src="./simresults/trackAnimVideo-16-Jan-2020-without-GP.gif" alt="drawing" width="400"/> | <img src="./simresults/trackAnimVideo-16-Jan-2020-with-GP-optimized.gif" alt="drawing" width="400"/> |
4242

ex_invertedPendulum_sim.slx

-31.1 KB
Binary file not shown.

ex_invertedPendulum_sim.slxc

-4.56 KB
Binary file not shown.

main_invertedPendulum.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@
236236

237237
%% Optimize GP hyperparameters ??? (Offline procedure, after simulation)
238238

239-
d_GP.M = M
240-
d_GP.var_f = var_f;
241-
d_GP.var_n = var_n;
242-
239+
d_GP.setHyperParameters( M, var_f, var_n )
243240
% d_GP.optimizeHyperParams('ga');
244241
d_GP.optimizeHyperParams('fmincon');
245242

main_singletrack.m

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -487,16 +487,6 @@
487487
gamma = 1000;
488488
lambda = -0.1;
489489
offroad_error = 5*(sqrt((4+gamma*(lambda-offroad_error).^2)/gamma) - (lambda-offroad_error));
490-
491-
% % CHECK SMOOTH TRANSITION
492-
% x = -0.5:0.01:0.5
493-
% % Relaxied barrier function for (x<=lambda)
494-
% gamma = 10000;
495-
% lambda = -0.2;
496-
% y = 0.5*(sqrt((4+gamma*(lambda-x).^2)/gamma) - (lambda-x)); % y = -log(lambda-x)
497-
% figure; hold on; grid on;
498-
% plot(x,y)
499-
500490
cost_outside = q_r * offroad_error^2;
501491

502492
% ---------------------------------------------------------------------

genFigs.m renamed to test-files/genFigs.m

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,31 @@
3333
cellfun( @(h) delete(h), trackAnim.h_var_x_pred_opt )
3434
legend('off')
3535
title('')
36-
fp.savefig(imgname,'format','epsc')
36+
fp.savefig(imgname,'format','epsc')
37+
38+
39+
40+
41+
42+
%% CHECK RELAXED BARRIER FUNCTION PLOT
43+
44+
45+
x = -0.5:0.001:0.5;
46+
% Relaxied barrier function for (x<=lambda)
47+
gamma = 10000;
48+
lambda = -0.2;
49+
y = 0.5*(sqrt((4+gamma*(lambda-x).^2)/gamma) - (lambda-x));
50+
figure('Color','w'); hold on; %grid on;
51+
plot(x,y,'LineWidth',2)
52+
ylim([0,0.1])
53+
xlim([-0.4,0])
54+
set(gca,'YTickLabel',[]);
55+
set(gca,'XTickLabel',[]);
56+
%%%%
57+
lambda = -0.2;
58+
x = -0.6:0.001:(lambda-eps);
59+
y = 0.1*-log(lambda-x);
60+
figure('Color','w'); hold on; %grid on;
61+
plot(x,y,'LineWidth',2)
62+
xlim([-0.6,0])
63+

test-files/test_GP.m

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
clear all; close all; clc;
2+
3+
var_w = 1e-8;
4+
var_f = 1e4; % output variance
5+
M = diag(1e0); % length scale
6+
var_n = var_w; % measurement noise variance
7+
maxsize = 100; % maximum number of points in the dictionary
8+
9+
% create GP object
10+
gp = GP(1, 1, var_f, var_n, M, maxsize);
11+
12+
%% true function
13+
Xt = [-4 -3 -2 -1 0 1 2 3 4];
14+
Yt = [-1 0.5 1.5 1.5 1 0.8 1 1.5 2]';
15+
pp = spline(Xt,Yt');
16+
truefun = @(x) ppval(pp, x)';
17+
18+
%% measure data
19+
X = Xt([1 2 3 5 7 8]);
20+
Y = truefun(X) + sqrt(var_n)*randn(length(X),1);
21+
22+
gp.add(X,Y);
23+
24+
25+
%% plot
26+
close all;
27+
28+
% test 1
29+
gp.setHyperParameters(1e-2, 2, var_w)
30+
gp.plot1d(truefun)
31+
xlim([-6 5]); ylim([-4 4]);
32+
33+
% test 2
34+
gp.setHyperParameters(50, 100, var_w)
35+
gp.plot1d(truefun)
36+
xlim([-6 5]); ylim([-4 4]);
37+
38+
% test 3
39+
gp.setHyperParameters(1e-3, 1e-2, var_w)
40+
gp.plot1d(truefun)
41+
xlim([-6 5]); ylim([-4 4]);
42+
43+
% test 4
44+
gp.setHyperParameters(50, 1e7, var_w)
45+
gp.plot1d(truefun)
46+
xlim([-6 5]); ylim([-4 4]);
47+
48+
% test 4
49+
gp.setHyperParameters(100^2, 100^2, 1^2)
50+
gp.plot1d(truefun)
51+
xlim([-6 5]); ylim([-4 4]);
52+
53+
%% optimize and plot
54+
55+
gp.setHyperParameters(0.1^2, 0.1^2, 1e-8)
56+
% gp.optimizeHyperParams('ga');
57+
gp.optimizeHyperParams('fmincon');
58+
59+
close all
60+
gp.plot1d(truefun)
61+
xlim([-6 5]); ylim([-4 4]);
62+
63+
%%
64+
close all
65+
gp.setHyperParameters(1.5^2, 2^2, 4.0228e-09)
66+
gp.plot1d(truefun)
67+
xlim([-6 5]); ylim([-5 5]);

0 commit comments

Comments
 (0)