Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update linear map for polynomial zonotopes #3036

Merged
merged 4 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/lib/sets/SimpleSparsePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dim(::SimpleSparsePolynomialZonotope)
ngens(::SimpleSparsePolynomialZonotope)
nparams(::SimpleSparsePolynomialZonotope)
order(::SimpleSparsePolynomialZonotope)
linear_map(::AbstractMatrix, ::SimpleSparsePolynomialZonotope)
linear_map(::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, ::SimpleSparsePolynomialZonotope)
minkowski_sum(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
cartesian_product(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
linear_combination(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib/sets/SparsePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ ngens_dep(::SparsePolynomialZonotope)
ngens_indep(::SparsePolynomialZonotope)
nparams(::SparsePolynomialZonotope)
order(::SparsePolynomialZonotope)
linear_map(::AbstractMatrix, ::SparsePolynomialZonotope)
linear_map(::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, ::SparsePolynomialZonotope)
exact_sum(::SparsePolynomialZonotope, ::SparsePolynomialZonotope)
```
4 changes: 2 additions & 2 deletions src/Sets/SimpleSparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ julia> expmat(S)
expmat(P::SSPZ) = P.E

"""
linear_map(M::AbstractMatrix, P::SimpleSparsePolynomialZonotope)
linear_map(M::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, P::SimpleSparsePolynomialZonotope)

Apply the linear map `M` to the simple sparse polynomial zonotope `P`.

Expand All @@ -203,7 +203,7 @@ Apply the linear map `M` to the simple sparse polynomial zonotope `P`.

The set resulting from applying the linear map `M` to `P`.
"""
function linear_map(M::AbstractMatrix, P::SSPZ)
function linear_map(M::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, P::SSPZ)
return SimpleSparsePolynomialZonotope(M * center(P), M * genmat(P), expmat(P))
end

Expand Down
5 changes: 2 additions & 3 deletions src/Sets/SparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ Returns a collection of n unique identifiers (intergers 1, …, n).
"""
uniqueID(n::Int) = 1:n
"""
linear_map(M::AbstractMatrix, P::SparsePolynomialZonotope)
linear_map(M::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, P::SparsePolynomialZonotope)

Apply the linear map `M` to the sparse polynomial zonotope `P`.

Expand All @@ -221,7 +221,7 @@ Apply the linear map `M` to the sparse polynomial zonotope `P`.

The set resulting from applying the linear map `M` to `P`.
"""
function linear_map(M::AbstractMatrix, P::SPZ)
function linear_map(M::Union{Real, AbstractMatrix, LinearAlgebra.UniformScaling}, P::SPZ)
return SparsePolynomialZonotope(M * center(P),
M * genmat_dep(P),
M * genmat_indep(P),
Expand All @@ -230,7 +230,6 @@ function linear_map(M::AbstractMatrix, P::SPZ)
)
end


"""
rand(::Type{SparsePolynomialZonotope};
[N]::Type{<:Real}=Float64, [dim]::Int=2, [nparams]::Int=2, [maxdeg]::Int=3,
Expand Down
5 changes: 5 additions & 0 deletions test/Sets/SimpleSparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ for N in [Float64, Float32, Rational{Int}]
@test genmat(LMS) == [5.0 6.0;11.0 14.0]
@test expmat(LMS) == expmat(S)

LMS2 = linear_map(0.5, S)
@test center(LMS2) == [1.0, 0.0]
@test genmat(LMS2) == [0.5 1;1 1]
@test expmat(LMS2) == expmat(LMS2)

MSS = minkowski_sum(S, S)
@test center(MSS) == [4.0, 0.0]
@test genmat(MSS) == [1 2 1 2;2 2 2 2.]
Expand Down
8 changes: 8 additions & 0 deletions test/Sets/SparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ for N in [Float64, Float32, Rational{Int}]
@test nparams(PZ) == 2
@test order(PZ) == 2//1


LM = linear_map(0.5, PZ)
@test center(LM) == [2, 2]
@test genmat_dep(LM) == [1 0.5 1;0 1 1]
@test genmat_indep(LM) == hcat([0.5, 0.0])
@test expmat(LM) == expmat(PZ)

M = N[-0.5 0.2;-0.1 0.6]
PZ2 = SparsePolynomialZonotope(zeros(N, 2), N[2 0 1;1 2 1], zeros(N, 2, 0), [1 0 1;0 1 3])
LMPZ = linear_map(M, PZ2)
Expand All @@ -30,6 +37,7 @@ for N in [Float64, Float32, Rational{Int}]
@test expmat(LMPZ) == [1 0 1;0 1 3]
@test indexvector(LMPZ) == indexvector(PZ)


ESPZ = PZ ⊞ PZ2
@test center(ESPZ) == [4, 4]
@test genmat_dep(ESPZ) == [2 1 2 2 0 1;0 2 2 1 2 1]
Expand Down