Skip to content

Commit e2f6cce

Browse files
committed
cleanup
1 parent f433d91 commit e2f6cce

123 files changed

Lines changed: 1475 additions & 6098 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

example/benchmark_boundary_analysis_vs_naive_partition_cmp.py renamed to benchmarks/benchmark_boundary_analysis_vs_naive_partition_cmp.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
import numpy as np
22
from pybdr.geometry import Interval, Zonotope, Geometry
33
from pybdr.geometry.operation import cvt2, partition, boundary
4-
from pybdr.algorithm import ASB2008CDCParallel
4+
from pybdr.algorithm import ASB2008CDC
55
from pybdr.dynamic_system import NonLinSys
66
from pybdr.model import *
77
from pybdr.util.visualization import plot, plot_cmp
88
from pybdr.util.functional import performance_counter, performance_counter_start
99

1010
if __name__ == '__main__':
11-
# tuples_list = [(1, 'a', 'x', 'u'), (2, 'b', 'y', 'v'), (3, 'c', 'z', 'w')]
12-
#
13-
# lists_list = [list(t) for t in zip(*tuples_list)]
14-
#
15-
# print(lists_list)
16-
#
17-
# exit(False)
18-
time_start = performance_counter_start()
19-
# init dynamic system
20-
# system = NonLinSys(Model(lotka_volterra_2d, [2, 1]))
21-
2211
# settings for the computation
23-
options = ASB2008CDCParallel.Options()
12+
options = ASB2008CDC.Options()
2413
options.t_end = 2.2
2514
options.step = 0.005
2615
options.tensor_order = 3
@@ -35,35 +24,35 @@
3524

3625
init_set = Interval.identity(2) * 0.5 + 3
3726

38-
_, tp_whole = ASB2008CDCParallel.reach(lotka_volterra_2d, [2, 1], options,
39-
cvt2(init_set, Geometry.TYPE.ZONOTOPE))
27+
time_start = performance_counter_start()
28+
_, rp_without_bound = ASB2008CDC.reach(lotka_volterra_2d, [2, 1], options, cvt2(init_set, Geometry.TYPE.ZONOTOPE))
4029

4130
# NAIVE PARTITION
4231
# --------------------------------------------------------
4332
# options.r0 = partition(z, 1, Geometry.TYPE.ZONOTOPE)
4433
# xs = partition(init_set, 1, Geometry.TYPE.ZONOTOPE)
4534
# 4
46-
# ASB2008CDCParallel.reach_parallel cost: 20.126129667s
35+
# ASB2008CDCParallel.reach_parallel cost: 20.126129667s MacOS
4736
# --------------------------------------------------------
4837
# xs = partition(init_set, 0.5, Geometry.TYPE.ZONOTOPE)
4938
# 9
50-
# ASB2008CDCParallel.reach_parallel cost: 23.938516459000002s
39+
# ASB2008CDCParallel.reach_parallel cost: 23.938516459000002s MacOS
5140
# --------------------------------------------------------
52-
xs = partition(init_set, 0.2, Geometry.TYPE.ZONOTOPE)
41+
# xs = partition(init_set, 0.2, Geometry.TYPE.ZONOTOPE)
5342
# 36
54-
# ASB2008CDCParallel.reach_parallel cost: 65.447113125s
43+
# ASB2008CDCParallel.reach_parallel cost: 65.447113125s MacOS
5544
# --------------------------------------------------------
5645

5746
# BOUNDAYR ANALYSIS
5847
# --------------------------------------------------------
5948
xs = boundary(init_set, 1, Geometry.TYPE.ZONOTOPE)
6049
# 8
61-
# ASB2008CDCParallel.reach_parallel cost: 22.185758250000003s
50+
# ASB2008CDCParallel.reach_parallel cost: 22.185758250000003s MacOS
6251

6352
print(len(xs))
6453

65-
_, tp_part_00 = ASB2008CDCParallel.reach_parallel(lotka_volterra_2d, [2, 1], options, xs)
54+
_, rp_with_bound = ASB2008CDC.reach_parallel(lotka_volterra_2d, [2, 1], options, xs)
6655

