-
Notifications
You must be signed in to change notification settings - Fork 33
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
Added Base.length
for EmptySet
and SingleTon
#3388
Conversation
For context, the Julia standard library defines julia> length([])
0 and for "singletons" julia> length(123)
1 |
initially i didn't make sense of but there is a well defined notion of |
My intuition for Another note is that, if |
not sure why are we testing in such an old version, i suggest to just test in the latest julia stable release |
this is in a weird state -- one approval (me) but some questioning by @schillic let's have another round of discussion on our next dev call (friday 3rd) -- details on https://hackmd.io/@juliareach/dev for anyone who's keen to join @mossr it's delightful to know that you're using this library in a textbook project! say hi to Mykel for me 👋 |
@mossr: To move forward, could you explain your use case and in particular why you chose |
Of course. We are implementing coverage metrics for a validation textbook and in the implementation of star discrepancy (eqs. (3-4) of Dang et al., pg. 193 [1]) we need the number of points of using LazySets
function star_discrepancy(points, a, b, lengths)
points_norm = [(point .- a) ./ (b .- a) for point in points]
P = UnionSetArray(Singleton.(points_norm))
ranges = [range(0, 1, length)[1:end-1] for length in lengths]
steps = [Float64(r.step) for r in ranges]
ℬ = Hyperrectangle(low=zeros(length(a)), high=ones(length(a)))
lbs = []
ubs = []
for grid_point in Iterators.product(ranges...)
b⁻ = Hyperrectangle(low=zeros(length(a)), high=[grid_point...])
b⁺ = Hyperrectangle(low=zeros(length(a)), high=grid_point .+ steps)
Pb⁻, Pb⁺ = length(intersection(P, b⁻)), length(intersection(P, b⁺)) # <-- use of length here
push!(lbs, max(abs(Pb⁻ / length(points) - volume(b⁻) / volume(ℬ)),
abs(Pb⁺ / length(points) - volume(b⁺) / volume(ℬ))))
push!(ubs, max(Pb⁺ / length(points) - volume(b⁻) / volume(ℬ),
volume(b⁺) / volume(ℬ) - Pb⁻ / length(points)))
end
return maximum(lbs), maximum(ubs)
end [1] Dang, Thao, and Tarik Nahhal. "Coverage-guided test generation for continuous and hybrid systems." Formal Methods in System Design 34 (2009): 183-213. |
Okay, I understand now, thanks. The implementation of
LazySets.jl/src/ConcreteOperations/intersection.jl Lines 848 to 867 in 97c91fc
Since you are only interested in the number of nonempty intersections, your proposal is one way to deal with these special cases. However, I still do not think that Since you just have singletons, I actually find it cleaner if you avoid the set view and operate on the element level. Here are three proposals, in the order of suggestion:
Pb⁻ = length(filter(p -> p ∈ b⁻, P))
Pb⁻ = length(filter(∈(b⁻), P)) # alternative syntax
Pb⁻ = length(filter(p -> p ⊆ b⁻, P))
Pb⁻ = filter(!isempty, intersection.(array(P), Ref(b⁻))) Would that be okay? (Side note: You do not have to recompute |
Closing as stale. |
We're using LazySets in our new textbook with Mykel Kochenderfer and would like to use
length
onEmptySet
andSingleton
. It is already defined forAbstractArraySet
and the code for the other two types is straightforward.