Skip to content

Commit e06a178

Browse files
authored
Merge pull request #225 from mldiego/master
Tutorial DSN 2024
2 parents 43ac8a8 + 70edd62 commit e06a178

File tree

12 files changed

+285
-357
lines changed

12 files changed

+285
-357
lines changed

code/nnv/engine/nn/layers/Conv1DLayer.m

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,10 @@ function set_name(obj, name)
521521

522522
end
523523

524-
% reachability analysis using star set
525-
methods
526-
% reachability analysis method using Stars
527-
% a star represent a set of images (2D matrix of h x w)
524+
525+
methods % reachability analysis using Stars
526+
527+
% reachability analysis using star set
528528
function S = reach_star_single_input(obj, input)
529529
% @inputs: an ImageStar input set
530530
% @S: an ImageStar with number of channels = obj.NumFilters
@@ -555,30 +555,6 @@ function set_name(obj, name)
555555

556556
end
557557

558-
% reachability analysis using ImageZonos
559-
function Z = reach_zono(obj, input)
560-
% @input: an ImageZono input set
561-
% @Z: an ImageZono with number of channels = obj.NumFilters
562-
563-
if ~isa(input, 'ImageZono')
564-
error('The input is not an ImageZono object');
565-
end
566-
567-
if input.numChannels ~= obj.NumChannels
568-
error("Input set contains %d channels while the convolutional layers has %d channels", input.numChannels, obj.NumChannels);
569-
end
570-
571-
% compute output sets
572-
c = vl_nnconv1d(input.V(:,:,:,1), obj.Weights, obj.Bias', obj.Stride, obj.PaddingSize, obj.DilationFactor);
573-
n = size(input.V(:,:,:,2:input.numPred + 1),4);
574-
for i = 1:n
575-
V(:,:,1,i) = vl_nnconv1d(input.V(:,:,:,i+1), obj.Weights, 0, obj.Stride, obj.PaddingSize, obj.DilationFactor);
576-
end
577-
Y = cat(4, c, V);
578-
Z = ImageZono(Y);
579-
580-
end
581-
582558
% hangle multiple inputs
583559
function images = reach_star_multipleInputs(obj, in_signals, option)
584560
% @in_images: an array of ImageStars input set
@@ -602,27 +578,6 @@ function set_name(obj, name)
602578
end
603579

604580
end
605-
606-
function images = reach_zono_multipleInputs(obj, in_images, option)
607-
% @in_images: an array of ImageZonos input set
608-
% @option: = 'parallel' or 'single' or empty
609-
610-
n = length(in_images);
611-
images(n) = ImageZono;
612-
613-
if strcmp(option, 'parallel')
614-
parfor i=1:n
615-
images(i) = obj.reach_zono(in_images(i));
616-
end
617-
elseif strcmp(option, 'single') || isempty(option)
618-
for i=1:n
619-
images(i) = obj.reach_zono(in_images(i));
620-
end
621-
else
622-
error('Unknown computation option');
623-
end
624-
625-
end
626581

627582
% reach star with multiple inputs
628583
function images = reachSequence(varargin)

code/nnv/engine/utils/findElementwiseAffineLayers.m

Lines changed: 0 additions & 11 deletions
This file was deleted.

code/nnv/engine/utils/parse_onnx_to_nnvnet.m

Lines changed: 0 additions & 70 deletions
This file was deleted.

code/nnv/engine/utils/vl_nnconv1d.m

Lines changed: 0 additions & 68 deletions
This file was deleted.

code/nnv/examples/Submission/ARCH-COMP2024/benchmarks/Attitude Control/reach.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% function t = reach()
1+
function t = reach()
22

33
%% Reachability analysis of the aircarft attitude benchmark
44

@@ -97,7 +97,7 @@
9797
exportgraphics(f,'attitude_5v6.pdf','ContentType', 'vector');
9898
end
9999

100-
% end
100+
end
101101

102102
%% Helper function
103103
function init_set = plantReach(plant,init_set,input_set,algoC)

code/nnv/examples/Submission/ARCH-COMP2024/benchmarks/Benchmark10-Unicycle/reach.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% function t = reach()
1+
function t = reach()
22

33
%% Reachability analysis of the Unicycle (benchmark 10)
44

@@ -33,8 +33,8 @@
3333
% Store all reachable sets
3434
reachAll = init_set;
3535
% Execute reachabilty analysis
36-
% steps = 25;
37-
steps = 50;
36+
steps = 25;
37+
% steps = 50;
3838
reachOptions.reachMethod ='approx-star';
3939
t = tic;
4040
for i=1:steps
@@ -80,7 +80,7 @@
8080
exportgraphics(f1,'unicycle_3v4.pdf', 'ContentType', 'vector');
8181
end
8282

83-
% end
83+
end
8484

8585
%% Helper function
8686
function init_set = plantReach(plant,init_set,input_set,algoC)

code/nnv/examples/Submission/ARCH-COMP2024/benchmarks/CartPole/reach.m

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
% function t = reach()
1+
function t = reach()
22

33
%% Reachability analysis of Cartpole Benchmark
44

@@ -13,6 +13,7 @@
1313
plant = NonLinearODE(4,1,@dynamics, reachStep, controlPeriod, eye(4));
1414
plant.set_tensorOrder(2);
1515

16+
t = tic;
1617

1718
%% Reachability analysis
1819

@@ -28,17 +29,25 @@
2829
reachAll = init_set;
2930
num_steps = 500;
3031
reachOptions.reachMethod = 'approx-star';
31-
t = tic;
32+
% t = tic;
3233
for i=1:num_steps
3334
disp(i);
3435
% Compute controller output set
3536
input_set = net.reach(init_set,reachOptions);
3637
% Compute plant reachable set
37-
init_set = plant.stepReachStar(init_set, input_set,'lin');
38+
init_set = plantReach(plant,init_set,input_set,'lin');
3839
reachAll = [reachAll init_set];
39-
toc(t);
40+
% toc(t);
4041
end
41-
t = toc(t);
42+
% t = toc(t);
43+
end
44+
t = toc(t);
45+
46+
% Save results
47+
if is_codeocean
48+
save('/results/logs/cartpole.mat', 'reachAll','t','-v7.3');
49+
else
50+
save('cartpole.mat', 'reachAll','t','-v7.3');
4251
end
4352

4453
%% Visualize results
@@ -56,11 +65,22 @@
5665
% ylabel('\theta');
5766
% xlim([0 0.6])
5867
% ylim([0.95 1.25])
68+
5969
% Save figure
60-
% if is_codeocean
61-
% exportgraphics(f,'/results/logs/cartpole.pdf', 'ContentType', 'vector');
62-
% else
63-
% exportgraphics(f,'cartpole.pdf','ContentType', 'vector');
64-
% end
70+
if is_codeocean
71+
exportgraphics(f,'/results/logs/cartpole.pdf', 'ContentType', 'vector');
72+
else
73+
exportgraphics(f,'cartpole.pdf','ContentType', 'vector');
74+
end
75+
76+
end
6577

66-
% end
78+
%% Helper function
79+
function init_set = plantReach(plant,init_set,input_set,algoC)
80+
nS = length(init_set); % based on approx-star, number of sets should be equal
81+
ss = [];
82+
for k=1:nS
83+
ss =[ss plant.stepReachStar(init_set(k), input_set(k),algoC)];
84+
end
85+
init_set = ss;
86+
end

0 commit comments

Comments
 (0)