6756
performance_counter(time_start, "ASB2008CDCParallel.reach_parallel")
6857

69-
plot_cmp([tp_whole, tp_part_00], [0, 1], cs=["#FF5722", "#303F9F"])
58+
plot_cmp([rp_without_bound, rp_with_bound], [0, 1], cs=["#FF5722", "#303F9F"])
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
from pybdr.algorithm import ASB2008CDC
3+
from pybdr.geometry import Zonotope, Interval, Geometry
4+
from pybdr.geometry.operation import boundary, cvt2
5+
from pybdr.model import *
6+
from pybdr.util.visualization import plot_cmp
7+
8+
if __name__ == '__main__':
9+
# settings for the computation
10+
options = ASB2008CDC.Options()
11+
options.t_end = 6.0
12+
options.step = 0.02
13+
options.tensor_order = 2
14+
options.taylor_terms = 4
15+
16+
options.u = Zonotope([0], np.diag([0]))
17+
options.u_trans = options.u.c
18+
19+
# settings for the using geometry
20+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
21+
Zonotope.ORDER = 50
22+
23+
z = Interval.identity(2) * 0.1 + 0.2
24+
x0 = cvt2(z, Geometry.TYPE.ZONOTOPE)
25+
xs = boundary(z, 0.3, Geometry.TYPE.ZONOTOPE)
26+
27+
ri_without_bound, rp_without_bound = ASB2008CDC.reach(brusselator, [2, 1], options, x0)
28+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(brusselator, [2, 1], options, xs)
29+
30+
# visualize the results
31+
xlim, ylim = [0, 2], [0, 2.4]
32+
plot_cmp([ri_without_bound, ri_with_bound], [0, 1], cs=["#FF5722", "#303F9F"])

benchmarks/benchmark_brusslator.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import numpy as np
2+
3+
from pybdr.algorithm import ASB2008CDC, ASB2008CDC
4+
from pybdr.util.functional import performance_counter, performance_counter_start
5+
from pybdr.geometry import Zonotope, Interval, Geometry
6+
from pybdr.geometry.operation import boundary
7+
from pybdr.model import *
8+
from pybdr.util.visualization import plot_cmp, plot
9+
# from save_results import save_result
10+
from pybdr.geometry.operation.convert import cvt2
11+
12+
if __name__ == '__main__':
13+
# settings for the computation
14+
options = ASB2008CDC.Options()
15+
options.t_end = 5.0
16+
options.step = 0.01
17+
options.tensor_order = 3
18+
options.taylor_terms = 4
19+
options.u = Zonotope.zero(1, 1)
20+
options.u_trans = np.zeros(1)
21+
22+
# settings for the using geometry
23+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
24+
Zonotope.ORDER = 50
25+
26+
z = Interval([-0.1, 3.9], [0.1, 4.1])
27+
28+
cell_nums = {12: 0.05, 16: 0.06, 20: 0.045}
29+
xs = boundary(z, cell_nums[20], Geometry.TYPE.ZONOTOPE)
30+
31+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(brusselator, [2, 1], options, xs)
32+
33+
# visualize the results
34+
plot(ri_with_bound, [0, 1])
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1-
import matplotlib.pyplot as plt
21
import numpy as np
3-
import sympy
4-
52
from pybdr.algorithm import ASB2008CDC
6-
from pybdr.dynamic_system import NonLinSys
73
from pybdr.geometry import Zonotope, Interval, Geometry
84
from pybdr.geometry.operation import boundary, cvt2
95
from pybdr.model import *
10-
from pybdr.util.visualization import plot, plot_cmp
6+
from pybdr.util.visualization import plot_cmp
117

128
if __name__ == '__main__':
13-
# init dynamic system
14-
system = NonLinSys(Model(jet_engine, [2, 1]))
15-
169
# settings for the computation
1710
options = ASB2008CDC.Options()
1811
options.t_end = 10
@@ -28,14 +21,11 @@
2821
Zonotope.ORDER = 50
2922

3023
z = Interval.identity(2) * 0.2 + 1
24+
x0 = cvt2(z, Geometry.TYPE.ZONOTOPE)
25+
xs = boundary(z, 1, Geometry.TYPE.ZONOTOPE)
3126

