-
Notifications
You must be signed in to change notification settings - Fork 32
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(::SuperpositionMeasure)
#191
Comments
Thanks @sethaxen , we really need to nail down the design for this. I think the main issue comes down to normalization. Some examples;
That might start to seem more like a clear "no", but then what about @theogf and I were talking recently about how a lot of what we do with smart constructors is like the usual data structure business of worrying about invariants. So one possibility would be to enforce that the weights in a superposition must add to one. Then My main concerns with that are (1) the overhead of maintaining the invariant, and (2) that is still leaves out that instead of a distribution we might have something like I should maybe mention another thing I was considering for that. rebase(μ, ν) = ∫(𝒹(μ,ν), ν) I think for sampling this, it's reasonable to use importance sampling. Or at least, that feels "primitive" in some sense. So we would sample This leads into some other things about representing samples as measures, etc, but I'll hold off on that for now. |
TBH I haven't thought about this at all from a design perspective. For the moment I just need a way to represent a uniformly weighted mixture of multivariate normals. I certainly could roll my own type for that (I'm going to keep the integration code in Pathfinder as not part of the API for now, so I'm not concerned about type changes in the future) as well instead of using But this also isn't urgent because I don't think the Pathfinder/MeasureTheory integration will be used much until Soss/Tilde use the latest MeasureTheory version. |
Ok, that's a nice special case. Previously I've had an |
That's currently my work-around which of course involve type piracy: weight(::MeasureBase.AbstractMeasure) = 1
weight(μ::MeasureBase.WeightedMeasure) = exp(μ.logweight)
function Base.rand(rng::AbstractRNG, μs::AbstractVector{<:MeasureBase.AbstractMeasure})
ws = weight.(μs)
ws /= sum(ws) # Normalization of the weights
μs[rand(rng, Categorical(ws))]
end
function Base.rand(rng::AbstractRNG, ::Type{T}, μ::SuperpositionMeasure) where {T}
rand(rng, T, rand(rng, μ.components))
end
function Base.rand(rng::AbstractRNG, ::Type{T}, μ::WeightedMeasure) where {T}
rand(rng, T, μ.base)
end EDIT: bug fix |
@cscherrer it seems
SuperpositionMeasure
does not have arand
method:Originally posted by @sethaxen in mlcolab/Pathfinder.jl#46 (comment)
The text was updated successfully, but these errors were encountered: