-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3574 from JuliaReach/schillic/SSPZ
Update `AbstractPolynomialZonotope` interface functions; add `AbstractSparsePolynomialZonotope` interface
- Loading branch information
Showing
17 changed files
with
204 additions
and
133 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
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
33 changes: 33 additions & 0 deletions
33
docs/src/lib/interfaces/AbstractSparsePolynomialZonotope.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,33 @@ | ||
```@contents | ||
Pages = ["AbstractSparsePolynomialZonotope.md"] | ||
Depth = 3 | ||
``` | ||
|
||
```@meta | ||
CurrentModule = LazySets | ||
``` | ||
|
||
# [Sparse polynomial zonotope sets (AbstractSparsePolynomialZonotope)](@id def_AbstractSparsePolynomialZonotope) | ||
|
||
```@docs | ||
AbstractSparsePolynomialZonotope | ||
``` | ||
|
||
This interface requires to implement the following functions: | ||
|
||
```@docs | ||
expmat(::AbstractSparsePolynomialZonotope) | ||
genmat_dep(::AbstractSparsePolynomialZonotope) | ||
genmat_indep(::AbstractSparsePolynomialZonotope) | ||
``` | ||
|
||
This interface defines the following functions: | ||
|
||
```@docs | ||
nparams(::AbstractSparsePolynomialZonotope) | ||
``` | ||
|
||
## Implementations | ||
|
||
* [Sparse polynomial zonotope (SparsePolynomialZonotope)](@ref def_SparsePolynomialZonotope) | ||
* [Simplified sparse polynomial zonotope (SimpleSparsePolynomialZonotope)](@ref def_SimpleSparsePolynomialZonotope) |
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
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,133 @@ | ||
export AbstractSparsePolynomialZonotope, | ||
expmat, | ||
genmat_dep, genmat_indep, | ||
nparams | ||
|
||
""" | ||
AbstractSparsePolynomialZonotope{N} <: AbstractPolynomialZonotope{N} | ||
Abstract type for sparse polynomial zonotope sets. | ||
### Notes | ||
Every concrete `AbstractSparsePolynomialZonotope` must define the following functions: | ||
- `expmat(::AbstractSparsePolynomialZonotope)` -- return the exponent matrix (sparse PZ only) | ||
- `genmat_dep(::AbstractSparsePolynomialZonotope)` -- return the matrix of dependent generators | ||
- `genmat_indep(::AbstractSparsePolynomialZonotope)` -- return the matrix of independent generators | ||
The subtypes of `AbstractSparsePolynomialZonotope` (including abstract interfaces): | ||
```jldoctest; setup = :(using LazySets: subtypes) | ||
julia> subtypes(AbstractSparsePolynomialZonotope) | ||
2-element Vector{Any}: | ||
SimpleSparsePolynomialZonotope | ||
SparsePolynomialZonotope | ||
``` | ||
""" | ||
abstract type AbstractSparsePolynomialZonotope{N} <: AbstractPolynomialZonotope{N} end | ||
|
||
""" | ||
expmat(P::AbstractSparsePolynomialZonotope) | ||
Return the matrix of exponents of a sparse polynomial zonotope. | ||
### Input | ||
- `P` -- sparse polynomial zonotope | ||
### Output | ||
The matrix of exponents, where each column is a multidegree. | ||
### Notes | ||
In the exponent matrix, each row corresponds to a parameter (``αₖ`` in the | ||
definition) and each column corresponds to a monomial. | ||
""" | ||
function expmat(::AbstractSparsePolynomialZonotope) end | ||
|
||
""" | ||
genmat_dep(P::AbstractSparsePolynomialZonotope) | ||
Return the matrix of dependent generators of a sparse polynomial zonotope. | ||
### Input | ||
- `P` -- sparse polynomial zonotope | ||
### Output | ||
The matrix of dependent generators. | ||
""" | ||
function genmat_dep(::AbstractSparsePolynomialZonotope) end | ||
|
||
""" | ||
genmat_indep(P::AbstractSparsePolynomialZonotope) | ||
Return the matrix of independent generators of a sparse polynomial zonotope. | ||
### Input | ||
- `P` -- sparse polynomial zonotope | ||
### Output | ||
The matrix of independent generators. | ||
""" | ||
function genmat_indep(::AbstractSparsePolynomialZonotope) end | ||
|
||
function ngens_dep(P::AbstractSparsePolynomialZonotope) | ||
return size(genmat_dep(P), 2) | ||
end | ||
|
||
function ngens_indep(P::AbstractSparsePolynomialZonotope) | ||
return size(genmat_indep(P), 2) | ||
end | ||
|
||
""" | ||
nparams(P::AbstractSparsePolynomialZonotope) | ||
Return the number of dependent parameters in the polynomial representation of a | ||
sparse polynomial zonotope. | ||
### Input | ||
- `P` -- sparse polynomial zonotope | ||
### Output | ||
The number of dependent parameters in the polynomial representation. | ||
### Notes | ||
This number corresponds to the number of rows in the exponent matrix. | ||
""" | ||
function nparams(P::AbstractSparsePolynomialZonotope) | ||
return size(expmat(P), 1) | ||
end | ||
|
||
function _remove_redundant_generators_polyzono(c, G, E) | ||
Gnew = Matrix{eltype(G)}(undef, size(G, 1), 0) | ||
Enew = Matrix{eltype(E)}(undef, size(E, 1), 0) | ||
cnew = copy(c) | ||
|
||
visited_exps = Dict{Vector{Int},Int}() | ||
@inbounds for (gi, ei) in zip(eachcol(G), eachcol(E)) | ||
all(isapproxzero, gi) && continue | ||
if iszero(ei) | ||
cnew += gi | ||
elseif haskey(visited_exps, ei) # repeated exponent | ||
idx = visited_exps[ei] | ||
Gnew[:, idx] += gi | ||
else | ||
Gnew = hcat(Gnew, gi) | ||
Enew = hcat(Enew, ei) | ||
visited_exps[ei] = size(Enew, 2) | ||
end | ||
end | ||
|
||
return cnew, Gnew, Enew | ||
end |
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
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 @@ | ||
genmat_dep(P::SSPZ) = P.G |
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 @@ | ||
genmat_indep(P::SSPZ{N}) where {N} = Matrix{N}(undef, dim(P), 0) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
ngens_indep(::SSPZ) = 0 |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.