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

Make @measure more flexible #18

Merged
merged 3 commits into from
Oct 7, 2020
Merged

Make @measure more flexible #18

merged 3 commits into from
Oct 7, 2020

Conversation

cscherrer
Copy link
Collaborator

Made it so things like this now work:

julia> using MeasureTheory

julia> using MacroTools

julia> using StatsFuns

julia> @measure MvNormal(μ,Σ)  (1/sqrt2π^length(μ)) * Lebesgue(Real)^size(μ);

julia> prettify(@macroexpand @measure MvNormal(μ,Σ)  (1/sqrt2π^length(μ)) * Lebesgue(Real)^size(μ))
quote
    struct MvNormal{P} <: MeasureTheory.AbstractMeasure
        par::P
    end
    function MvNormal(nt::NamedTuple)
        P = typeof(nt)
        return MvNormal{P}(nt)
    end
    MvNormal(; kwargs...) = MvNormal((; kwargs...))
    function MeasureTheory.basemeasure::MvNormal{P}) where P
        return (1 / sqrt2π ^ length.par.μ)) * Lebesgue(Real) ^ size.par.μ)
    end
    MvNormal(μ, Σ) = MvNormal(; μ, Σ)
end

julia> μ = randn(3);

julia> Σ = let x = randn(10,3)
           x' * x
       end;

julia> basemeasure(MvNormal(μ, Σ))
MeasureTheory.ScaledMeasure{Float64,PowerMeasure{Lebesgue{Real},1}}(-2.7568155996140185, PowerMeasure{Lebesgue{Real},1}(Lebesgue{Real}(), (3,)))

Currently I'm just escaping the whole thing, we'll need another pass once we have it working properly to make things more hygienic.

@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2020

Codecov Report

Merging #18 into master will increase coverage by 6.11%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #18      +/-   ##
==========================================
+ Coverage    8.57%   14.68%   +6.11%     
==========================================
  Files          16       16              
  Lines         140      143       +3     
==========================================
+ Hits           12       21       +9     
+ Misses        128      122       -6     
Impacted Files Coverage Δ
src/combinators/power.jl 0.00% <0.00%> (ø)
src/combinators/product.jl 0.00% <0.00%> (ø)
src/probability/normal.jl 0.00% <ø> (ø)
src/macros.jl 83.33% <100.00%> (+37.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b28d28e...10b2527. Read the comment docs.

@cscherrer cscherrer merged commit 9775480 into master Oct 7, 2020
@cscherrer cscherrer deleted the cs-macrostuff branch November 28, 2020 15:48
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.

3 participants