Replacing Function with Leaky ReLU in Barrier Function Design: A Union of Invariant Sets Approach for ReLU-Based Dynamical Systems
Abstract
In this paper, a systematic framework is presented for determining piecewise affine () barrier functions and their corresponding invariant sets for dynamical systems identified via Rectified Linear Unit (ReLU) neural networks or their equivalent representations. A common approach to determining the invariant set is to use Nagumo’s condition, or to utilize the barrier function with a class- function. It may be challenging to find a suitable class- function in some cases. We propose leaky ReLU as an efficient substitute to the complex nonlinear function in our formulation. Moreover, we propose the Union of Invariant Sets (UIS) method, which combines information from multiple invariant sets in order to compute the largest possible invariant set. The proposed framework is validated through multiple examples, showcasing its potential to enhance the analysis of invariant sets in ReLU-based dynamical systems. Our code is available at: https://github.com/PouyaSamanipour/UIS.git.
I Introduction
The Rectified Linear Unit (ReLU) neural network (NN) is capable of identifying complex system dynamics, and ReLU-based neural networks have been successfully applied as NN-controllers for a variety of challenging control applications such as robot manipulation, autonomous driving [1, 2]. In spite of their effectiveness, standard NN training lacks the safety and convergence guarantees provided by classical control methods. Moreover, ReLU-based controllers are inherently sensitive to small input perturbations, which can lead to unexpected and potentially unsafe behavior [3]. These limitations highlight the need for computational tools to ensure safety and reliability for ReLU NNs, particularly for applications in safety-critical domains [4, 5, 6].
Barrier functions (BFs) are a widely used approach for automatically guaranteeing safety in dynamical systems [7]. As safety filters in control systems, control barrier functions(CBF) are commonly used, but their effectiveness depends heavily on their robustness to model uncertainties [8]. The challenge of dynamical model uncertainty has been addressed by various sampling-based methods such as supervised learning, reinforcement learning (RL), and integration of CBFs in order to establish forward invariance sets and ensure the safety of uncertain systems [9, 10]. Despite their success, in most applications it may be difficult to verify the learned safe set [5].
The piecewise affine () nature of ReLU neural networks enables their representation as functions [11]. The computation of invariant sets for both continuous and discrete-time dynamical systems has been extensively investigated in the literature, with significant contributions addressing constrained systems and their invariant properties [12, 13]. In [14], we introduced a method to estimate invariant sets and construct BFs for dynamical systems. The BF found depends on the choice of the function, , which is restricted to be a linear function in [14]. Furthermore, their approach relies on trying different linear coefficients and selecting the one that provides the largest possible invariant set. While trying various linear to obtain the largest possible set of invariants might be computationally inexpensive in lower dimensions, it might prove to be computationally demanding in higher-dimensional systems.
In the present work, we address the challenge of selecting an appropriate function for barrier-based safety analysis. We propose using a Leaky ReLU function instead of a complex or highly nonlinear function for . This choice offers two key benefits: simplicity in form and a seamless path towards incorporating the non-smooth BF framework described in [15]. The non-smooth BF [15] utilizes multiple valid BFs to construct a new candidate BF; the validity of this combined BF depends on the existence of an appropriate that satisfies essential safety conditions for these multiple BFs simultaneously. No method to find such is provided. By using the Leaky ReLU function as , we are able to find such an , so that our combined barrier function is valid. Building on this insight, we introduce a new method, the Union of Invariant Sets (UIS). The UIS method combines several BFs derived from various linear functions for ReLU-based dynamical systems into a single BF. This integration may expand the overall invariant set while preserving safety guarantees and incurring no additional computational cost compared to [14].
II Preliminaries
To begin, we briefly introduce the necessary notations and provide an overview of piecewise affine functions.
Notation
Let be a set. The set of indices corresponding to the elements of is denoted by . The convex hull, interior, and boundary are denoted by , , respectively. For a matrix , denotes its transpose. As part of this paper, we present a definition of dynamical systems on a partition. Consequently, the partition is defined as follows:
Definition 1
Throughout this paper, the partition is a collection of subsets , where each represents a closed subset of for all . In the partition , and for .
The other concept we need is the refinement of a partition. In mathematical terms, given two partitions and of a set , we say that is a refinement of if implies .
Furthermore, we use to denote the dimension of a cell , where .
II-A Piecewise Affine Functions
A piecewise affine function, denoted by , is represented via an explicit parameterization based on a partition . Each region in the partition corresponds to a set of affine dynamics, described by a collection of matrices and vectors . The function is defined as follows:
(1) |
where the region (cell) is described by
(2) |
with matrices and vectors , defining the boundary hyperplanes of . Here, denotes the number of hyperplanes in cell .
Assumption 1
In this work, we assume that all partition cells are bounded polytopes. Consequently, the vertex representation of the dynamics is valid. Specifically, each cell in the partition can be represented as the convex hull of its set of vertices, , as follows:
(3) |
III Invariant Set Estimation
To describe the invariant set estimation algorithm, we must first define the concept of the set of invariance.
III-A Forward Invariance
To explain the concepts of forward invariant, consider the following nonlinear dynamics:
(4) |
Consider as locally Lipschitz continuous within the domain . Based on this assumption, for any initial condition , there is a time interval within which a unique solution to (4) exists, fulfilling the differential equation (4) and the initial condition [16].
Definition 2 (Forward invariant set [16])
Let us define a super-level set corresponding to a continuously differentiable function for the closed-loop system given by equation (4) as follows:
(5) |
where set is considered forward-invariant if the solution remains in for all for every .
Definition 3 (Barrier function [16])
Let represent the superlevel set of a continuously differentiable function . It is said that is a BF if there exists an extended class function in which:
(6) |
where lie derivative of along the closed loop dynamics is denoted by . Equation (6) makes set an asymptotically set in .
A key challenge in finding the BF using (6) is choosing the function . A method for selecting will be discussed in the following section.
III-B Leaky ReLU: A practical choice for in BF design
Definition 3 shows that if there exists an satisfies constraint (6), then is a BF, and remains forward invariant and asymptotically stable in . Finding a suitable nonlinear is often challenging and computationally expensive because it often involves searching through a large function space. It is common practice to simplify the analysis using a linear , [14]. However, this methodology may impose limitations on the search for a larger invariant set.
To address these limitations, we propose a Leaky ReLU function as a practical and flexible substitute. Unlike approaches that rely on complex functions or trial-and-error selection of linear , the Leaky ReLU function provides an efficient alternative with only a few tunable parameters, enabling more effective barrier function construction for dynamics (4).
Theorem 1
Let represent the super-level set, as defined in Equation (5), of a continuously differentiable function with respect to the closed-loop dynamic (4). If is a bounded function such that for , then the followings are equivalent:
-
(a)
There exists an extended class function such that the barrier constraint (6) is satisfied, rendering invariant (i.e., is a valid BF).
-
(b)
There exists an extended class function with constants , where is a Leaky ReLU function defined as
(7) such that condition (6) is satisfied,rendering invariant (i.e., is a valid BF).
Proof:
The Leaky ReLU function in (7) is continuous, strictly increasing, and satisfies . Thus, if (b) holds, it immediately implies (a).
Now, suppose (a) is true. Since is bounded on with , and is continuous, the composition is also bounded.
Case 1: . Because and remain finite, the ratio is bounded above. Hence, there exists such that
(8) |
Adding to both sides of (8) and using , we obtain
(9) |
Case 2: . Similarly, is bounded below. Thus there exists such that
(10) |
Again, adding to both sides of (10) yields
(11) |
From these two cases, we see that we can define as described in (7). Therefore, if (a) holds, (b) must also hold. This completes the proof. ∎
Theorem 1 provides insight into how BFs can be constructed by tuning a Leaky ReLU with two parameters rather than looking for a complex function. For less conservative behavior, could be set to a large value and to a small value. The boundedness of imposes no restrictions if is a compact set.
III-C barrier function
The main goal of this paper is to estimate the invariant set for the dynamical systems identified using ReLU NN or its equivalent dynamical systems as follows:
(12) |
where the function is defined on a pre-selected domain . In [14], we proposed an approach to estimate the invariant set for dynamical systems (12) with linear . However, using linear might be challenging. Before discussing how leaky ReLU can address this challenge, it is necessary to take a look at our work [14].
Our work in [14] consists of parameterizing the BF as a function on the same partition as the dynamical systems (12). The BF for the cell can be parameterized as follows:
(13) |
where and . is a continuous and differentiable function within the interior of the cell.
Assumption 2
In [14], we constructed an optimization problem to search for a invariant set over the domain . To describe the optimization problem, we must first establish useful index sets. Since our algorithm depends on the partition, we denote all these sets as functions of the partition. We define the index set as follows:
(15) |
where represents the indices of cells that have a non-empty intersection with the boundary of the . To determine whether a vertex belongs to the or the , we introduce the following sets:
(16) | ||||
Here, and are sets of ordered pairs where the first element corresponds to the cell index , and the second element corresponds to the vertex index . Specifically, identifies the vertices on the boundary of and their associated cells, while identifies the vertices in the interior of the domain partition and their associated cells.
We constructed a linear optimization in [14] as follows to find a certified invariant set with where .
(17a) | |||
Subject to: | |||
(17b) | |||
(17c) | |||
(17d) | |||
(17e) | |||
(17f) |
where . In (17a), and denote the number of elements in and , respectively. Constraint (17b) ensures that vertices in are excluded from the invariant set, while constraint (17c) guides the search algorithm to include all points in .
These constraints, (17b) and (17c), are relaxed, as some vertices in may not be contained within the invariant set, or the search algorithm may encounter feasibility issues for a given partition. Following the parametrization, constraint (17d) is derived from the general constraint (6). The feasibility of this optimization problem is analyzed in [14]. For further details, please refer to [14].
Remark 1
We must note that the optimization problem (17) is always feasible, however, its solution might not be a certified invariant set. In case the in the optimization problem (17), the current partition does not justify a certified invariant set since certain constraints on the boundary cells, (17b), have not been met. In order to resolve this issue, all boundary cells where the slack variable is non-zero must be refined. Refinement should also be considered for interior cells with non-zero slack variables, . In this work, we utilized the vector field refinement approach presented in [17].
In [14], we employed a bisection method to obtain a set of parameters each yielding an associated invariant set. We then retained only the invariant set corresponding to the parameter that resulted in the largest invariant set, discarding all other sets obtained from the remaining parameters. Although this strategy was effective it is not computationally efficient.
As described earlier, Leaky ReLUs may address the challenge of using linear in [14]. However, due to the constraint (17d), the resulting formulation requires mixed-integer programming, which results in high computational costs. Another potential solution is to take advantage of the concept of non-smooth BFs developed in [15], where multiple invariant sets can be merged. The primary challenge in [15] is determining a suitable that simultaneously satisfies all the necessary barrier-function conditions, which can be difficult in practice. In the next step, we will describe a new algorithm for estimating the invariant set for dynamical systems (12).
III-D Union of Invariant Sets(UIS)
This section addresses the challenge of finding suitable by integrating non-smooth BF with leaky ReLU . This combination aims to produce a possibly larger invariant set compared to [14] without any additional computational cost. To demonstrate how non-smooth BFs can be used with the Leaky ReLU , we must first modify our notation.
As mentioned earlier, the solution to the optimization problem (17) depends on both and . Henceforth, we will use the notation and to reflect this dependency. The rest of the paper assumes in unless otherwise stated.
Lemma 1
Consider the dynamical system given by (12) with an equilibrium at the origin, defined on a compact set . Let be a set of parameters ordered in ascending order. Suppose that the corresponding invariant sets, obtained through the optimization problem (17) are denoted by for with . Then, the following results hold:
-
1.
There exists an invariant set with respect to the dynamical system (12), where is given by:
(18) -
2.
The set is rendered asymptotically stable in with the following BF and class- function:
(19) where is defined as:
(20) and denotes the Leaky ReLU function as defined in (7). The partition is the product partition defined as:
(21) where:
Proof:
The first part of the proof can be proved using the contradiction. Assume, for contradiction, that there exists an initial condition such that the trajectory of the system leaves at some future time.
By definition of , for any , there exists such that . Since is invariant by definition, any initial condition implies that the trajectory will remain within for all future time steps.
However, this contradicts our assumption that the trajectory leaves . Therefore, for any , the trajectory of the system will always remain within one of the sets , which are invariant by construction.
To prove the second part, note that is a continuous BF, since all for are continuous and . To make the definition of this new BF compatible with (1), we defined to ensure that in each cell, we have only one affine function for .
To prove that the candidate BF is valid, we first need to show that for and for . By definition of the in (19), we know
(22) |
Moreover, by definition of , for any , there exists such that and as a result . Therefore, with respect to (22), and due to the existence of for all , we can conclude that for . Due to brevity, the proof of for is eliminated.
Now, we need to prove that condition (6) holds for with respect to the dynamical system (12) for . According to Theorem 1, if the condition in (6) holds for with an arbitrary , then can be substituted with a Leaky ReLU function. Give that, let us assume . Let us consider such that is differentiable with respect to . To prove by contradiction, suppose equation (6) does not hold for . By the definition of in (19), for , where can be any value . Due to the fact that (6) holds for for , we can conclude that:
(23) |
Also, the following holds because and for :
(24) |
With respect to the assumption that is a differentiable point we can conclude that and by adding it to both sides of inequality (24):
(25) | ||||
which is a contradiction to the assumption that (6) does not hold for for . As a result, we can conclude for all the differentiable points in the ,
The same reasoning can be applied to points outside the invariant set . For differentiable points, such as , outside the invariant set, where , let us assume, for contradiction, that (6) does not hold. Since , we have , where and . Therefore,
Adding to both sides of this inequality, we maintain the validity of (23). Thus,
(26) |
which contradicts our assumption. This allows us to conclude that equation (6) holds for points outside the invariant set.
The non-smooth BFs for differential inclusion are discussed in detail in [15]. Proposition 2 in [15] demonstrates that (19) is valid for non-differentiable points. For the sake of brevity, we will skip this part.
Consequently, is a certified barrier function for the system described by (12). ∎
Remark 2
Lemma 1 indicates that when multiple valid BFs exist, they can be combined to form a single BF using (19). It is shown here for , but this approach can also be applied to more general nonlinear dynamics on compact sets, as described in (4), even though those broader applications are beyond the scope of this work.
Building on Lemma 1, we introduce the Union of Invariant Sets (UIS) method for constructing invariant sets. Instead of identifying a single Leaky ReLU function that maximizes the invariant set, UIS forms a unified invariant set by taking the union of multiple invariant sets, each obtained by solving (17) with a distinct linear . This may result in a broader coverage of the state space while maintaining all interior points. The final invariant set is characterized by the barrier function (19) and a Leaky ReLU , integrating information from various valid BFs with linear functions systematically. The complete procedure is detailed in Algorithm 1.
Corollary 1
Proof:
The result follows directly from the construction of the UIS algorithm. ∎
As a result of Corollary 1, it is important to note that UIS does not guarantee a larger forward invariant set in all cases; for instance, solutions such as in Figure 1 do not contribute any new points to the UIS algorithm. However, in comparison to the previous approach proposed in [14], this method offers the advantage of incurring no additional computational expense, while simultaneously allowing for the determination of a potentially larger invariant set.
IV Results and Simulations
All computations are implemented using Python 3.11 and on a computer with a 2.1 GHz processor and 8 GB RAM. A tolerance of is used to determine if a number is nonzero. Moreover, the examples employ a tolerance of .
Example 1 (Inverted Pendulum [14])
The inverted pendulum system can be modeled as follows:
where represents the pendulum’s angle, and is its angular velocity. The control input , defined as , is constrained by a saturation limit between the lower bound of and the upper bound of . The system’s domain, , is given by , where represents the infinity norm. We utilize a ReLU neural network with a single hidden layer with eight neurons to approximate the right-hand side of the dynamics. The UIS estimates the invariant set with . The results are shown in Fig 2. The invariant set obtained with UIS is larger than the invariant set obtained with a linear as can be seen in Fig 2.
Example 2 (Barrier Certificate Verification)
Consider the following continuous system from [18]:
defined over the state space . The objective is to ensure that any trajectory that originates in the set never enters the unsafe region .
The dynamic is identified using a ReLU NN with 20 neurons. UIS, as described in Algorithm 1, utilized to obtain a new invariant set, and the results compared with [18]. In Fig 3, UIS has a larger invariant set than one linear , and it is also comparable to the SyntheBC approach as described in [18].
V Conclusion
This paper presents a systematic method for deriving BFs and their corresponding invariant sets for dynamical systems identified using ReLU NNs or their equivalent dynamical systems. A key innovation of this method is the introduction of the leaky ReLU function as a simplified substitute to the complex function typically used in BF formulations. As an extension of our previous work, we propose a novel approach, the Union of Invariant Sets (UIS), which takes advantage of all information obtained from previous methods to compute the largest possible invariant set. The efficacy of the UIS framework has been demonstrated through a number of nontrivial examples.



