Skip to content

Examples

JKoeln edited this page Jun 14, 2024 · 9 revisions

Neural Networks

The exampleReluNN.m example demonstrates how a trained ReLu Neural Network (NN) can be represented as a hybrid zonotope. Given the weights and biases for a NN trained to approximate the function $f(x_1,x_2) = cos(x_1) + sin(x_2)$, a hybrid zonotope is created using reluNN. Since this NN has 2 inputs and 1 output, the resulting hybrid zonotope has 3 dimensions, with the first two corresponding to the inputs and the third corresponding to the output. In addition to these 2 inputs and 1 output, there are 3 hidden layers with widths of 20, 10, and 10 neurons. This results in a total of 40 neurons, which corresponds to the number of binary factors in the resulting hybrid zonotope. This zonotope also has 162 continuous factors and 120 constraints. Of the 240 $\approx$ 1012 possible combinations of these 40 binary factors, only 980 of these combinations result in a non-empty set (which can be computed using the getLeaves function.

hybrid zonotope

Model Predictive Control

The exampleDoubleIntegrator.m example demonstrates how the explicit feedback control policy for Model Predictive Control (MPC) can be represented as a hybrid zonotope. For a double-integrator system with 2 states, 1 input, state and input constraints, LQR-based terminal constraint, and a prediction horizon of 5 steps, the resulting hybrid zonotope has 80 continuous factors, 18 binary factors, and 60 constraints. A key step in generating this hybrid zonotope is determining bounds on the dual variables of the MPC optimization problem. Computing these bounds is computationally expensive and is a limiting factor in the scalability of this approach. If estimates of these bounds are known, these estimates can be provided to avoid this computational expense. However, if the provided bounds are too small, the resulting hybrid zonotope may not accurately reflect the feasible domain of the original MPC problem. Once these bounds are known, the construction of the hybrid zonotope is performed in mpQPMap using purely algebraic methods including Cartesian productions, halfspace intersections, and projections.

hybrid zonotope

Hybrid System Reachability

The exampleTwoEquilibrium.m example demonstrates how hybrid zonotopes can be used to compute the reachable sets for a discrete-time Piece-Wise Affine (PWA) system using two different approaches. The first approach converts the PWA system into a Mixed Logical Dynamical (MLD) system (using HYSDEL) and then uses the stepMLD function to compute the reachable sets. The second approach uses the notion of state-update sets, where the PWA dynamics mapping the states at time step $k$ to time step $k+1$ are represented as a hybrid zonotope, which is then used to forward propagate the reachable sets. While both approaches have merits, with application-dependent tradeoffs, the PWA approach is more direct, and does not require using HYSDEL, but results in a set-representation complexity that is slightly higher than that using the MLD approach for this equilibrium example.

hybrid zonotope

Nonlinear Reachability

The exampleNonlinear.m demonstrates how nonlinear functions, and systems with nonlinear dynamics, can be outer-approximated to conduct closed-loop reachability analysis. In this example, a discrete-time system with 2 states and 1 input is considered, where the dynamics are nonlinear due to a $sin(x)$ function. The nonlinear system is in closed-loop with a saturated Linear Quadratic Regulator (LQR) control law. The nonlinear $sin(x)$ function is bounded with a hybrid zonotope, which is then used to generate a hybrid zonotope for the open-loop state-update set for the dynamic system. When combined with a hybrid zonotope representation of the LQR controller, the closed-loop reachable sets are computed. These reachable sets provide outer-approximations of the reachable sets for the original nonlinear system.

hybrid zonotope

Note that this example takes roughly 25 minutes to run, but 99% of this time is spent plotting the 15 reachable sets due to the large number of non-empty leaves. All other calculations are performed in around 15 seconds.

Clone this wiki locally