forked from verivital/nnv
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspiral2D_nonlinear_reach.m
87 lines (70 loc) · 2.71 KB
/
spiral2D_nonlinear_reach.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
function spiral2D_nonlinear_reach()
%% Reachability analysis of a spiral2D Neural ODE
% Function defined in a different file for CORA
C = eye(2);
reachstep = 0.01; % step size to compute reach sets
final_time = 10.0; % Time horizon
Initial_radius = 0.01; % Uncertainty in dynamics (initial states)
% Contruct NeuralODE (odeblock)
model = NonLinearODE(2,1,@spiral_non,reachstep,final_time,C); % Nonlinear ODE plant
% Change default options
model.options.timeStep = 0.01;
model.options.taylorTerms = 2;
model.options.zonotopeOrder = 20;
model.options.alg = 'lin';
model.options.tensorOrder = 2;
% Initial states
x0 = [2.0;0.0]; % This is like the initial input to the ODEblock (initial state)
lb = x0 - Initial_radius;
ub = x0 + Initial_radius;
init_set = Star(lb,ub);
input_set = Star(0,0); % No inputs, but need to define it
% Compute reachability analysis
t = tic;
R = model.stepReachStar(init_set,input_set);
time = toc(t);
Rall = model.intermediate_reachSet;
save('spiral_nl_0.01.mat','Rall','time')
%% Reachability scenario 2
Initial_radius = 0.05; % Uncertainty in dynamics (initial states)
% Contruct NeuralODE (odeblock)
model = NonLinearODE(2,1,@spiral_non,reachstep,final_time,C); % Nonlinear ODE plant
% Change default options
model.options.timeStep = 0.01;
model.options.taylorTerms = 2;
model.options.zonotopeOrder = 20;
model.options.alg = 'lin';
model.options.tensorOrder = 2;
% Initial states
lb = x0 - Initial_radius;
ub = x0 + Initial_radius;
init_set = Star(lb,ub);
input_set = Star(0,0); % No inputs, but need to define it
% Compute reachability analysis
t = tic;
R = model.stepReachStar(init_set,input_set);
time = toc(t);
Rall = model.intermediate_reachSet;
save('spiral_nl_0.05.mat','Rall','time')
%% Reachability scenario #3
Initial_radius = 0.1; % Uncertainty in dynamics (initial states)
% Contruct NeuralODE (odeblock)
model = NonLinearODE(2,1,@spiral_non,reachstep,final_time,C); % Nonlinear ODE plant
% Change default options
model.options.timeStep = 0.01;
model.options.taylorTerms = 2;
model.options.zonotopeOrder = 20;
model.options.alg = 'lin';
model.options.tensorOrder = 2;
% Initial states
lb = x0 - Initial_radius;
ub = x0 + Initial_radius;
init_set = Star(lb,ub);
input_set = Star(0,0); % No inputs, but need to define it
% Compute reachability analysis
t = tic;
R = model.stepReachStar(init_set,input_set);
time = toc(t);
Rall = model.intermediate_reachSet;
save('spiral_nl_0.1.mat','Rall','time')
end