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

rand() #109

Closed
zsunberg opened this issue Aug 18, 2022 · 5 comments · Fixed by #112
Closed

rand() #109

zsunberg opened this issue Aug 18, 2022 · 5 comments · Fixed by #112

Comments

@zsunberg
Copy link
Contributor

zsunberg commented Aug 18, 2022

First of all, thank you, @daanhb and everyone else for making this package - we have been needing something to represent these types of spaces for a while: JuliaPOMDP/POMDPs.jl#301, JuliaReinforcementLearning/CommonRLSpaces.jl#14 (also, it seems quite a challenge to deal with all of the conceptual issues and different use cases people have - I admire your valor in attempting that 😃 )

One thing that we commonly need in our applications is to get a random element of a set, for example rand(ProductDomain(1..2, 3..4)).

Do you think that this package should include rand?

On one hand, this does not make a ton of sense because it is not clear what distribution this should be drawn from (uniform would be a natural choice, but may be hard to implement for some sets), but on the other hand, many other sets without distributions support rand, i.e. (rand(Set([1,2])), rand(1..2)).

If rand does not belong in this package, where should it go?

@daanhb
Copy link
Member

daanhb commented Aug 19, 2022

Hmm, does IntervalSets actually implement rand? I seem to get an error:

julia> using IntervalSets; rand(1..2)
ERROR: ArgumentError: Sampler for this object is not defined

Apart from that, did you have any issues implementing rand? If so perhaps I can help.

Not sure that this package itself is the place though. There is a point_in_domain function to generate exactly one point of a domain, which is mainly used for testing purposes (and is incredibly helpful for that).

@daanhb
Copy link
Member

daanhb commented Aug 19, 2022

First of all, thank you, @daanhb and everyone else for making this package - we have been needing something to represent these types of spaces for a while: JuliaPOMDP/POMDPs.jl#301, JuliaReinforcementLearning/CommonRLSpaces.jl#14 (also, it seems quite a challenge to deal with all of the conceptual issues and different use cases people have - I admire your valor in attempting that 😃 )

Thanks!

@zsunberg
Copy link
Contributor Author

It works for me with IntervalSets 0.7.1

julia> using IntervalSets

julia> rand(1..2)
1.0824522848444758

Apart from that, did you have any issues implementing rand? If so perhaps I can help.

No, it should not be a terrible challenge to implement. It is just a communication/packaging/conceptual issue. If I implement rand(::DomainSets.Rectangle) in package P, and someone else implements it in package Q, things could get confusing if you use both P and Q.

So, the question is where to implement it. Since rand belongs to Base and DomainSets owns the types, it seems like here would be the only safe place. Maybe another package like DomainSetsRandom?

@zsunberg
Copy link
Contributor Author

(to be clear, I'm happy to make a PR for the low hanging fruit cases at least but just want to make sure package maintainers are on board before I jump in)

@daanhb
Copy link
Member

daanhb commented Aug 20, 2022

Well if IntervalSets has it, we are just extending. Why don't you aim for a file like src/applications/rand.jl to get started, thanks for offering.

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 a pull request may close this issue.

2 participants