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

Combine ai2 #133

Merged
merged 9 commits into from Jul 29, 2020
Merged

Combine ai2 #133

merged 9 commits into from Jul 29, 2020

Conversation

tomerarnon
Copy link
Collaborator

@SebastianGuadalupe here I try to consolidate the 3 methods of Ai2 into one Ai2{T}

Copy link
Contributor

@SebastianGuadalupe SebastianGuadalupe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

src/reachability/ai2.jl Outdated Show resolved Hide resolved
return overapproximate(Rectification(Ẑ), T)
end


# extend lazysets convex_hull to a vector of polytopes
function LazySets.convex_hull(sets::Vector{<:AbstractPolytope}; backend = CDDLib.Library())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In LazySets there is a function that does this: JuliaReach/LazySets.jl#2215

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. It returns a vector of vertices and we want a Polytope (we could do VPolytope(...) at the end though). Also, in hrep, I think it's more efficient not to go to vrep, no?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that you are doing a convex_hull every loop, while that implementation only does once, so, if there are more than two polytopes, I think that it will be faster even after the conversion, and it will scale much better with more polytopes and dimensions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this could be. I didn't think so since I assumed convex_hull of two polytopes of the same type does not convert, and therefore it should be more efficient. Since the code in LazySets defers to Polyhedra, do you know if this is the case or not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function used is removehredundancy() here, so it does not convert to v-rep.
I did a benchmark with two polygons:

julia> @btime convert(HPolytope, VPolytope(convex_hull(UnionSetArray([$H, $H]))));
  331.000 ns (4620 allocations: 310.05 KiB)
julia> @btime convex_hull($H, $H);
  1.072 ms (14202 allocations: 864.63 KiB)

So it seems to me that the implementation in LazySets is faster even in 2D and two polytopes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Computing Pch in Polyhedra requires vrep I think. The Polyhedra documentation suggests it is only possible in vrep: https://juliapolyhedra.github.io/Polyhedra.jl/latest/utilities/#Polyhedra.convexhull

Therefore your method is better after all (probably much better)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I have recently noticed printouts from the LP solver used by LazySets (or lower in the stack) which were not there in prior package versions. Do you know which issue/s or update/s these new messages are related to? An example is:

julia> convex_hull(UnionSetArray([hp, hp]))
glp_simplex: unable to recover undefined or non-optimal solution
glp_simplex: unable to recover undefined or non-optimal solution
glp_simplex: unable to recover undefined or non-optimal solution
glp_simplex: unable to recover undefined or non-optimal solution
glp_simplex: unable to recover undefined or non-optimal solution
glp_simplex: unable to recover undefined or non-optimal solution
3-element Array{Array{Float64,1},1}:
 [-0.36626701868929534, 1.1382211150524333, -0.6787710912863433]
 [0.36968831822766857, -0.7100424633428055, -0.1920207505884401]
 [-1.9245657296871925, 0.42914282672330284, -0.7531344058289536]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know where they originate but there are issues that mentions it(JuliaReach/LazySets.jl#2278 (comment) and JuliaReach/LazySets.jl#861 (comment))

@tomerarnon
Copy link
Collaborator Author

tomerarnon commented Jul 28, 2020

Hmm... It seems tests are failing due to Box or Ai2z being too overapproximate (returning :violated for :holds). But in your PRs the tests passed just fine. Do you see anywhere where I made a mistake @SebastianGuadalupe?

@SebastianGuadalupe
Copy link
Contributor

Hmm... It seems tests are failing due to Box or Ai2z being too overapproximate (returning :violated for :holds). But in your PRs the tests passed just fine. Do you see anywhere where I made a mistake @SebastianGuadalupe?

I run the test locally and it doesn't seems to be a problem of being too overapproximate, the resulting set does not include the expected result, my guess is that the problem is in the affine map?

@tomerarnon
Copy link
Collaborator Author

my guess is that the problem is in the affine map?

I believe you also used affine_map in Ai2z, no? In the travis tests, that is the first failure case encountered. Very strange indeed!

@tomerarnon
Copy link
Collaborator Author

I think I found the issue... I unwittingly removed definitions for identity activation. I'll check on my end if that's it.

@SebastianGuadalupe
Copy link
Contributor

Yes, that is the error, I just found it too

@SebastianGuadalupe
Copy link
Contributor

Great to see ReachabilityResult always returning a reach set, I wondered why it was not the case, we have applications where it is very useful!

@tomerarnon
Copy link
Collaborator Author

Indeed, I consider that to be a design mistake. I figured I might as well fix it here than in another PR 🤷‍♂️

@tomerarnon tomerarnon merged commit f36efbe into master Jul 29, 2020
@tomerarnon tomerarnon deleted the combine_ai2 branch September 3, 2020 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants