diff --git a/README.md b/README.md index 5de1403..65161ec 100644 --- a/README.md +++ b/README.md @@ -134,13 +134,121 @@ ti, tp, _, _ = ASB2008CDC.reach(system, options) plot(tp, [0, 1]) ``` -![](doc/imgs/vanderpol_example.png) +| With Boundary Analysis | Without Boundary Analysis | +| :---------------------------------: | :---------------------------------: | +| ![](doc/imgs/vanderpol_example.png) | ![](doc/imgs/vanderpol_example.png) | + ## Computing Reachable Sets based on Boundary Analysis for Neural ODE +An example for computing the reachable sets of neural ODEs with the tool is also provided. Users can refer +to the example files provided and modify the neural network parameters to compute the reachable sets of other neural odes. Moreover, it is also enabled for users to modify the required caluculation parameters to +see the effect of using different settings for calculating reachable sets. + +For example, consider a neural ODE with following parameters and $\textit{sigmoid}$ activation function, also evaluated in 'Manzanas Lopez, D., Musau, P., Hamilton, N. P., & Johnson, T. T. Reachability analysis of a general class of neural ordinary differential equations. In Formal Modeling and Analysis of Timed Systems: 20th International Conference, FORMATS 2022, Warsaw, Poland, September 13–15, 2022, Proceedings (pp. 258-277).': + +$$ + w_1 = \left[ + \begin{align*} + 0.2911133 \quad & 0.12008807\\ + -0.24582624 \quad & 0.23181419\\ + -0.25797904 \quad & 0.21687193\\ + -0.19282854 \quad & -0.2602416 \\ + 0.26780415 \quad & -0.20697702\\ + 0.23462369\quad & 0.2294843 \\ + -0.2583547\quad & 0.21444395\\ + -0.04514714 \quad & 0.29514763\\ + -0.15318371 \quad & -0.275755 \\ + 0.24873598 \quad & 0.21018365 + \end{align*} + \right] +$$ + +$$ + w_2 = \left[ + \begin{align*} + -0.58693904 \quad & -0.814841 & -0.8175157 \quad & 0.97060364 & 0.6908913\\ + -0.92446184 \quad & -0.79249185 & -1.1507587 \quad & 1.2072723 & -0.7983982\\ + 1.1564877 \quad & -0.8991244 & -1.0774536 \quad & -0.6731967 & 1.0154784\\ + 0.8984464 \quad & -1.0766245 & -0.238209 \quad & -0.5233613 & 0.8886671 + \end{align*} + \right] +$$ + +$$ + b_1 = \left[ + \begin{align*} + 0.0038677\quad & -0.00026365 & -0.007168970\quad & 0.02469357 & 0.01338706\\ + 0.00856025\quad & -0.00888401& 0.00516089\quad & -0.00634514 & -0.01914518 + \end{align*} + \right] +$$ + +$$ +b_2 = \left[ + \begin{align*} + -0.04129209 \quad & -0.01508532 + \end{align*} + \right] +$$ + +```python +import numpy as np +np.seterr(divide='ignore',invalid='ignore') +import sys +sys.path.append("./../../") +from pyrat.algorithm import ASB2008CDC +from pyrat.dynamic_system import NonLinSys +from pyrat.geometry import Zonotope, Interval, Geometry +from pyrat.model import * +from pyrat.util.visualization import plot +from pyrat.util.functional.neural_ode_generate import neuralODE +from pyrat.geometry.operation import boundary + + +# init neural ODE +system = NonLinSys(Model(neuralODE, [2,1])) + +# settings for the computation +options = ASB2008CDC.Options() +options.t_end = 1.5 +options.step = 0.01 +options.tensor_order = 2 +options.taylor_terms = 2 +Z = Zonotope([0.5, 0], np.diag([1, 0.5])) + +# Reachable sets computed with boundary analysis +# options.r0 = boundary(Z,1,Geometry.TYPE.ZONOTOPE) + +# Reachable sets computed without boundary analysis +options.r0 = [Z] + + +options.u = Zonotope.zero(1, 1) +options.u_trans = np.zeros(1) + +# settings for the using geometry +Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD +Zonotope.ORDER = 50 + +# reachable sets computation +ti, tp, _, _ = ASB2008CDC.reach(system, options) + +# visualize the results +plot(tp, [0, 1]) +``` +In the following table, we show the reachable computed with boundary analysis and without boundary analysis on different time instance cases. + + +| Time Instance | With Boundary Analysis | Without Boundary Analysis | +| :-----------: | :---------------------------: | :--------------------------: | +| t=0.5s | ![](doc/imgs/Neural_BA05.png) | ![](doc/imgs/Neural_E05.png) | +| t=1.0s | ![](doc/imgs/Neural_BA1.png) | ![](doc/imgs/Neural_E1.png) | +| t=1.5s | ![](doc/imgs/Neural_BA15.png) | __Set Explosion Occured!__ | + ## Frequently Asked Questions and Troubleshooting -### the computation is slow +### The computation is slow - The tool supports two modes of computation for reachable sets, one is to compute the reachable set of evolved states @@ -160,7 +268,7 @@ plot(tp, [0, 1]) reachable states at a suitable time consumption. -### controlling the wrapping effect +### Controlling the wrapping effect +### RuntimeWarning: divide by zero encountered in true_divide + +- This warning may be reported on the paltforms with Windows operating system. It does not affect the running of the tool and it can be eliminiated with the decalration: +```python + numpy.seterr(divide='ignore',invalid='ignore') +``` + > Feel free to contact [dingjianqiang0x@gmail.com](mailto:dingjianqiang0x@gmail.com) if you find any > issues or bugs in this code, or you struggle to run it in any way. diff --git a/doc/imgs/Neural_BA05.png b/doc/imgs/Neural_BA05.png new file mode 100644 index 0000000..160bbe3 Binary files /dev/null and b/doc/imgs/Neural_BA05.png differ diff --git a/doc/imgs/Neural_BA1.png b/doc/imgs/Neural_BA1.png new file mode 100644 index 0000000..37647b5 Binary files /dev/null and b/doc/imgs/Neural_BA1.png differ diff --git a/doc/imgs/Neural_BA15.png b/doc/imgs/Neural_BA15.png new file mode 100644 index 0000000..5f70b5f Binary files /dev/null and b/doc/imgs/Neural_BA15.png differ diff --git a/doc/imgs/Neural_E05.png b/doc/imgs/Neural_E05.png new file mode 100644 index 0000000..c0d39de Binary files /dev/null and b/doc/imgs/Neural_E05.png differ diff --git a/doc/imgs/Neural_E1.png b/doc/imgs/Neural_E1.png new file mode 100644 index 0000000..bbefa90 Binary files /dev/null and b/doc/imgs/Neural_E1.png differ diff --git a/pyrat/__pycache__/__init__.cpython-39.pyc b/pyrat/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..b538699 Binary files /dev/null and b/pyrat/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/algorithm/__pycache__/__init__.cpython-39.pyc b/pyrat/algorithm/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..da6e9f1 Binary files /dev/null and b/pyrat/algorithm/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/algorithm/__pycache__/algorithm.cpython-39.pyc b/pyrat/algorithm/__pycache__/algorithm.cpython-39.pyc new file mode 100644 index 0000000..e57b98e Binary files /dev/null and b/pyrat/algorithm/__pycache__/algorithm.cpython-39.pyc differ diff --git a/pyrat/algorithm/__pycache__/alk2011hscc.cpython-39.pyc b/pyrat/algorithm/__pycache__/alk2011hscc.cpython-39.pyc new file mode 100644 index 0000000..92388f7 Binary files /dev/null and b/pyrat/algorithm/__pycache__/alk2011hscc.cpython-39.pyc differ diff --git a/pyrat/algorithm/__pycache__/althoff2013hscc.cpython-39.pyc b/pyrat/algorithm/__pycache__/althoff2013hscc.cpython-39.pyc new file mode 100644 index 0000000..786e2fe Binary files /dev/null and b/pyrat/algorithm/__pycache__/althoff2013hscc.cpython-39.pyc differ diff --git a/pyrat/algorithm/__pycache__/asb2008cdc.cpython-39.pyc b/pyrat/algorithm/__pycache__/asb2008cdc.cpython-39.pyc new file mode 100644 index 0000000..3a7da59 Binary files /dev/null and b/pyrat/algorithm/__pycache__/asb2008cdc.cpython-39.pyc differ diff --git a/pyrat/algorithm/__pycache__/hscc2005.cpython-39.pyc b/pyrat/algorithm/__pycache__/hscc2005.cpython-39.pyc new file mode 100644 index 0000000..3126f37 Binary files /dev/null and b/pyrat/algorithm/__pycache__/hscc2005.cpython-39.pyc differ diff --git a/pyrat/algorithm/__pycache__/scs2022.cpython-39.pyc b/pyrat/algorithm/__pycache__/scs2022.cpython-39.pyc new file mode 100644 index 0000000..c215bd8 Binary files /dev/null and b/pyrat/algorithm/__pycache__/scs2022.cpython-39.pyc differ diff --git a/pyrat/algorithm/__pycache__/xse2016cav.cpython-39.pyc b/pyrat/algorithm/__pycache__/xse2016cav.cpython-39.pyc new file mode 100644 index 0000000..21b086a Binary files /dev/null and b/pyrat/algorithm/__pycache__/xse2016cav.cpython-39.pyc differ diff --git a/pyrat/dynamic_system/__pycache__/__init__.cpython-39.pyc b/pyrat/dynamic_system/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..345f086 Binary files /dev/null and b/pyrat/dynamic_system/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/dynamic_system/continuous_system/__pycache__/__init__.cpython-39.pyc b/pyrat/dynamic_system/continuous_system/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..493706a Binary files /dev/null and b/pyrat/dynamic_system/continuous_system/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/dynamic_system/continuous_system/__pycache__/linear_system.cpython-39.pyc b/pyrat/dynamic_system/continuous_system/__pycache__/linear_system.cpython-39.pyc new file mode 100644 index 0000000..6d8a14f Binary files /dev/null and b/pyrat/dynamic_system/continuous_system/__pycache__/linear_system.cpython-39.pyc differ diff --git a/pyrat/dynamic_system/continuous_system/__pycache__/nonlinear_system.cpython-39.pyc b/pyrat/dynamic_system/continuous_system/__pycache__/nonlinear_system.cpython-39.pyc new file mode 100644 index 0000000..4a701e5 Binary files /dev/null and b/pyrat/dynamic_system/continuous_system/__pycache__/nonlinear_system.cpython-39.pyc differ diff --git a/pyrat/geometry/__pycache__/__init__.cpython-39.pyc b/pyrat/geometry/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..eb043ca Binary files /dev/null and b/pyrat/geometry/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/geometry/__pycache__/geometry.cpython-39.pyc b/pyrat/geometry/__pycache__/geometry.cpython-39.pyc new file mode 100644 index 0000000..3cd84f3 Binary files /dev/null and b/pyrat/geometry/__pycache__/geometry.cpython-39.pyc differ diff --git a/pyrat/geometry/__pycache__/interval.cpython-39.pyc b/pyrat/geometry/__pycache__/interval.cpython-39.pyc new file mode 100644 index 0000000..7043bca Binary files /dev/null and b/pyrat/geometry/__pycache__/interval.cpython-39.pyc differ diff --git a/pyrat/geometry/__pycache__/polytope.cpython-39.pyc b/pyrat/geometry/__pycache__/polytope.cpython-39.pyc new file mode 100644 index 0000000..bf6ffc0 Binary files /dev/null and b/pyrat/geometry/__pycache__/polytope.cpython-39.pyc differ diff --git a/pyrat/geometry/__pycache__/zonotope.cpython-39.pyc b/pyrat/geometry/__pycache__/zonotope.cpython-39.pyc new file mode 100644 index 0000000..40a65c3 Binary files /dev/null and b/pyrat/geometry/__pycache__/zonotope.cpython-39.pyc differ diff --git a/pyrat/geometry/operation/__pycache__/__init__.cpython-39.pyc b/pyrat/geometry/operation/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..5df8671 Binary files /dev/null and b/pyrat/geometry/operation/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/geometry/operation/__pycache__/boundary.cpython-39.pyc b/pyrat/geometry/operation/__pycache__/boundary.cpython-39.pyc new file mode 100644 index 0000000..d1e9de1 Binary files /dev/null and b/pyrat/geometry/operation/__pycache__/boundary.cpython-39.pyc differ diff --git a/pyrat/geometry/operation/__pycache__/convert.cpython-39.pyc b/pyrat/geometry/operation/__pycache__/convert.cpython-39.pyc new file mode 100644 index 0000000..dc2ca10 Binary files /dev/null and b/pyrat/geometry/operation/__pycache__/convert.cpython-39.pyc differ diff --git a/pyrat/geometry/operation/__pycache__/enclose.cpython-39.pyc b/pyrat/geometry/operation/__pycache__/enclose.cpython-39.pyc new file mode 100644 index 0000000..540a0ca Binary files /dev/null and b/pyrat/geometry/operation/__pycache__/enclose.cpython-39.pyc differ diff --git a/pyrat/geometry/operation/__pycache__/partition.cpython-39.pyc b/pyrat/geometry/operation/__pycache__/partition.cpython-39.pyc new file mode 100644 index 0000000..c060076 Binary files /dev/null and b/pyrat/geometry/operation/__pycache__/partition.cpython-39.pyc differ diff --git a/pyrat/misc/__pycache__/__init__.cpython-39.pyc b/pyrat/misc/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..9148b45 Binary files /dev/null and b/pyrat/misc/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/__init__.cpython-39.pyc b/pyrat/model/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..8f6f9f9 Binary files /dev/null and b/pyrat/model/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/genetic_model.cpython-39.pyc b/pyrat/model/__pycache__/genetic_model.cpython-39.pyc new file mode 100644 index 0000000..f805a7c Binary files /dev/null and b/pyrat/model/__pycache__/genetic_model.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/laubLoomis.cpython-39.pyc b/pyrat/model/__pycache__/laubLoomis.cpython-39.pyc new file mode 100644 index 0000000..1736b2d Binary files /dev/null and b/pyrat/model/__pycache__/laubLoomis.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/ltv.cpython-39.pyc b/pyrat/model/__pycache__/ltv.cpython-39.pyc new file mode 100644 index 0000000..a09acd0 Binary files /dev/null and b/pyrat/model/__pycache__/ltv.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/model.cpython-39.pyc b/pyrat/model/__pycache__/model.cpython-39.pyc new file mode 100644 index 0000000..94a4331 Binary files /dev/null and b/pyrat/model/__pycache__/model.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/p53_small.cpython-39.pyc b/pyrat/model/__pycache__/p53_small.cpython-39.pyc new file mode 100644 index 0000000..aae9dfa Binary files /dev/null and b/pyrat/model/__pycache__/p53_small.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/spiral_non_model.cpython-39.pyc b/pyrat/model/__pycache__/spiral_non_model.cpython-39.pyc new file mode 100644 index 0000000..b3c7b6b Binary files /dev/null and b/pyrat/model/__pycache__/spiral_non_model.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/synchronous_machine.cpython-39.pyc b/pyrat/model/__pycache__/synchronous_machine.cpython-39.pyc new file mode 100644 index 0000000..538b9ac Binary files /dev/null and b/pyrat/model/__pycache__/synchronous_machine.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/tank6Eq.cpython-39.pyc b/pyrat/model/__pycache__/tank6Eq.cpython-39.pyc new file mode 100644 index 0000000..f05bf7d Binary files /dev/null and b/pyrat/model/__pycache__/tank6Eq.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/vanderpol.cpython-39.pyc b/pyrat/model/__pycache__/vanderpol.cpython-39.pyc new file mode 100644 index 0000000..131e841 Binary files /dev/null and b/pyrat/model/__pycache__/vanderpol.cpython-39.pyc differ diff --git a/pyrat/model/__pycache__/vmodelABicycleLinearControlled.cpython-39.pyc b/pyrat/model/__pycache__/vmodelABicycleLinearControlled.cpython-39.pyc new file mode 100644 index 0000000..bb140da Binary files /dev/null and b/pyrat/model/__pycache__/vmodelABicycleLinearControlled.cpython-39.pyc differ diff --git a/pyrat/model/neural_ode/__pycache__/neural_ode_model1.cpython-39.pyc b/pyrat/model/neural_ode/__pycache__/neural_ode_model1.cpython-39.pyc new file mode 100644 index 0000000..28784ca Binary files /dev/null and b/pyrat/model/neural_ode/__pycache__/neural_ode_model1.cpython-39.pyc differ diff --git a/pyrat/model/neural_ode/__pycache__/neural_ode_model2.cpython-39.pyc b/pyrat/model/neural_ode/__pycache__/neural_ode_model2.cpython-39.pyc new file mode 100644 index 0000000..b741cdd Binary files /dev/null and b/pyrat/model/neural_ode/__pycache__/neural_ode_model2.cpython-39.pyc differ diff --git a/pyrat/model/neural_ode/neural_ode_model1.py b/pyrat/model/neural_ode/neural_ode_model1.py new file mode 100644 index 0000000..28e5ef9 --- /dev/null +++ b/pyrat/model/neural_ode/neural_ode_model1.py @@ -0,0 +1,33 @@ + +def get_param(): + + # the weight, bias and activation function list + + w1 = [[0.2911133 , 0.12008807], + [-0.24582624, 0.23181419], + [-0.25797904, 0.21687193], + [-0.19282854, -0.2602416 ], + [ 0.26780415, -0.20697702], + [ 0.23462369, 0.2294843 ], + [ -0.2583547 , 0.21444395], + [ -0.04514714, 0.29514763], + [-0.15318371, -0.275755] , + [ 0.24873598, 0.21018365]] + + b1 = [0.0038677 , -0.00026365, -0.007168970, 0.02469357, 0.01338706, + 0.00856025, -0.00888401, 0.00516089, -0.00634514, -0.01914518] + + w2 = [[-0.58693904, -0.814841 , -0.8175157 , 0.97060364, 0.6908913 , + -0.92446184, -0.79249185, -1.1507587 , 1.2072723 , -0.7983982], + [1.1564877 , -0.8991244 , -1.0774536 , -0.6731967 , 1.0154784 , + 0.8984464 , -1.0766245 , -0.238209 , -0.5233613 , 0.8886671]] + + b2 = [-0.04129209, -0.01508532] + + act1 = "sigmoid" + + weight = [w1, w2] + bias = [b1,b2] + func_list =[act1] + + return weight, bias, func_list \ No newline at end of file diff --git a/pyrat/model/neural_ode/neural_ode_model2.py b/pyrat/model/neural_ode/neural_ode_model2.py new file mode 100644 index 0000000..351d1f2 --- /dev/null +++ b/pyrat/model/neural_ode/neural_ode_model2.py @@ -0,0 +1,30 @@ + +def get_param(): + + # the weight, bias and activation function list + + w1 =[ [-0.32294768,0.59955627], + [0.47014388,-0.39748120], + [-0.56326932,0.33752987], + [0.45147443,0.31528524], + [0.41403031,-0.47271276], + [-0.12952870,-0.62095606], + [-0.41343114,-0.45678866], + [-0.33266136,0.29245856], + [0.50114638,0.39612201], + [0.47665390,0.55137879]] + + b1 = [0.0038923009,0.0037905588,0.0017197595,-0.0033185149,0.0024190384,-0.0013056855,0.0011365928,-0.00042518601,-0.0025141449,0.0010660964] + + w2 = [[-0.50525320,0.34800902,-0.34015974,-0.40054744,0.39193857,0.59363592,0.56743664,-0.33811751,-0.36945280,-0.46805024], + [-0.41715327,0.56257814,-0.56921810,0.60423535,0.53992182,-0.14412111,-0.45906776,-0.35295558,0.49238238,0.43526673]] + + b2 = [-0.0013696412,0.00060380378] + + act1 = "purelin" + + weight = [w1, w2] + bias = [b1,b2] + func_list =[act1] + + return weight, bias, func_list \ No newline at end of file diff --git a/pyrat/util/__pycache__/__init__.cpython-39.pyc b/pyrat/util/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..1af5a42 Binary files /dev/null and b/pyrat/util/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/util/functional/__pycache__/__init__.cpython-39.pyc b/pyrat/util/functional/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..4991f03 Binary files /dev/null and b/pyrat/util/functional/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/util/functional/__pycache__/auxiliary.cpython-39.pyc b/pyrat/util/functional/__pycache__/auxiliary.cpython-39.pyc new file mode 100644 index 0000000..df27bba Binary files /dev/null and b/pyrat/util/functional/__pycache__/auxiliary.cpython-39.pyc differ diff --git a/pyrat/util/functional/__pycache__/csp_solver.cpython-39.pyc b/pyrat/util/functional/__pycache__/csp_solver.cpython-39.pyc new file mode 100644 index 0000000..63923a0 Binary files /dev/null and b/pyrat/util/functional/__pycache__/csp_solver.cpython-39.pyc differ diff --git a/pyrat/util/functional/__pycache__/kd_tree.cpython-39.pyc b/pyrat/util/functional/__pycache__/kd_tree.cpython-39.pyc new file mode 100644 index 0000000..201a97b Binary files /dev/null and b/pyrat/util/functional/__pycache__/kd_tree.cpython-39.pyc differ diff --git a/pyrat/util/functional/__pycache__/neural_ode_generate.cpython-39.pyc b/pyrat/util/functional/__pycache__/neural_ode_generate.cpython-39.pyc new file mode 100644 index 0000000..8bd91ec Binary files /dev/null and b/pyrat/util/functional/__pycache__/neural_ode_generate.cpython-39.pyc differ diff --git a/pyrat/util/functional/__pycache__/solver.cpython-39.pyc b/pyrat/util/functional/__pycache__/solver.cpython-39.pyc new file mode 100644 index 0000000..ee6527d Binary files /dev/null and b/pyrat/util/functional/__pycache__/solver.cpython-39.pyc differ diff --git a/pyrat/util/functional/neural_ode_generate.py b/pyrat/util/functional/neural_ode_generate.py new file mode 100644 index 0000000..563954d --- /dev/null +++ b/pyrat/util/functional/neural_ode_generate.py @@ -0,0 +1,47 @@ +from sympy import * +import sys +sys.path.append("./../../") +import numpy as np +import math +# import model_description as md +import pyrat.model.neural_ode.neural_ode_model1 as md + + +def sigmoid(x): + return (1 / (1 + exp(-x))) + +def purelin(x): + return x + +def neuralODE (x, u): + weight, bias, func_list = md.get_param() + + layer_num = np.shape(bias)[0] + dim = np.shape(weight[0])[1] + + x = Matrix(x) + dxdt = [None] * dim + + for i in range(layer_num): + if (i < layer_num -1): + w = Matrix(weight[i]) + b = Matrix(bias[i]) + act_func = func_list[i] + if act_func == "tanh": + vecF = np.vectorize(tanh) + elif act_func == "sigmoid": + vecF = np.vectorize(sigmoid) + elif act_func == "purelin": + vecF = np.vectorize(purelin) + else: + raise NotImplementedError + if (i == 0): + dxdt = vecF(w*x+b) + else: + dxdt = vecF(w*dxdt+b) + + else: + w = Matrix(weight[i]) + b = Matrix(bias[i]) + dxdt = w*dxdt+b + return dxdt diff --git a/pyrat/util/gui/__pycache__/__init__.cpython-39.pyc b/pyrat/util/gui/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..f41d760 Binary files /dev/null and b/pyrat/util/gui/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/util/gui/__pycache__/callback_manager.cpython-39.pyc b/pyrat/util/gui/__pycache__/callback_manager.cpython-39.pyc new file mode 100644 index 0000000..4044ae2 Binary files /dev/null and b/pyrat/util/gui/__pycache__/callback_manager.cpython-39.pyc differ diff --git a/pyrat/util/gui/__pycache__/geometry_manager.cpython-39.pyc b/pyrat/util/gui/__pycache__/geometry_manager.cpython-39.pyc new file mode 100644 index 0000000..9c5c068 Binary files /dev/null and b/pyrat/util/gui/__pycache__/geometry_manager.cpython-39.pyc differ diff --git a/pyrat/util/gui/__pycache__/ui_settings.cpython-39.pyc b/pyrat/util/gui/__pycache__/ui_settings.cpython-39.pyc new file mode 100644 index 0000000..f4fe0d5 Binary files /dev/null and b/pyrat/util/gui/__pycache__/ui_settings.cpython-39.pyc differ diff --git a/pyrat/util/gui/__pycache__/widget_manager.cpython-39.pyc b/pyrat/util/gui/__pycache__/widget_manager.cpython-39.pyc new file mode 100644 index 0000000..f8b6c07 Binary files /dev/null and b/pyrat/util/gui/__pycache__/widget_manager.cpython-39.pyc differ diff --git a/pyrat/util/gui/__pycache__/window.cpython-39.pyc b/pyrat/util/gui/__pycache__/window.cpython-39.pyc new file mode 100644 index 0000000..7ffa2e8 Binary files /dev/null and b/pyrat/util/gui/__pycache__/window.cpython-39.pyc differ diff --git a/pyrat/util/visualization/__pycache__/__init__.cpython-39.pyc b/pyrat/util/visualization/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..aa51c1b Binary files /dev/null and b/pyrat/util/visualization/__pycache__/__init__.cpython-39.pyc differ diff --git a/pyrat/util/visualization/__pycache__/plot.cpython-39.pyc b/pyrat/util/visualization/__pycache__/plot.cpython-39.pyc new file mode 100644 index 0000000..21db68d Binary files /dev/null and b/pyrat/util/visualization/__pycache__/plot.cpython-39.pyc differ diff --git a/pyrat/util/visualization/__pycache__/vis_2d.cpython-39.pyc b/pyrat/util/visualization/__pycache__/vis_2d.cpython-39.pyc new file mode 100644 index 0000000..892bb94 Binary files /dev/null and b/pyrat/util/visualization/__pycache__/vis_2d.cpython-39.pyc differ diff --git a/pyrat/util/visualization/__pycache__/vis_3d.cpython-39.pyc b/pyrat/util/visualization/__pycache__/vis_3d.cpython-39.pyc new file mode 100644 index 0000000..6c51c3a Binary files /dev/null and b/pyrat/util/visualization/__pycache__/vis_3d.cpython-39.pyc differ diff --git a/test/algorithm/temp_test.py b/test/algorithm/temp_test.py new file mode 100644 index 0000000..3dac297 --- /dev/null +++ b/test/algorithm/temp_test.py @@ -0,0 +1,36 @@ +import numpy as np +np.seterr(divide='ignore',invalid='ignore') +import sys +sys.path.append("./../../") +from pyrat.algorithm import ALTHOFF2013HSCC +from pyrat.dynamic_system import NonLinSys +from pyrat.geometry import Geometry, Zonotope +from pyrat.geometry.operation import cvt2 +from pyrat.model import * +from pyrat.util.visualization import plot + + + +# init dynamic system +system = NonLinSys(Model(vanderpol, [2, 1])) + +# settings for the computation +options = ALTHOFF2013HSCC.Options() +options.t_end = 6.74 +options.step = 0.005 +options.taylor_terms = 4 +options.tensor_order = 3 +options.r0 = [Zonotope([1.4, 2.4], np.diag([0.17, 0.06]))] +options.u = Zonotope.zero(1, 1) +options.u_trans = np.zeros(1) + +# settings for using Zonotope +Zonotope.ORDER = 50 +Zonotope.INTERMEDIATE_ORDER = 50 +Zonotope.ERROR_ORDER = 20 + +# reachable sets +ti, tp, _, _ = ALTHOFF2013HSCC.reach(system, options) + +# visualize the results +plot(tp, [0, 1]) \ No newline at end of file diff --git a/test/algorithm/test_neural_ode.py b/test/algorithm/test_neural_ode.py new file mode 100644 index 0000000..da897fd --- /dev/null +++ b/test/algorithm/test_neural_ode.py @@ -0,0 +1,42 @@ +import numpy as np +np.seterr(divide='ignore',invalid='ignore') +import sys +sys.path.append("./../../") +from pyrat.algorithm import ASB2008CDC +from pyrat.dynamic_system import NonLinSys +from pyrat.geometry import Zonotope, Interval, Geometry +from pyrat.model import * +from pyrat.util.visualization import plot +from pyrat.util.functional.neural_ode_generate import neuralODE +from pyrat.geometry.operation import boundary + +if __name__=="__main__": + # init neural ODE + system = NonLinSys(Model(neuralODE, [2,1])) + + # settings for the computation + options = ASB2008CDC.Options() + options.t_end = 1 + options.step = 0.01 + options.tensor_order = 2 + options.taylor_terms = 2 + Z = Zonotope([0.5, 0], np.diag([0.5, 0.5])) + + # Reachable sets computed with boundary analysis + # options.r0 = boundary(Z,1,Geometry.TYPE.ZONOTOPE) + + # Reachable sets computed without boundary analysis + options.r0 = [Z] + + options.u = Zonotope.zero(1, 1) + options.u_trans = np.zeros(1) + + # settings for the using geometry + Zonotope.REDUCE_METHOD = Zonotope.REDUCE_METHOD.GIRARD + Zonotope.ORDER = 50 + + # reachable sets computation + ti, tp, _, _ = ASB2008CDC.reach(system, options) + + # visualize the results + plot(tp, [0, 1]) \ No newline at end of file