generated from JuliaReach/JuliaReachTemplatePkg.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
2,605 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Spell Check | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
typos-check: | ||
name: check spelling | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Actions Repository | ||
uses: actions/checkout@v4 | ||
- name: Check spelling | ||
uses: crate-ci/typos@master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,6 @@ docs/site/ | |
.vscode | ||
|
||
Manifest.toml | ||
|
||
*.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[default.extend-words] | ||
# do not correct the following strings: | ||
BA = "BA" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
name = "JuliaReachTemplatePkg" | ||
uuid = "2b714139-d377-45b9-9f15-0355f7430025" | ||
name = "NeuralNetworkReachability" | ||
uuid = "5de1e908-2f08-45bf-a571-ac88a54f7e7f" | ||
version = "0.1.0" | ||
|
||
[deps] | ||
ControllerFormats = "02ac4b2c-022a-44aa-84a5-ea45a5754bcc" | ||
LazySets = "b4f0291d-fe17-52bc-9479-3d1a343d9043" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
ReachabilityBase = "379f33d0-9447-4353-bd03-d664070e549f" | ||
Reexport = "189a3867-3050-52da-a836-e630ba90ab69" | ||
Requires = "ae029012-a4dd-5104-9daa-d747884805df" | ||
|
||
[compat] | ||
julia = "1" | ||
ControllerFormats = "0.2" | ||
LazySets = "2.11.1" | ||
ReachabilityBase = "0.2.1" | ||
Reexport = "0.2, 1" | ||
Requires = "0.5, 1" | ||
julia = "1.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,19 @@ | ||
# JuliaReachTemplatePkg.jl | ||
# NeuralNetworkReachability.jl | ||
|
||
| **Documentation** | **Status** | **Community** | **License** | | ||
|:-----------------:|:----------:|:-------------:|:-----------:| | ||
| [![docs-dev][dev-img]][dev-url] | [![CI][ci-img]][ci-url] [![codecov][cov-img]][cov-url] | [![gitter][chat-img]][chat-url] | [![license][lic-img]][lic-url] | | ||
| [![docs-dev][dev-img]][dev-url] | [![CI][ci-img]][ci-url] [![codecov][cov-img]][cov-url] | [![zulip][chat-img]][chat-url] | [![license][lic-img]][lic-url] | | ||
|
||
[dev-img]: https://img.shields.io/badge/docs-latest-blue.svg | ||
[dev-url]: https://juliareach.github.io/JuliaReachTemplatePkg.jl/dev/ | ||
[ci-img]: https://github.com/JuliaReach/JuliaReachTemplatePkg.jl/workflows/CI/badge.svg | ||
[ci-url]: https://github.com/JuliaReach/JuliaReachTemplatePkg.jl/actions/workflows/ci.yml | ||
[cov-img]: https://codecov.io/github/JuliaReach/JuliaReachTemplatePkg.jl/coverage.svg | ||
[cov-url]: https://app.codecov.io/github/JuliaReach/JuliaReachTemplatePkg.jl | ||
[dev-url]: https://juliareach.github.io/NeuralNetworkReachability.jl/dev/ | ||
[ci-img]: https://github.com/JuliaReach/NeuralNetworkReachability.jl/workflows/CI/badge.svg | ||
[ci-url]: https://github.com/JuliaReach/NeuralNetworkReachability.jl/actions/workflows/ci.yml | ||
[cov-img]: https://codecov.io/github/JuliaReach/NeuralNetworkReachability.jl/coverage.svg | ||
[cov-url]: https://app.codecov.io/github/JuliaReach/NeuralNetworkReachability.jl | ||
[chat-img]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg | ||
[chat-url]: https://julialang.zulipchat.com/#narrow/stream/278609-juliareach | ||
[lic-img]: https://img.shields.io/github/license/mashape/apistatus.svg | ||
[lic-url]: https://github.com/JuliaReach/JuliaReachTemplatePkg.jl/blob/master/LICENSE | ||
[lic-url]: https://github.com/JuliaReach/NeuralNetworkReachability.jl/blob/master/LICENSE | ||
|
||
`JuliaReachTemplatePkg` is a [Julia](http://julialang.org) template package for | ||
the JuliaReach ecosystem. | ||
|
||
## Installing | ||
|
||
This package requires Julia v1.0 or later. | ||
We refer to the [official documentation](https://julialang.org/downloads) on how | ||
to install and run Julia on your system. | ||
|
||
Depending on your needs, choose an appropriate command from the following list | ||
and enter it in Julia's REPL. | ||
To activate the `pkg` mode, type `]` (and to leave it, type `<backspace>`). | ||
|
||
#### [Install the latest release version](https://pkgdocs.julialang.org/v1/managing-packages/#Adding-registered-packages-1) | ||
|
||
```julia | ||
pkg> add JuliaReachTemplatePkg | ||
``` | ||
|
||
#### Install the latest development version | ||
|
||
```julia | ||
pkg> add JuliaReachTemplatePkg#master | ||
``` | ||
|
||
#### [Clone the package for development](https://pkgdocs.julialang.org/v1/managing-packages/#developing) | ||
|
||
```julia | ||
pkg> dev JuliaReachTemplatePkg | ||
``` | ||
`NeuralNetworkReachability.jl` is a [Julia](http://julialang.org) package to symbolically analyze | ||
neural networks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
[deps] | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
|
||
[compat] | ||
Documenter = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
using Documenter, JuliaReachTemplatePkg | ||
using Documenter, NeuralNetworkReachability | ||
|
||
DocMeta.setdocmeta!(JuliaReachTemplatePkg, :DocTestSetup, | ||
:(using JuliaReachTemplatePkg); recursive=true) | ||
DocMeta.setdocmeta!(NeuralNetworkReachability, :DocTestSetup, | ||
:(using NeuralNetworkReachability); recursive=true) | ||
|
||
makedocs(; sitename="JuliaReachTemplatePkg.jl", | ||
modules=[JuliaReachTemplatePkg], | ||
makedocs(; sitename="NeuralNetworkReachability.jl", | ||
modules=[NeuralNetworkReachability], | ||
format=Documenter.HTML(; prettyurls=get(ENV, "CI", nothing) == "true", | ||
assets=["assets/aligned.css"]), | ||
collapselevel=1, assets=["assets/aligned.css"]), | ||
pagesonly=true, | ||
pages=["Home" => "index.md", | ||
"About" => "about.md"], | ||
strict=true) | ||
"Library" => Any["ForwardAlgorithms" => "lib/ForwardAlgorithms.md", | ||
"BackwardAlgorithms" => "lib/BackwardAlgorithms.md", | ||
"BidirectionalAlgorithms" => "lib/BidirectionalAlgorithms.md"], | ||
"About" => "about.md"]) | ||
|
||
deploydocs(; repo="github.com/JuliaReach/JuliaReachTemplatePkg.jl.git", | ||
deploydocs(; repo="github.com/JuliaReach/NeuralNetworkReachability.jl.git", | ||
push_preview=true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
# JuliaReachTemplatePkg.jl | ||
# NeuralNetworkReachability.jl | ||
|
||
`JuliaReachTemplatePkg` is a [Julia](http://julialang.org) template package for | ||
the JuliaReach ecosystem. | ||
|
||
## Library Outline | ||
[NeuralNetworkReachability.jl](http://github.com/JuliaReach/NeuralNetworkReachability.jl) is a | ||
[Julia](http://julialang.org) package for reachability analysis of artificial neural networks. | ||
|
||
```@contents | ||
Pages = [ | ||
] | ||
Depth = 2 | ||
Pages = ["index.md"] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# BackwardAlgorithms | ||
|
||
This section of the manual describes the module for backward algorithms. | ||
|
||
```@contents | ||
Pages = ["BackwardAlgorithms.md"] | ||
Depth = 3 | ||
``` | ||
|
||
```@meta | ||
CurrentModule = NeuralNetworkReachability.BackwardAlgorithms | ||
``` | ||
|
||
```@docs | ||
BackwardAlgorithm | ||
PolyhedraBackward | ||
BoxBackward | ||
PartitioningLeakyReLU | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# BidirectionalAlgorithms | ||
|
||
This section of the manual describes the module for bidirectional algorithms. | ||
|
||
```@contents | ||
Pages = ["BidirectionalAlgorithms.md"] | ||
Depth = 3 | ||
``` | ||
|
||
```@meta | ||
CurrentModule = NeuralNetworkReachability.BidirectionalAlgorithms | ||
``` | ||
|
||
```@docs | ||
BidirectionalAlgorithm | ||
SimpleBidirectional | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# ForwardAlgorithms | ||
|
||
This section of the manual describes the module for forward algorithms. | ||
|
||
```@contents | ||
Pages = ["ForwardAlgorithms.md"] | ||
Depth = 3 | ||
``` | ||
|
||
```@meta | ||
CurrentModule = NeuralNetworkReachability.ForwardAlgorithms | ||
``` | ||
|
||
```@docs | ||
ForwardAlgorithm | ||
DefaultForward | ||
ConcreteForward | ||
LazyForward | ||
BoxForward | ||
SplitForward | ||
DeepZ | ||
Verisig | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
""" | ||
BackwardAlgorithm | ||
Abstract supertype of backward algorithms. | ||
""" | ||
abstract type BackwardAlgorithm end | ||
|
||
remove_constraints(::BackwardAlgorithm, x) = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module BackwardAlgorithms | ||
|
||
using ControllerFormats | ||
using LazySets | ||
using LazySets: affine_map_inverse | ||
using ReachabilityBase.Arrays: SingleEntryVector | ||
using ReachabilityBase.Comparison: _leq | ||
using ReachabilityBase.Iteration: BitvectorIterator | ||
using LinearAlgebra: Diagonal | ||
|
||
export backward, | ||
PolyhedraBackward, | ||
BoxBackward | ||
|
||
include("simplify_sets.jl") | ||
include("PartitioningLeakyReLU.jl") | ||
include("BackwardAlgorithm.jl") | ||
include("backward_default.jl") | ||
include("PolyhedraBackward.jl") | ||
include("BoxBackward.jl") | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
BoxBackward <: BackwardAlgorithm | ||
Backward algorithm that uses a polyhedral approximation with axis-aligned | ||
linear constraints. | ||
""" | ||
struct BoxBackward <: BackwardAlgorithm end | ||
|
||
function backward(Y::LazySet, act::ReLU, ::BoxBackward) | ||
return _backward_box(Y, act) | ||
end | ||
|
||
function backward(Y::UnionSetArray, act::ReLU, ::BoxBackward) | ||
return _backward_box(Y, act) | ||
end | ||
|
||
function _backward_box(Y::LazySet{N}, ::ReLU) where {N} | ||
n = dim(Y) | ||
|
||
# intersect with nonnegative orthant | ||
Q₊ = HPolyhedron([HalfSpace(SingleEntryVector(i, n, -one(N)), zero(N)) for i in 1:n]) | ||
Y₊ = intersection(Y, Q₊) | ||
if isempty(Y₊) # pre-image is empty if image was not nonnegative | ||
return EmptySet{N}(dim(Y)) | ||
end | ||
|
||
constraints = Vector{HalfSpace{N,SingleEntryVector{N}}}() | ||
@inbounds for i in 1:n | ||
e₊ = SingleEntryVector(i, n, one(N)) | ||
upper = ρ(e₊, Y₊) | ||
if upper < N(Inf) | ||
push!(constraints, HalfSpace(e₊, upper)) | ||
end | ||
|
||
e₋ = SingleEntryVector(i, n, -one(N)) | ||
lower = -ρ(e₋, Y₊) | ||
if !_leq(lower, zero(N)) | ||
push!(constraints, HalfSpace(e₋, lower)) | ||
end | ||
end | ||
if isempty(constraints) | ||
return Universe{N}(n) | ||
end | ||
return HPolyhedron(constraints) | ||
end | ||
|
||
for T in (Sigmoid, LeakyReLU) | ||
@eval begin | ||
function backward(Y::AbstractHyperrectangle, act::$T, ::BoxBackward) | ||
l = _inverse(low(Y), act) | ||
h = _inverse(high(Y), act) | ||
return Hyperrectangle(; low=l, high=h) | ||
end | ||
end | ||
end |
Oops, something went wrong.