-
Notifications
You must be signed in to change notification settings - Fork 37
Add linear_map
between MatrixZonotope
and SPZ
#3969
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
817e37d
Add linear map between `MatrixZonotope` and `SPZ
alecarraro a3987c2
Apply suggestions from code review
alecarraro 1416b43
add test for overapproximation of MZP map with zonotope
alecarraro b61c8e7
fixed computation of the centre of zonotope overapproximation
alecarraro dba416f
Apply suggestions from code review
alecarraro 9b8469c
change `A` to `Ai` in `overapproximate`
alecarraro 23a473d
change `A` to `Ai` in `linear_map`
alecarraro b64918a
Apply suggestions from code review
alecarraro d33967c
add MZ to validate
alecarraro 11e8ade
remove `validate` macro calls
alecarraro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,82 @@ | ||
""" | ||
linear_map(MZ::MatrixZonotope, P::SparsePolynomialZonotope) | ||
|
||
Compute the linear map of a sparse polynomial zonotope through a matrix zonotope, | ||
following Proposition 1 of [HuangLBS2025](@citet). | ||
|
||
### Input | ||
|
||
- `lm` -- a linear map of a sparse polynomial zonotope through a matrix zonotope | ||
|
||
### Output | ||
|
||
A sparse polynomial zonotope representing the linear map ``MZ ⋅ P```. | ||
|
||
""" | ||
function linear_map(MZ::MatrixZonotope, P::SparsePolynomialZonotope) | ||
if ngens_indep(P) > 0 | ||
error("an exact expression for the linear map is only available for " * | ||
"`SparsePolynomialZonotope`s with no independent generators. " * | ||
"Try using `overapproximate` instead") | ||
end | ||
|
||
@assert size(MZ, 2) == dim(P) "a linear map of size $(size(M)) cannot " * | ||
"be applied to a set of dimension $(dim(X))" | ||
schillic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
T = promote_type(eltype(MZ), eltype(P)) | ||
|
||
n = dim(P) | ||
w = ngens(MZ) | ||
h = ngens_dep(P) | ||
|
||
c = center(MZ) * center(P) | ||
|
||
# compute matrix of dependent generators | ||
G = Matrix{T}(undef, n, h + w + h * w) | ||
G[:, 1:h] = center(MZ) * genmat_dep(P) | ||
@inbounds for (i, A) in enumerate(generators(MZ)) | ||
G[:, h + i] = A * center(P) | ||
G[:, (h + w + (i - 1) * h + 1):(h + w + i * h)] = A * genmat_dep(P) | ||
end | ||
|
||
Gi = Matrix{T}(undef, n, 0) | ||
|
||
# compute exponent | ||
alecarraro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Imat = Matrix{Int}(I, w, w) | ||
Ê₁, Ê₂, idx = merge_id(indexvector(P), indexvector(MZ), expmat(P), Imat) | ||
pₖ = size(Ê₁, 1) | ||
E = Matrix{Int}(undef, pₖ, h + w + h * w) | ||
E[:, 1:h] = Ê₁ | ||
E[:, (h + 1):(h + w)] = Ê₂ | ||
ones_h = ones(Int, 1, h) | ||
@inbounds for l in 1:w | ||
cstart = (h + w) + (l - 1) * h + 1 | ||
cend = (h + w) + l * h | ||
col = @view Ê₂[:, l] | ||
E[:, cstart:cend] = col * ones_h .+ Ê₁ | ||
end | ||
|
||
return SparsePolynomialZonotope(c, G, Gi, E, idx) | ||
end | ||
|
||
""" | ||
linear_map(MZP::MatrixZonotopeProduct, P::SparsePolynomialZonotope) | ||
|
||
Compute the linear map of a sparse polynomial zonotope through a matrix zonotope product | ||
by recursively applying the overapproximation rule from the inside out. | ||
alecarraro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Input | ||
|
||
- `MZ` -- a matrix zonotope product | ||
- `P` -- a sparse polynomial zonotope | ||
|
||
### Output | ||
|
||
A sparse polynomial zonotope representing the linear map ``MZ ⋅ P```. | ||
|
||
alecarraro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
function linear_map(MZP::MatrixZonotopeProduct, P::SparsePolynomialZonotope) | ||
alecarraro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
MZs = factors(MZP) | ||
reduced = foldr((A, acc) -> linear_map(A, acc), MZs; init=P) | ||
return reduced | ||
end |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.