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

sampling #614

Closed
ga72kud opened this issue Apr 11, 2022 · 2 comments
Closed

sampling #614

ga72kud opened this issue Apr 11, 2022 · 2 comments

Comments

@ga72kud
Copy link

ga72kud commented Apr 11, 2022

How does the sampling work for a LazySet. I used Projections and intersections to process the sets. Is there a method for flowpipes

@schillic schillic transferred this issue from JuliaReach/LazySets.jl Apr 11, 2022
@schillic
Copy link
Member

schillic commented Apr 11, 2022

Flowpipes live in ReachabilityAnalysis (RA). I transferred the issue there. In RA there is no sample method, but you can easily define it. Here is one proposal:

LazySets.sample(fp::ReachabilityAnalysis.ReachSolution, m) = vcat([sample(set(R), m) for R in array(flowpipe(fp))]...)

Example:

using ReachabilityAnalysis, Polyhedra, Plots

# sample model (here: Motor)

using SparseArrays

function motor_homog()
    I = [1, 2, 2, 3, 3, 3, 3, 4, 5, 6, 6, 7, 7, 7, 7, 8]
    J = [2, 3, 2, 1, 2, 3, 4, 1, 6, 7, 6, 5, 6, 7, 8, 5]
    V = [1, 8487.2, -1.0865, -2592.1, -21.119, -698.91, -141399.0, 1.0, 1.0,
         8487.2, -1.0865, -2592.1, -21.119, -698.91, -141399.0, 1.0]
    A = sparse(I, J, V)
    X0 = Hyperrectangle(low=[0.002, 0.0, 0.0, 0.0, 0.001, 0.0, 0.0, 0.0],
                        high=[0.0025, 0.0, 0.0, 0.0, 0.0015, 0.0, 0.0, 0.0])
    return @ivp(x' = Ax, x(0)  X0)
end

P = motor_homog();

# compute the flowpipe

F = solve(P, T=0.02, δ = 1e-3);

# sample 30 elements from each reach set

julia> V = sample(F, 30);

# plot the reach sets and the samples (here I plot dimensions 1 and 2)

julia> plot(F, vars=(1, 2))
julia> plot!([Singleton(p[1:2]) for p in V])

samples

@ga72kud
Copy link
Author

ga72kud commented Apr 12, 2022

@schillic, thank you, this helped. I did not understand all the details of the example. This is what I got:

function sample_flowpipe(fp, m)
	return [LazySets.sample(set(R), m) for R in fp]
end

 sample_flowpipe(𝒫ℛ, 3)

@ga72kud ga72kud closed this as completed Apr 12, 2022
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

No branches or pull requests

2 participants