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

Rectangular linear_map from Zonotope given inverse matrix crashes #2176

Closed
schillic opened this issue Jun 8, 2020 · 2 comments
Closed

Rectangular linear_map from Zonotope given inverse matrix crashes #2176

schillic opened this issue Jun 8, 2020 · 2 comments
Labels
bug 🐛 Something isn't working

Comments

@schillic
Copy link
Member

schillic commented Jun 8, 2020

The original problem in #2169 is not fixed yet (now we get an error, though).

using LazySets, Polyhedra

# dimensions of X and Y
n = 2
m = 4
A = rand(m, n)
B = transpose(A)  # dummy matrix with n rows / m columns (currently required but ignored)

X = rand(BallInf, dim=n)
Y = linear_map(A, X)

julia> Z = linear_map(B, Y, inverse=A)
ERROR: AssertionError: the constraints must have the same normal direction
Stacktrace:
 [1] macro expansion at .julia/dev/LazySets/src/Assertions/Assertions.jl:23 [inlined]
 [2] is_tighter_same_dir_2D(::LazySets.HalfSpace{Float64,Array{Float64,1}}, ::LazySets.HalfSpace{Float64,Array{Float64,1}}; strict::Bool) at .julia/dev/LazySets/src/Sets/HalfSpace.jl:437
 [3] isredundant(::LazySets.HalfSpace{Float64,Array{Float64,1}}, ::LazySets.HalfSpace{Float64,Array{Float64,1}}, ::LazySets.HalfSpace{Float64,Array{Float64,1}}) at .julia/dev/LazySets/src/Interfaces/AbstractHPolygon.jl:312
 [4] addconstraint!(::Array{LazySets.HalfSpace{Float64,Array{Float64,1}},1}, ::LazySets.HalfSpace{Float64,Array{Float64,1}}; linear_search::Bool, prune::Bool) at .julia/dev/LazySets/src/Interfaces/AbstractHPolygon.jl:476
 [5] HPolygon(::Array{LazySets.HalfSpace{Float64,Array{Float64,1}},1}; sort_constraints::Bool, check_boundedness::Bool, prune::Bool) at .julia/dev/LazySets/src/Sets/HPolygon.jl:56
 [6] HPolygon(::Array{LazySets.HalfSpace{Float64,Array{Float64,1}},1}) at .julia/dev/LazySets/src/Sets/HPolygon.jl:52
 [7] _linear_map_hrep_helper(::LinearAlgebra.Transpose{Float64,Array{Float64,2}}, ::Zonotope{Float64,Array{Float64,1},Array{Float64,2}}, ::LazySets.LinearMapInverse{Float64,Array{Float64,2}}) at .julia/dev/LazySets/src/Interfaces/AbstractPolytope.jl:155
 [8] linear_map(::LinearAlgebra.Transpose{Float64,Array{Float64,2}}, ::Zonotope{Float64,Array{Float64,1},Array{Float64,2}}; algorithm::Nothing, check_invertibility::Bool, cond_tol::Float64, inverse::Array{Float64,2}, backend::Nothing, elimination_method::Nothing) at .julia/dev/LazySets/src/Interfaces/AbstractPolyhedron_functions.jl:608
 [9] top-level scope at REPL[23]:1
 [10] eval(::Module, ::Any) at ./boot.jl:331
 [11] eval_user_input(::Any, ::REPL.REPLBackend) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:86
 [12] run_backend(::REPL.REPLBackend) at .julia/packages/Revise/tV8FE/src/Revise.jl:1165
 [13] top-level scope at none:0
@schillic schillic added the bug 🐛 Something isn't working label Jun 8, 2020
@mforets
Copy link
Member

mforets commented Jun 8, 2020

If the map is rectangular with m > n, it can't be invertible (unless you are considering a generalized inverse such a Moore-Penrose pseudoinverse, but that hasn't been considered in linear_map). For these cases one can use the lift algorithm, such as Y = linear_map(A, X, algorithm="lift") in your example. Recall that the fallback just passes X to a zonotope and computes the concrete linear map, btw.

The behavior is like this because if the inverse matrix is given, the "inverse" is applied,

If an inverse matrix is passed in inverse, the given algorithm is applied, and if none is given, either "inverse" or "inverse_right" is applied (in that order of preference)

It is not checked that the matrix is square.. maybe we should make this check and send an error message otherwise.

@schillic
Copy link
Member Author

This is fixed in the current master version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants