Skip to content

Commit c25a6af

Browse files
committed
update benchmarks and doc
1 parent 722e2b0 commit c25a6af

File tree

8 files changed

+174
-89
lines changed

8 files changed

+174
-89
lines changed

README.md

Lines changed: 63 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -117,45 +117,41 @@ $$
117117

118118
```python
119119
import numpy as np
120-
121-
from pybdr.algorithm import ASB2008CDC
122-
from pybdr.dynamic_system import NonLinSys
120+
from pybdr.algorithm import ASB2008CDC, ASB2008CDC
121+
from pybdr.util.functional import performance_counter, performance_counter_start
123122
from pybdr.geometry import Zonotope, Interval, Geometry
124-
from pybdr.geometry.operation import boundary
123+
from pybdr.geometry.operation import boundary, cvt2
125124
from pybdr.model import *
126125
from pybdr.util.visualization import plot
127126

128-
# init dynamic system
129-
system = NonLinSys(Model(vanderpol, [2, 1]))
130-
131-
# settings for the computation
132-
options = ASB2008CDC.Options()
133-
options.t_end = 6.74
134-
options.step = 0.005
135-
options.tensor_order = 3
136-
options.taylor_terms = 4
137-
options.u = Zonotope.zero(1, 1)
138-
options.u_trans = np.zeros(1)
139-
140-
z = Zonotope([1.4, 2.4], np.diag([0.17, 0.06]))
141-
142-
# -----------------------------------------------------
143-
# computing reachable sets with boundary analysis
144-
options.r0 = boundary(z, 1, Geometry.TYPE.ZONOTOPE)
145-
# -----------------------------------------------------
146-
# computing reachable sets without boundary analysis
147-
# options.r0 = [z]
148-
# -----------------------------------------------------
149-
150-
# settings for the using geometry
151-
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
152-
Zonotope.ORDER = 50
153-
154-
# reachable sets computation
155-
ti, tp, _, _ = ASB2008CDC.reach(system, options)
156-
157-
# visualize the results
158-
plot(tp, [0, 1])
127+
if __name__ == '__main__':
128+
# settings for the computation
129+
options = ASB2008CDC.Options()
130+
options.t_end = 6.74
131+
options.step = 0.005
132+
options.tensor_order = 3
133+
options.taylor_terms = 4
134+
options.u = Zonotope.zero(1, 1)
135+
options.u_trans = np.zeros(1)
136+
137+
# settings for the using geometry
138+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
139+
Zonotope.ORDER = 50
140+
141+
z = Interval([1.23, 2.34], [1.57, 2.46])
142+
x0 = cvt2(z, Geometry.TYPE.ZONOTOPE)
143+
xs = boundary(z, 1, Geometry.TYPE.ZONOTOPE)
144+
145+
this_time = performance_counter_start()
146+
ri_without_bound, rp_without_bound = ASB2008CDC.reach(vanderpol, [2, 1], options, x0)
147+
this_time = performance_counter(this_time, 'reach_without_bound')
148+
149+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(vanderpol, [2, 1], options, xs)
150+
this_time = performance_counter(this_time, 'reach_with_bound')
151+
152+
# visualize the results
153+
plot(ri_without_bound, [0, 1])
154+
plot(ri_with_bound, [0, 1])
159155
```
160156

161157
| With Boundary Analysis (BA) | No Boundary Analysis (NBA) |
@@ -164,16 +160,16 @@ plot(tp, [0, 1])
164160

165161
For large initial sets,
166162