References
- [1] J. Tan, T. Zhang, E. Coumans, A. Iscen, Y. Bai, D. Hafner, S. Bohez, and V. Vanhoucke, “Sim-to-real: Learning agile locomotion for quadruped robots,” arXiv preprint arXiv:1804.10332, 2018.
- [2] N. Rober, S. M. Katz, C. Sidrane, E. Yel, M. Everett, M. J. Kochenderfer, and J. P. How, “Backward reachability analysis of neural feedback loops: Techniques for linear and nonlinear systems,” IEEE Open Journal of Control Systems, vol. 2, pp. 108–124, 2023.
- [3] X. Yuan, P. He, Q. Zhu, and X. Li, “Adversarial examples: Attacks and defenses for deep learning,” IEEE transactions on neural networks and learning systems, vol. 30, no. 9, pp. 2805–2824, 2019.
- [4] Y.-C. Chang, N. Roohi, and S. Gao, “Neural lyapunov control,” Advances in neural information processing systems, vol. 32, 2019.
- [5] H. Dai, B. Landry, L. Yang, M. Pavone, and R. Tedrake, “Lyapunov-stable neural-network control,” arXiv preprint arXiv:2109.14152, 2021.
- [6] C. Dawson, Z. Qin, S. Gao, and C. Fan, “Safe nonlinear control using robust neural lyapunov-barrier functions,” in Conference on Robot Learning, pp. 1724–1735, PMLR, 2022.
- [7] A. D. Ames, J. W. Grizzle, and P. Tabuada, “Control barrier function based quadratic programs with application to adaptive cruise control,” in 53rd IEEE Conference on Decision and Control, pp. 6271–6278, IEEE, 2014.
- [8] V. Hamdipoor, N. Meskin, and C. G. Cassandras, “Safe control synthesis using environmentally robust control barrier functions,” European Journal of Control, vol. 74, p. 100840, 2023. 2023 European Control Conference Special Issue.
- [9] Z. Marvi and B. Kiumarsi, “Safe reinforcement learning: A control barrier function optimization approach,” International Journal of Robust and Nonlinear Control, vol. 31, no. 6, pp. 1923–1940, 2021.
- [10] A. Taylor, A. Singletary, Y. Yue, and A. Ames, “Learning for safety-critical control with control barrier functions,” in Learning for Dynamics and Control, pp. 708–717, PMLR, 2020.
- [11] P. Samanipour and H. A. Poonawala, “Stability analysis and controller synthesis using single-hidden-layer relu neural networks,” IEEE Transactions on Automatic Control, pp. 1–12, 2023.
- [12] F. Blanchini and S. Miani, “Constrained stabilization of continuous-time linear systems,” Systems & control letters, vol. 28, no. 2, pp. 95–102, 1996.
- [13] S. Raković, E. Kerrigan, K. Kouramas, and D. Mayne, Invariant approximations of robustly positively invariant sets for constrained linear discrete-time systems subject to bounded disturbances. University of Cambridge, Department of Engineering Cambridge, 2004.
- [14] P. Samanipour and H. Poonawala, “Invariant set estimation for piecewise affine dynamical systems using piecewise affine barrier function,” European Journal of Control, p. 101115, 2024.
- [15] P. Glotfelter, J. Cortés, and M. Egerstedt, “Nonsmooth barrier functions with applications to multi-robot systems,” IEEE control systems letters, vol. 1, no. 2, pp. 310–315, 2017.
- [16] A. D. Ames, S. Coogan, M. Egerstedt, G. Notomista, K. Sreenath, and P. Tabuada, “Control barrier functions: Theory and applications,” in 2019 18th European control conference (ECC), pp. 3420–3431, IEEE, 2019.
- [17] P. Samanipour and H. A. Poonawala, “Automated stability analysis of piecewise affine dynamics using vertices,” in 2023 59th Annual Allerton Conference on Communication, Control, and Computing (Allerton), pp. 1–8, 2023.
- [18] Q. Zhao, X. Chen, Y. Zhang, M. Sha, Z. Yang, W. Lin, E. Tang, Q. Chen, and X. Li, “Synthesizing relu neural networks with two hidden layers as barrier certificates for hybrid systems,” in Proceedings of the 24th International Conference on Hybrid Systems: Computation and Control, pp. 1–11, 2021.