32-
# reachable sets computation without boundary analysis
33-
options.r0 = [cvt2(z, Geometry.TYPE.ZONOTOPE)]
34-
ti_whole, tp_whole, _, _ = ASB2008CDC.reach(system, options)
35-
36-
# reachable sets computation with boundary analysis
37-
options.r0 = boundary(z, 1, Geometry.TYPE.ZONOTOPE)
38-
ti_bound, tp_bound, _, _ = ASB2008CDC.reach(system, options)
27+
ri_without_bound, rp_without_bound = ASB2008CDC.reach(jet_engine, [2, 1], options, x0)
28+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(jet_engine, [2, 1], options, xs)
3929

4030
# visualize the results
41-
plot_cmp([tp_whole, tp_bound], [0, 1], cs=["#FF5722", "#303F9F"])
31+
plot_cmp([ri_without_bound, ri_with_bound], [0, 1], cs=["#FF5722", "#303F9F"])

benchmarks/benchmark_lorentz.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import numpy as np
2+
from pybdr.algorithm import ASB2008CDC
3+
from pybdr.geometry import Zonotope, Interval, Geometry
4+
from pybdr.geometry.operation import boundary
5+
from pybdr.model import *
6+
from pybdr.util.visualization import plot
7+
8+
if __name__ == '__main__':
9+
# settings for the computation
10+
options = ASB2008CDC.Options()
11+
options.t_end = 1.0
12+
options.step = 0.02
13+
options.tensor_order = 3
14+
options.taylor_terms = 4
15+
options.u = Zonotope.zero(1, 1)
16+
options.u_trans = np.zeros(1)
17+
18+
# settings for the using geometry
19+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
20+
Zonotope.ORDER = 50
21+
22+
z = Interval([-11, -3, -3], [3, 11, 11])
23+
24+
cell_nums = {216: 2.5, 294: 2.3, 384: 2}
25+
xs = boundary(z, cell_nums[384], Geometry.TYPE.ZONOTOPE)
26+
27+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(lorentz, [3, 1], options, xs)
28+
29+
# visualize the results
30+
# plot(ri_with_bound, [0, 1])

example/benchmark_synchronous_machine_cmp.py renamed to benchmarks/benchmark_lotka_volterra_2d_cmp.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
from pybdr.geometry.operation import boundary, cvt2
99
from pybdr.model import *
1010
from pybdr.util.visualization import plot, plot_cmp
11+
from pybdr.util.functional import performance_counter_start, performance_counter
1112

1213
if __name__ == '__main__':
13-
# init dynamic system
14-
system = NonLinSys(Model(synchronous_machine, [2, 1]))
15-
1614
# settings for the computation
1715
options = ASB2008CDC.Options()
18-
options.t_end = 3
19-
options.step = 0.01
16+
options.t_end = 2.2
17+
options.steps_num = 0.01
2018
options.tensor_order = 3
2119
options.taylor_terms = 4
2220

@@ -27,16 +25,12 @@
2725
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
2826
Zonotope.ORDER = 50
2927

30-
# z = Zonotope([0, 3], np.diag([0.2, 0.2]))
31-
z = Interval([-0.2, 2.8], [0.2, 3.2])
32-
33-
# reachable sets computation without boundary analysis
34-
options.r0 = [cvt2(z, Geometry.TYPE.ZONOTOPE)]
35-
ti_whole, tp_whole, _, _ = ASB2008CDC.reach(system, options)
28+
z = Interval([2.5, 2.5], [3.5, 3.5])
29+
x0 = cvt2(z, Geometry.TYPE.ZONOTOPE)
30+
xs = boundary(z, 1, Geometry.TYPE.ZONOTOPE)
3631

37-
# reachable sets computation with boundary analysis
38-
options.r0 = boundary(z, 1, Geometry.TYPE.ZONOTOPE)
39-
ti_bound, tp_bound, _, _ = ASB2008CDC.reach(system, options)
32+
ri_without_bound, rp_without_bound = ASB2008CDC.reach(lotka_volterra_2d, [2, 1], options, x0)
33+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(lotka_volterra_2d, [2, 1], options, xs)
4034