167-
| System | Code | Reachable Sets (Orange-NBA,Blue-BA) |
168-
|:-----------------------------------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------:|
169-
| [synchronous machine](https://github.com/ASAG-ISCAS/PyBDR/blob/master/pyrat/model/synchronous_machine.py) | [benchmark_synchronous_machine_cmp.py](https://github.com/ASAG-ISCAS/PyBDR/blob/master/example/benchmark_synchronous_machine_cmp.py) | ![](doc/imgs/sync_machine_cmp.png) |
170-
| [Lotka Volterra model of 2 variables](https://github.com/ASAG-ISCAS/PyBDR/blob/master/pyrat/model/lotka_volterra_2d.py) | [benchmark_lotka_volterra_2d_cmp.py](https://github.com/ASAG-ISCAS/PyBDR/blob/master/example/benchmark_lotka_volterra_2d_cmp.py) | ![](doc/imgs/lotka_volterra_2d_cmp.png) |
171-
| [Jet engine](https://github.com/ASAG-ISCAS/PyBDR/blob/master/pyrat/model/jet_engine.py) | [benchmark_jet_engine_cmp.py](https://github.com/ASAG-ISCAS/PyBDR/blob/master/example/benchmark_jet_engine_cmp.py) | ![](doc/imgs/jet_engine_cmp.png) |
163+
| System | Code | Reachable Sets (Orange-NBA,Blue-BA) |
164+
|:-----------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------:|
165+
| [synchronous machine](https://github.com/ASAG-ISCAS/PyBDR/blob/master/pyrat/model/synchronous_machine.py) | [benchmark_synchronous_machine_cmp.py](https://github.com/ASAG-ISCAS/PyBDR/blob/master/benchmarks/benchmark_synchronous_machine_cmp.py) | ![](doc/imgs/sync_machine_cmp.png) |
166+
| [Lotka Volterra model of 2 variables](https://github.com/ASAG-ISCAS/PyBDR/blob/master/pyrat/model/lotka_volterra_2d.py) | [benchmark_lotka_volterra_2d_cmp.py](https://github.com/ASAG-ISCAS/PyBDR/blob/master/benchmarks/benchmark_lotka_volterra_2d_cmp.py) | ![](doc/imgs/lotka_volterra_2d_cmp.png) |
167+
| [Jet engine](https://github.com/ASAG-ISCAS/PyBDR/blob/master/pyrat/model/jet_engine.py) | [benchmark_jet_engine_cmp.py](https://github.com/ASAG-ISCAS/PyBDR/blob/master/benchmarks/benchmark_jet_engine_cmp.py) | ![](doc/imgs/jet_engine_cmp.png) |
172168

173169
For large time horizons, i.e. consider
174170
the system [Brusselator](https://github.com/ASAG-ISCAS/PyBDR/blob/master/pyrat/model/brusselator.py)
175171
> For more details about the following example, please refer to
176-
> our [code](https://github.com/ASAG-ISCAS/PyBDR/blob/master/example/benchmark_brusselator_cmp.py).
172+
> our [code](https://github.com/ASAG-ISCAS/PyBDR/blob/master/benchmarks/benchmark_brusselator_cmp.py).
177173
178174
| Time instance | With Boundary Analysis | Without Boundary Analysi |
179175
|:-------------:|---------------------------------------|:--------------------------------------:|
@@ -238,47 +234,43 @@ $$
238234
```python
239235
import numpy as np
240236

241-
np.seterr(divide='ignore', invalid='ignore')
242-
import sys
243-
244-
# sys.path.append("./../../") uncomment this line if you need to add path manually
245237
from pybdr.algorithm import ASB2008CDC
246-
from pybdr.dynamic_system import NonLinSys
247238
from pybdr.geometry import Zonotope, Interval, Geometry
248239
from pybdr.model import *
249-
from pybdr.util.visualization import plot
250-
from pybdr.util.functional.neural_ode_generate import neuralODE
251-
from pybdr.geometry.operation import boundary
240+
from pybdr.util.visualization import plot, plot_cmp
241+
from pybdr.geometry.operation import boundary, cvt2
242+
from pybdr.util.functional import performance_counter_start, performance_counter
252243

253-
# init neural ODE
254-
system = NonLinSys(Model(neuralODE, [2, 1]))
244+
if __name__ == '__main__':
245+
# settings for the computation
246+
options = ASB2008CDC.Options()
247+
options.t_end = 1
248+
options.step = 0.01
249+
options.tensor_order = 2
250+
options.taylor_terms = 2
255251

256-
# settings for the computation
257-
options = ASB2008CDC.Options()
258-
options.t_end = 1.5
259-
options.step = 0.01
260-
options.tensor_order = 2
261-
options.taylor_terms = 2
262-
Z = Zonotope([0.5, 0], np.diag([1, 0.5]))
252+
options.u = Zonotope([0], np.diag([0]))
253+
options.u_trans = options.u.c
263254

264-
# Reachable sets computed with boundary analysis
265-
# options.r0 = boundary(Z,1,Geometry.TYPE.ZONOTOPE)
255+
# settings for the using geometry
256+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
257+
Zonotope.ORDER = 50
266258

267-
# Reachable sets computed without boundary analysis
268-
options.r0 = [Z]
259+
z = Interval([0, -0.5], [1, 0.5])
260+
x0 = cvt2(z, Geometry.TYPE.ZONOTOPE)
261+
xs = boundary(z, 2, Geometry.TYPE.ZONOTOPE)
269262

270-
options.u = Zonotope.zero(1, 1)
271-
options.u_trans = np.zeros(1)
263+
print(len(xs))
272264

273-
# settings for the using geometry
274-
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
275-
Zonotope.ORDER = 50
265+
this_time = performance_counter_start()
266+
ri_without_bound, rp_without_bound = ASB2008CDC.reach(neural_ode_spiral1, [2, 1], options, x0)
267+
this_time = performance_counter(this_time, "reach_without_bound")
276268

277-
# reachable sets computation
278-
ti, tp, _, _ = ASB2008CDC.reach(system, options)
269+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(neural_ode_spiral1, [2, 1], options, xs)
270+
this_time = performance_counter(this_time, "reach_with_bound")
279271

280-
# visualize the results
281-
plot(tp, [0, 1])
272+
# visualize the results
273+
plot_cmp([ri_without_bound, ri_with_bound], [0, 1], cs=["#FF5722", "#303F9F"])
282274
```
283275

284276
In the following table, we show the reachable computed with boundary analysis and without boundary analysis on different

benchmarks/benchmark_boundary_analysis_vs_naive_partition_cmp.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
from pybdr.geometry import Interval, Zonotope, Geometry
33
from pybdr.geometry.operation import cvt2, partition, boundary
44
from pybdr.algorithm import ASB2008CDC
5-
from pybdr.dynamic_system import NonLinSys
65
from pybdr.model import *
7-
from pybdr.util.visualization import plot, plot_cmp
6+
from pybdr.util.visualization import plot_cmp
87
from pybdr.util.functional import performance_counter, performance_counter_start
98

109
if __name__ == '__main__':
@@ -24,35 +23,52 @@
2423

2524
init_set = Interval.identity(2) * 0.5 + 3
2625

27-
time_start = performance_counter_start()
26+
this_time = performance_counter_start()
2827
_, rp_without_bound = ASB2008CDC.reach(lotka_volterra_2d, [2, 1], options, cvt2(init_set, Geometry.TYPE.ZONOTOPE))
28+
this_time = performance_counter(this_time, 'reach_without_bound')
2929

3030
# NAIVE PARTITION
3131
# --------------------------------------------------------
3232
# options.r0 = partition(z, 1, Geometry.TYPE.ZONOTOPE)
33-
# xs = partition(init_set, 1, Geometry.TYPE.ZONOTOPE)
33+
xs_naive_partition_4 = partition(init_set, 1, Geometry.TYPE.ZONOTOPE)
3434
# 4
3535
# ASB2008CDCParallel.reach_parallel cost: 20.126129667s MacOS
3636
# --------------------------------------------------------
37-
# xs = partition(init_set, 0.5, Geometry.TYPE.ZONOTOPE)
37+
xs_naive_partition_9 = partition(init_set, 0.5, Geometry.TYPE.ZONOTOPE)
3838
# 9
3939
# ASB2008CDCParallel.reach_parallel cost: 23.938516459000002s MacOS
4040
# --------------------------------------------------------
41-
# xs = partition(init_set, 0.2, Geometry.TYPE.ZONOTOPE)
41+
xs_naive_partition_36 = partition(init_set, 0.2, Geometry.TYPE.ZONOTOPE)
4242
# 36
4343
# ASB2008CDCParallel.reach_parallel cost: 65.447113125s MacOS
4444
# --------------------------------------------------------
4545

4646
# BOUNDAYR ANALYSIS
4747
# --------------------------------------------------------
48-
xs = boundary(init_set, 1, Geometry.TYPE.ZONOTOPE)
48+
xs_with_bound_8 = boundary(init_set, 1, Geometry.TYPE.ZONOTOPE)
4949
# 8
5050
# ASB2008CDCParallel.reach_parallel cost: 22.185758250000003s MacOS
5151

52-
print(len(xs))
52+
print(len(xs_naive_partition_4))
53+
print(len(xs_naive_partition_9))
54+
print(len(xs_naive_partition_36))
55+
print(len(xs_with_bound_8))
5356

54-
_, rp_with_bound = ASB2008CDC.reach_parallel(lotka_volterra_2d, [2, 1], options, xs)
57+
this_time = performance_counter(this_time, 'partition and boundary')
5558

56-
performance_counter(time_start, "ASB2008CDCParallel.reach_parallel")
59+
_, rp_naive_partition_4 = ASB2008CDC.reach_parallel(lotka_volterra_2d, [2, 1], options, xs_naive_partition_4)
60+
this_time = performance_counter(this_time, 'reach naive partition 4')
5761

58-
plot_cmp([rp_without_bound, rp_with_bound], [0, 1], cs=["#FF5722", "#303F9F"])
62+
_, rp_naive_partition_9 = ASB2008CDC.reach_parallel(lotka_volterra_2d, [2, 1], options, xs_naive_partition_9)
63+
this_time = performance_counter(this_time, 'reach naive partition 9')
64+
65+
_, rp_naive_partition_36 = ASB2008CDC.reach_parallel(lotka_volterra_2d, [2, 1], options, xs_naive_partition_36)
66+
this_time = performance_counter(this_time, 'reach naive partition 36')
67+
68+
_, rp_with_bound_8 = ASB2008CDC.reach_parallel(lotka_volterra_2d, [2, 1], options, xs_with_bound_8)
69+
this_time = performance_counter(this_time, 'reach with bound 8')
70+
71+
plot_cmp([rp_without_bound, rp_naive_partition_4], [0, 1], cs=["#FF5722", "#303F9F"])
72+
plot_cmp([rp_without_bound, rp_naive_partition_9], [0, 1], cs=["#FF5722", "#303F9F"])
73+
plot_cmp([rp_without_bound, rp_naive_partition_36], [0, 1], cs=["#FF5722", "#303F9F"])
74+
plot_cmp([rp_without_bound, rp_with_bound_8], [0, 1], cs=["#FF5722", "#303F9F"])
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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, plot_cmp
7+
from pybdr.geometry.operation import boundary, cvt2
8+
from pybdr.util.functional import performance_counter_start, performance_counter
9+
10+
if __name__ == '__main__':
11+
# settings for the computation
12+
options = ASB2008CDC.Options()
13+
options.t_end = 1
14+
options.step = 0.01
15+
options.tensor_order = 2
16+
options.taylor_terms = 2
17+
18+
options.u = Zonotope([0], np.diag([0]))
19+
options.u_trans = options.u.c
20+
21+
# settings for the using geometry
22+
Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD
23+
Zonotope.ORDER = 50
24+
25+
z = Interval([0, -0.5], [1, 0.5])
26+
x0 = cvt2(z, Geometry.TYPE.ZONOTOPE)
27+
xs = boundary(z, 2, Geometry.TYPE.ZONOTOPE)
28+
29+
print(len(xs))
30+
31+
this_time = performance_counter_start()
32+
ri_without_bound, rp_without_bound = ASB2008CDC.reach(neural_ode_spiral1, [2, 1], options, x0)
33+
this_time = performance_counter(this_time, "reach_without_bound")
34+
35+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(neural_ode_spiral1, [2, 1], options, xs)
36+
this_time = performance_counter(this_time, "reach_with_bound")
37+
38+
# visualize the results
39+
plot_cmp([ri_without_bound, ri_with_bound], [0, 1], cs=["#FF5722", "#303F9F"])
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import numpy as np
2+
from pybdr.algorithm import ASB2008CDC, ASB2008CDC
3+
from pybdr.util.functional import performance_counter, performance_counter_start
4+
from pybdr.geometry import Zonotope, Interval, Geometry
5+
from pybdr.geometry.operation import boundary, cvt2
6+
from pybdr.model import *
7+
from pybdr.util.visualization import plot
8+
9+
if __name__ == '__main__':
10+
# settings for the computation
11+
options = ASB2008CDC.Options()
12+
options.t_end = 6.74
13+
options.step = 0.005
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([1.23, 2.34], [1.57, 2.46])
24+
x0 = cvt2(z, Geometry.TYPE.ZONOTOPE)
25+
xs = boundary(z, 1, Geometry.TYPE.ZONOTOPE)
26+
27+
this_time = performance_counter_start()
28+
ri_without_bound, rp_without_bound = ASB2008CDC.reach(vanderpol, [2, 1], options, x0)
29+
this_time = performance_counter(this_time, 'reach_without_bound')
30+
31+
ri_with_bound, rp_with_bound = ASB2008CDC.reach_parallel(vanderpol, [2, 1], options, xs)
32+
this_time = performance_counter(this_time, 'reach_with_bound')
33+
34+
# visualize the results
35+
plot(ri_without_bound, [0, 1])
36+
plot(ri_with_bound, [0, 1])

pybdr/algorithm/asb2008cdc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def linearize(dyn: Callable, dims, r: Geometry.Base, opt: Options):
5353
a = sys.evaluate((opt.lin_err_x, opt.lin_err_u), "numpy", 1, 0)
5454
b = sys.evaluate((opt.lin_err_x, opt.lin_err_u), "numpy", 1, 1)
5555
assert not (np.any(np.isnan(a))) or np.any(np.isnan(b))
56-
lin_sys = LinSys(xa=a)
56+
lin_sys = LinSys(xa=a, ub=None)
5757
lin_opt = ALK2011HSCC.Options()
5858
lin_opt.step = opt.step
5959
lin_opt.taylor_terms = opt.taylor_terms

pybdr/dynamic_system/continuous_system/linear_system.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66

77

88
class LinSys:
9-
def __init__(self, xa, ub):
9+
def __init__(self, xa, ub=None):
1010
self._xa = np.atleast_2d(xa)
11-
self._ub = np.atleast_2d(ub)
12-
assert self._xa.shape[1] == self._ub.shape[0]
11+
if ub is not None:
12+
self._ub = np.atleast_2d(ub)
13+
assert self._xa.shape[1] == self._ub.shape[0]
14+
else:
15+
self._ub = None
1316

1417
@property
1518
def dim(self):
1619
return self._xa.shape[1]
1720

1821
@property
1922
def type(self):
20-
return 'linear_simple'
23+
return 'linear'
2124

2225
@property
2326
def xa(self):

pybdr/dynamic_system/continuous_system/nonlinear_system.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from __future__ import annotations
2-
import numpy as np
32
from pybdr.model import Model
43

54

pybdr/util/visualization/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __2d_plot(
9595
raise NotImplementedError
9696

9797
ax.autoscale_view()
98-
ax.axis("equal")
98+
# ax.axis("equal")
9999
ax.set_xlabel("x" + str(dims[0]))
100100
ax.set_ylabel("x" + str(dims[1]))
101101

0 commit comments

Comments
 (0)