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

Monadic iteration for measures? #55

Open
oschulz opened this issue May 31, 2022 · 1 comment
Open

Monadic iteration for measures? #55

oschulz opened this issue May 31, 2022 · 1 comment

Comments

@oschulz
Copy link
Collaborator

oschulz commented May 31, 2022

By defining

Base.iterate(m::AbstractMeasure) = rand(m), nothing
Base.iterate(m::AbstractMeasure, ::Nothing) = rand(m), nothing
Base.Iterators.IteratorSize(::Type{<:AbstractMeasure}) = Base.IsInfinite()

we could make measures monadic in respect to Julia's iteration interface:

julia> using Base.Iterators, MeasureTheory
julia> take((x^2 for x in Normal()), 10) |> collect
10-element Vector{Float64}:
[...]

This would play well semantically with a syntax f.(μ) for pushforward measures (#54).

x^2 for x in Normal would become semantically equivalent to x ~ Normal(); return x^2 in a model.

@cscherrer
Copy link
Collaborator

Thanks @oschulz . We've talked a little bit about ideas in this direction, and I appreciate your creating these issues to make things easier to track.

Similar to likelihoods, I think pushforwards need to be set up in a way that allows simplification in cases with closed form solutions. The problem with sampling is that it "forgets" about any structure of a given measure and takes a very specific concrete approach.

I like the idea of being able to map a measure to an infinite stream of samples (maybe similar to Chain), but I think it's important to have a method to take us from the world of "measure expressions" to the world of infinite streams.

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