4135
# visualize the results
42-
plot_cmp([tp_whole, tp_bound], [0, 1], cs=["#FF5722", "#303F9F"])
36+
plot_cmp([ri_without_bound, ri_with_bound], [0, 1], cs=["#FF5722", "#303F9F"])
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
3+
from pybdr.algorithm import ASB2008CDC
4+
from pybdr.geometry import Zonotope, Interval, Geometry
5+
from pybdr.model import *
6+
from pybdr.util.visualization import plot
7+
from pybdr.geometry.operation import boundary
8+
9+
if __name__ == '__main__':
10+
# settings for the computation
11+
options = ASB2008CDC.Options()
12+
options.t_end = 1.0
13+
options.step = 0.02
14+
options.tensor_order = 3
15+
options.taylor_terms = 4
16+
options.u = Zonotope.zero(1, 1)
17+
options.u_trans = np.zeros(1)
18+
19+
# settings for the using geometry
20+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
21+
Zonotope.ORDER = 50
22+
23+
z = Interval([0.0, -2.0], [4.0, 2.0])
24+
25+
cell_nums = {16: 1.1, 20: 1.0, 24: 0.7, 28: 0.6, 32: 0.55}
26+
27+
xs = boundary(z, cell_nums[20], Geometry.TYPE.ZONOTOPE)
28+
29+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(neural_ode_spiral1, [2, 1], options, xs)
30+
31+
# visualize the results
32+
plot(ri_with_bound, [0, 1])
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
3+
from pybdr.algorithm import ASB2008CDC
4+
from pybdr.geometry import Zonotope, Interval, Geometry
5+
from pybdr.model import *
6+
from pybdr.util.visualization import plot
7+
from pybdr.geometry.operation import boundary
8+
9+
if __name__ == '__main__':
10+
# settings for the computation
11+
options = ASB2008CDC.Options()
12+
options.t_end = 7.0
13+
options.step = 0.1
14+
options.tensor_order = 3
15+
options.taylor_terms = 4
16+
options.u = Zonotope.zero(1, 1)
17+
options.u_trans = np.zeros(1)
18+
19+
# settings for the using geometry
20+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
21+
Zonotope.ORDER = 50
22+
23+
z = Interval([-4.0, -4.0], [-2.0, -2.0])
24+
25+
cell_nums = {16: 1.1, 20: 1.0, 24: 0.7, 28: 0.65, 32: 0.52}
26+
27+
xs = boundary(z, cell_nums[32], Geometry.TYPE.ZONOTOPE)
28+
29+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(neural_ode_spiral2, [2, 1], options, xs)
30+
31+
# visualize the results
32+
plot(ri_with_bound, [0, 1])

benchmarks/benchmark_over.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from __future__ import annotations
2+
import numpy as np
3+
4+
from pybdr.geometry import Geometry, Zonotope, Interval
5+
from pybdr.model import vanderpol
6+
from pybdr.algorithm import ASB2008CDC
7+
from pybdr.geometry.operation import boundary, cvt2
8+
from pybdr.util.visualization import plot_cmp
9+
10+
if __name__ == '__main__':
11+
# settings for the computation
12+
options = ASB2008CDC.Options()
13+
options.t_end = 6.74
14+
options.step = 0.01
15+
options.tensor_order = 3
16+
options.taylor_terms = 4
17+
18+
options.u = Zonotope.zero(1, 1)
19+
options.u_trans = np.zeros(1)
20+
21+
# settings for the using geometry
22+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
23+
Zonotope.ORDER = 50
24+
25+
z = Interval([1.23, 2.34], [1.57, 2.46])
26+
x0 = cvt2(z, Geometry.TYPE.ZONOTOPE)
27+
xs = boundary(z, 1, Geometry.TYPE.ZONOTOPE)
28+
29+
ri_without_bound, rp_without_bound = ASB2008CDC.reach(vanderpol, [2, 1], options, x0)
30+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(vanderpol, [2, 1], options, xs)
31+
32+
# visualize the results
33+
plot_cmp([ri_without_bound, ri_with_bound], [0, 1], cs=["#FF5722", "#303F9F"])

0 commit comments

Comments
 (0)