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

added ImplicitDistribution #37

Merged
merged 3 commits into from
Jun 22, 2020
Merged

added ImplicitDistribution #37

merged 3 commits into from
Jun 22, 2020

Conversation

zsunberg
Copy link
Member

added ImplicitDistribution

@zsunberg
Copy link
Member Author

zsunberg commented Jun 11, 2020

One question is should we also add an @implicit_distribution macro for syntactic sugar?

@implicit_distribution (s, a, rng)->s + a + randn(rng)

that expands to

ImplicitDistribution(s, a) do s, a, rng
    s + a + randn(rng)
end

@zsunberg
Copy link
Member Author

This allows JuliaPOMDP/POMDPs.jl#269 to work

@coveralls
Copy link

coveralls commented Jun 11, 2020

Pull Request Test Coverage Report for Build 176

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 80.568%

Totals Coverage Status
Change from base Build 170: 0.1%
Covered Lines: 369
Relevant Lines: 458

💛 - Coveralls

@zsunberg zsunberg changed the title added docs added ImplicitDistribution Jun 11, 2020
@zsunberg
Copy link
Member Author

(I just requested the reviews to make sure everyone thinks this is a good idea - I don't expect any detailed feedback or anything)

@lassepe
Copy link
Member

lassepe commented Jun 11, 2020

I'll have a loot at this tomorrow.

Copy link
Member

@rejuvyesh rejuvyesh left a comment

Choose a reason for hiding this comment

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

This is NICE! makes the interface consistent too. I don't think adding a macro is necessary (as is often mentioned, we should avoid meta programming if it's not necessary).

@MaximeBouton
Copy link
Contributor

ImplicitDistribution looks great! I don't see the benefit of the macro either.

rand(td) # will return a number near 2
```
"""
struct ImplicitDistribution{F<:Function, A}
Copy link
Member

Choose a reason for hiding this comment

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

I would drop the constraint of this being a function. It may also be useful to pass other callable objects here.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can make callable objects Functions e.g. struct MyType <: Function. Probably if someone passes an object here, it will be custom made for this purpose, or it is not too difficult to make a small closure. I think that the documentation/clarity bonus for including the constraint outweighs the downside. Am I forgetting anything?

Copy link
Member

Choose a reason for hiding this comment

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

I guess your are right. I forgot that you could just do sub-type Function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I am going to remove the Function constraint. It is an antipattern https://www.juliabloggers.com/julialang-antipatterns/


Each time `rand(rng, d::ImplicitDistribution)` is called,
```julia
sample_function(args..., rng)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Maybe have rng as the first argument? I feel like rng should always be the first argument to be consistent with rand. Then again, this is also different in other parts of POMDPs.jl.

Copy link
Member Author

@zsunberg zsunberg Jun 12, 2020

Choose a reason for hiding this comment

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

I don't consider this a "nit" 😄 Yeah, I have wondered about this. I think that having rng as an optional first argument to rand was a design mistake that we shouldn't copy except when implementing new methods of Base.rand. Anyone else have strong opinions?

@zsunberg zsunberg merged commit ce6af69 into master Jun 22, 2020
@zsunberg zsunberg deleted the implicit branch August 5, 2020 19:51
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

5 participants