A safety property is essentially an input-output relationship for the model we want to verify. In general, the constraints for the input set $\mathcal{X}$ and the output set $\mathcal{Y}$ can have any geometry. For the sake of simplicity, ModelVerification.jl uses convex polytopes and the complement of a polytope to encode the input and output specifications. Specifically, our implementation utilizes the geometric definitions of LazySets, a Julia package for calculus with convex sets. The following section dives into the geometric representations ModelVerification.jl uses and the representations required for each solver.
Different solvers implemented in ModelVerification.jl require the input-output specification formulated with particular geometries. We report here a brief overview of the sets we use. For specifics, please read Algorithms for Verifying Deep Neural Networks by C. Liu, et al. and Sets in LazySets.jl
.
- HR =
Hyperrectangle
- HS =
HalfSpace
- HP =
HPolytope
- SS =
StarSet
- IS =
ImageStar
- ZT =
Zonotope
- PC =
PolytopeComplement
- CH =
ConvexHull
Solver | Input set | Output |
---|
Ai2 | ZT,SS,HP,HR | ReachabilityResult , CounterExampleResult |
CROWN | ZT,SS,HP,HR,CH | BasicResult |
$\alpha$-CROWN | ZT,SS,HP,HR,CH | BasicResult |
$\beta$-CROWN | ZT,SS,HP,HR,CH | BasicResult |
$\alpha$-$\beta$-CROWN | ZT,SS,HP,HR,CH | BasicResult |
ImageZono | CH | ReachabilityResult , CounterExampleResult |
ImageStar | CH | ReachabilityResult , CounterExampleResult |
Corresponds to a high-dimensional rectangle, defined by
\[|x-c| \le r,\]
where $c\in\mathbb{R}^{k_0}$ is the center of the hyperrectangle and $r\in\mathbb{R}^{k_0}$ is the radius of the hyperrectangle.
Represented by a single linear inequality constraint
\[a^\top x \le b,\]
where $a\in\mathbb{R}^{k_0}$ and $b\in\mathbb{R}$.
HPolytope
uses a set of linear inequality constraints to represent a convex polytope, i.e., it is a bounded set defined using an intersection of half-spaces.
\[Ax \le b,\]
where $A\in\mathbb{R}^{k\times k_0}, b\in\mathbb{R}^k$ with $k$ representing the number of inequality constraints.
Only convex star set is considered in this toolbox. A convex star set is an affine transformation of an arbitrary convex polytope,
\[x = c + \begin{bmatrix} r_1 & r_2 & \cdots & r_l \end{bmatrix} \alpha,\; C\alpha \le d,\]
where $c\in\mathbb{R}^{k_0}$ is the center of the star set, $r_i\in\mathbb{R}^{k_0},\; i\in\{1,\dots,l\}$ are generators of the star set, $C\in\mathbb{R}^{k\times l}$, $d\in\mathbb{R}^{k}$, $\alpha\in\mathbb{R}^l$ is the free parameter that belongs to a unit hypercube, and $k$ is the number of inequality constraints on $\alpha$. $l$ is the degree of freedom of the star set.
The general starset, on the left, is not necessarily convex. We only consider convex starsets.
Zonotope
is basically as star set in which all predicate variables are in the range of $[-1, 1]$. Zonotope represents polytopes that can be written as affine transformations of a unit hypercube, defined as
\[x = c + \begin{bmatrix} r_1 & r_2 & \cdots & r_l \end{bmatrix} \alpha,\; |\alpha| \le 1,\]
where $c\in\mathbb{R}^{k_0}$ is the center of the zonotope, $r_i\in\mathbb{R}^{k_0},\; i\in\{1,\dots,l\}$ are generators of the zonotope, and $\alpha\in\mathbb{R}^l$ is the free parameter that belongs to a unit hypercube. $l$ is the degree of freedom of the zonotope.
ImageStar
is an extension of the star set where the center and generators are images with multiple channels.
\[x = c + \begin{bmatrix} r_1 & r_2 & \cdots & r_l \end{bmatrix} \alpha,\; C\alpha \le d,\]
where $c\in\mathbb{R}^{h\times w \times k_0}$ is the center image, $r_i\in\mathbb{R}^{h \times w \times k_0},\; i\in\{1,\dots,l\}$ are the generator iamges, $C\in\mathbb{R}^{k\times l}$, $d\in\mathbb{R}^{k}$, and $h,w,k$ are the height, width, and number of channels (input dimension) of the images respectively. $\alpha\in\mathbb{R}^l$ is the free parameter that belongs to a unit hypercube, and $k$ is the number of inequality constraints on $\alpha$. $l$ is the degree of freedom of the star set.
ImageZono
is an extension of the zonotope where the center and generators are images with multiple channels.
\[x = c + \begin{bmatrix} r_1 & r_2 & \cdots & r_l \end{bmatrix} \alpha\]
where $c\in\mathbb{R}^{h\times w \times k_0}$ is the center image, $r_i\in\mathbb{R}^{h \times w \times k_0},\; i\in\{1,\dots,l\}$ are the generator iamges, and $h,w,k$ are the height, width, and number of channels (input dimension) of the images respectively. $\alpha\in\mathbb{R}^l$ is the free parameter that belongs to a unit hypercube and $l$ is the degree of freedom of the zonotope.
PolytopeComplement
is a type that represents the complement of a polytope, that is the set
\[Y = X^c = \{ y\in\mathbb{R}^n : y \notin X \}.\]
[1] C. Liu, T. Arnon, C. Lazarus, C. Strong, C. Barret, and M. J. Kochenderfer, "Algorithms for Verifying Deep Neural Networks," in Foundations and Trends in Optimization, 2021.
[2] T. Gehr, M. Mirman, D. Drashsler-Cohen, P. Tsankov, S. Chaudhuri, and M. Vechev, "Ai2: Safety and Robustness Certification of Neural Networks with Abstract Interpretation," in 2018 IEEE Symposium on Security and Privacy (SP), 2018.
[3] M. Forets and C. Schilling, "LazySets.jl: Scalable Symbolic-Numeric Set Computations," in Proceeds of the JuliaCon Conferences, 2021.
[4] HD. Tran, S. Bak, W. Xiang, and T.T. Johnson, "Verification of Deep Convolutional Neural Networks Using ImageStars," in Computer Aided Verification (CAV), 2020.
Spec
Abstract super-type for input-output specifications.
sourceInputSpec
Input specification can be of any type supported by LazySet
or ImageConvexHull
.
sourceOutputSpec
Output specification can be of any type supported by LazySet
or LinearSpec
.
sourceThe following are structures for specifications and construction functions for specifications.
LinearSpec <: Spec
Safety specification defined as the set $\{ x: x = A x - b ≤ 0 \}$.
Fields
A
(AbstractArray{FloatType[], 3}
): Normal dierction of size spec_dim x out_dim x batch_size
.b
(AbstractArray{FloatType[], 2}
): Constraints of size spec_dim x batch_size
.is_complement
(Bool
): Boolean flag for whether this specification is a complement or not.
sourceget_linear_spec(batch_out_set::AbstractVector)
Retrieves the linear specifications of the batch of output sets and returns a LinearSpec
structure.
Arguments
batch_out_set
(AbstractVector
): Batch of output sets.
Returns
LinearSpec
of the batch of output sets.
sourceReLUConstraints
A mutable structure for storing information related to the constraints of a ReLU (Rectified Linear Unit) activation function in a neural network.
Fields
idx_list
: A list of indices. val_list
: A list of values corresponding to the indices in idx_list
. not_splitted_mask
: A mask indicating which elements in idx_list
and val_list
have not been split. This is used in the context of a piecewise linear approximation of the ReLU function, where the input space is split into regions where the function is linear.history_split
: A record of the splits that have been performed.
sourceReLUConstrainedDomain <: Spec
A mutable structure for storing specifications related to the ReLU (Rectified Linear Unit) activation function in a neural network.
Fields
domain
: A geometric specification representing the domain of the ReLU function.all_relu_cons
: A dictionary of ReLU constraints for each node in the network.
sourceImageConvexHull <: Spec
Convex hull for images used to specify safety property for images. It is the smallest convex polytope that contains all the images given in the imgs
array.
Fields
imgs
(AbstractArray
): List of images in AbstractArray
. Image is represented as a matrix of height x weight x channels.
sourceImageLinfBall
A mutable structure for storing information related to the constraints of a L-infinity ball for images.
Fields
lb
: Lower bound of the ball.ub
: Upper bound of the ball.
sourceMissing docstring for get_image_linf_spec
. Check Documenter's build log for details.
classification_spec(n::Int64, target::Int64)
Generates an output specification constructed with a convex polyhedron, HPolyhedron
, for classification tasks. Given n
-number of labels with target
as the correct label, the resulting polyhedron is the finite intersection of halfspaces:
$P = \bigcap_{i=1}^n H_i$
where $H_i = \{x : a_i^T x \leq 0 \}, \; i\in\{1:n\}$ is a halfspace, $a_i$ is a row vector where the n
-th element is 1.0, the target
-th element is -1.0, and the rest are 0's.
Arguments
n
(Int64
): Number of labels.target
(Int64
): Target label.
Returns
HPolyhedron
specified as above such that the output specification captures the target label.
sourceThe following are helper functions for retrieving information the specification structures.
get_size(input_spec::LazySet)
Given a LazySet
, it determines the size of the set.
sourceget_size(input_spec::ImageConvexHull)
Given an ImageConvexHull
, it determines the size of the image.
sourceget_shape(input::ImageConvexHull)
Returns the shape of the given ImageConvexHull
input set.
Arguments
input
(ImageConvexHull
): Input set.
Returns
shape
(Tuple
): Shape of the input set. The last dimension is always the number of the images. The first dimensions are the shape of the image. For example, if the input set is consisted of 10 images of size 128 x 128, then the shape is (128, 128, 10)
.
sourceget_shape(input::Hyperrectangle)
Returns the shape of the given Hyperrectangle
input set.
Arguments
input
(Hyperrectangle
): Input set.
Returns
shape
(Tuple
): Shape of the hyperrectangle. The last dimension is always - For example, if the input set is a 2D hyperrectangle, then the shape is
(2, 1)
.
sourceThe following are helper functions for modifying (scaling) the specification structures.
scale_set(set::Hyperrectangle, ratio)
Scale the hyperrectangle set by the given ratio. The center of the set is not changed, but the radius is scaled by the ratio.
Arguments
set
(Hyperrectangle
): The set to be scaled.ratio
(Real
): The ratio to scale the set by.
Returns
- The scaled
Hyperrectangle
set.
sourcescale_set(set::ImageConvexHull, ratio)
Scale the image convex hull set by the given ratio. The first image is not changed, but the rest of the images are scaled by the ratio. The first image is not changed because it acts as the "center" of the set.
Arguments
set
(ImageConvexHull
): The set to be scaled.ratio
(Real
): The ratio to scale the set by.
Returns
- The scaled
ImageConvexHull
set.
source