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

MeasureBase 0.14 + other updates #260

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/Breakage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
fail-fast: false
matrix:
pkg: [
"cscherrer/Soss.jl",
"mschauer/Mitosis.jl"
# "cscherrer/Soss.jl",
# "mschauer/Mitosis.jl"
]
pkgversion: [latest, stable]

Expand Down
16 changes: 7 additions & 9 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeasureTheory"
uuid = "eadaa1a4-d27c-401d-8699-e962e1bbc33b"
authors = ["Chad Scherrer <chad.scherrer@gmail.com> and contributors"]
version = "0.18.4"
version = "0.19.0"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand All @@ -10,7 +10,6 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
DistributionMeasures = "35643b39-bfd4-4670-843f-16596ca89bf3"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DynamicIterators = "6c76993d-992e-5bf1-9e63-34920a5a5a38"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand Down Expand Up @@ -47,30 +46,29 @@ Compat = "3.42, 4"
ConcreteStructs = "0.2"
ConstructionBase = "1.3"
DensityInterface = "0.4"
DistributionMeasures = "0.2"
Distributions = "0.25"
DynamicIterators = "0.4"
FillArrays = "0.12, 0.13"
FillArrays = "1"
IfElse = "0.1"
Infinities = "0.1"
InverseFunctions = "0.1"
KeywordCalls = "0.2"
LazyArrays = "0.22"
LazyArrays = "1"
LogExpFunctions = "0.3.3"
MLStyle = "0.4"
MacroTools = "0.5"
MappedArrays = "0.4"
MeasureBase = "0.13"
MeasureBase = "0.14"
NamedTupleTools = "0.13, 0.14"
PositiveFactorizations = "0.2"
PrettyPrinting = "0.3, 0.4"
Reexport = "1"
SpecialFunctions = "1, 2"
Static = "0.5, 0.6"
Static = "0.8"
StaticArraysCore = "1"
StatsBase = "0.32, 0.33"
StatsBase = "0.34"
StatsFuns = "0.9, 1"
TransformVariables = "0.5, 0.6, 0.7"
TransformVariables = "0.8"
Tricks = "0.1"
julia = "1.6"

Expand Down
10 changes: 6 additions & 4 deletions src/MeasureTheory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using MLStyle
import TransformVariables
const TV = TransformVariables

using DistributionMeasures
using TransformVariables: asℝ₊, as𝕀, asℝ, transform

import Base
Expand All @@ -27,7 +26,7 @@ export Lebesgue
export ℝ, ℝ₊, 𝕀
export ⊙
export SpikeMixture
export CountingMeasure
export Counting
export TrivialMeasure
export Likelihood
export testvalue
Expand Down Expand Up @@ -60,7 +59,7 @@ import MeasureBase:
𝒹,
∫exp
import MeasureBase: ≪
using MeasureBase: BoundedInts, BoundedReals, CountingMeasure, IntegerDomain, IntegerNumbers
using MeasureBase: BoundedInts, BoundedReals, CountingBase, IntegerDomain, IntegerNumbers
using MeasureBase: weightedmeasure, restrict
using MeasureBase: AbstractTransitionKernel

Expand Down Expand Up @@ -97,7 +96,7 @@ using MeasureBase: kernel
using MeasureBase: Returns
import MeasureBase: proxy, @useproxy
import MeasureBase: basemeasure_depth
using MeasureBase: LebesgueMeasure
using MeasureBase: LebesgueBase

import DensityInterface: logdensityof
import DensityInterface: densityof
Expand All @@ -119,6 +118,9 @@ xlog1py(x, y) = x * log(1 + y)

as(args...; kwargs...) = TV.as(args...; kwargs...)
gaurav-arya marked this conversation as resolved.
Show resolved Hide resolved

# Type piracy until https://github.com/JuliaMath/MeasureBase.jl/issues/127 is fixed
MeasureBase.rand(::FixedRNG, ::Type{Bool}) = true

include("utils.jl")
include("const.jl")
include("combinators/for.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/combinators/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ end
@inline function basemeasure(d::AffinePushfwd{N,L}) where {N,L<:Lebesgue}
weightedmeasure(-logjac(d), d.parent)
end
@inline function basemeasure(d::AffinePushfwd{N,L}) where {N,L<:LebesgueMeasure}
@inline function basemeasure(d::AffinePushfwd{N,L}) where {N,L<:LebesgueBase}
weightedmeasure(-logjac(d), d.parent)
end

Expand Down
1 change: 0 additions & 1 deletion src/distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ function as(d::Dists.Product, _data::NamedTuple = NamedTuple())
as(Vector, as(v[1]), n)
end

as(m::DistributionMeasures.DistributionMeasure) = as(m.d)
gaurav-arya marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion src/parameterized/bernoulli.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Base

Bernoulli(p) = Bernoulli((p = p,))

basemeasure(::Bernoulli) = CountingMeasure()
basemeasure(::Bernoulli) = CountingBase()

testvalue(::Bernoulli) = true

Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/beta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end

@inline function basemeasure(d::Beta{(:α, :β)})
ℓ = -logbeta(d.α, d.β)
weightedmeasure(ℓ, LebesgueMeasure())
weightedmeasure(ℓ, LebesgueBase())
end

Base.rand(rng::AbstractRNG, T::Type, μ::Beta) = rand(rng, Dists.Beta(μ.α, μ.β))
Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/betabinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using SpecialFunctions

@parameterized BetaBinomial(n, α, β)

basemeasure(d::BetaBinomial) = CountingMeasure()
basemeasure(d::BetaBinomial) = CountingBase()

testvalue(::BetaBinomial) = 0

Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ probit(p) = sqrt2 * erfinv(2p - 1)

@parameterized Binomial(n, p)

basemeasure(d::Binomial) = CountingMeasure()
basemeasure(d::Binomial) = CountingBase()

testvalue(::Binomial) = 0

Expand Down
6 changes: 5 additions & 1 deletion src/parameterized/cauchy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

logdensity_def(d::Cauchy, x) = logdensity_def(proxy(d), x)

basemeasure(d::Cauchy) = WeightedMeasure(static(-logπ), LebesgueMeasure())
basemeasure(d::Cauchy) = WeightedMeasure(static(-logπ), LebesgueBase())

# @affinepars Cauchy

Expand All @@ -28,6 +28,8 @@

Base.rand(rng::AbstractRNG, T::Type, μ::Cauchy{()}) = randn(rng, T) / randn(rng, T)

Base.rand(::FixedRNG, ::Type{T}, μ::Cauchy{()}) where {T} = zero(T)

for N in AFFINEPARS
@eval begin
proxy(d::Cauchy{$N}) = affine(params(d), Cauchy())
Expand All @@ -46,6 +48,8 @@

HalfCauchy(σ) = HalfCauchy(σ = σ)

Base.rand(::FixedRNG, ::Type{T}, μ::Half{<:Cauchy}) where {T} = one(T)

Check warning on line 51 in src/parameterized/cauchy.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized/cauchy.jl#L51

Added line #L51 was not covered by tests

proxy(d::Cauchy{()}) = Dists.Cauchy()

insupport(::Cauchy, x) = true
2 changes: 1 addition & 1 deletion src/parameterized/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export Exponential
@parameterized Exponential(β)

insupport(::Exponential, x) = x ≥ 0
basemeasure(::Exponential) = LebesgueMeasure()
basemeasure(::Exponential) = LebesgueBase()

@kwstruct Exponential()

Expand Down
6 changes: 3 additions & 3 deletions src/parameterized/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

function basemeasure(d::Gamma{(:k,)})
ℓ = -loggamma(d.k)
weightedmeasure(ℓ, LebesgueMeasure())
weightedmeasure(ℓ, LebesgueBase())

Check warning on line 22 in src/parameterized/gamma.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized/gamma.jl#L22

Added line #L22 was not covered by tests
end

@kwstruct Gamma(k, σ)
Expand Down Expand Up @@ -57,11 +57,11 @@
ϕ = d.ϕ
ϕinv = inv(ϕ)
ℓ = -ϕinv * log(ϕ) - first(logabsgamma(ϕinv))
weightedmeasure(ℓ, LebesgueMeasure())
weightedmeasure(ℓ, LebesgueBase())

Check warning on line 60 in src/parameterized/gamma.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized/gamma.jl#L60

Added line #L60 was not covered by tests
end

function basemeasure(d::Gamma{(:μ, :ϕ),Tuple{M,StaticFloat64{ϕ}}}) where {M,ϕ}
ϕinv = inv(ϕ)
ℓ = static(-ϕinv * log(ϕ) - first(logabsgamma(ϕinv)))
weightedmeasure(ℓ, LebesgueMeasure())
weightedmeasure(ℓ, LebesgueBase())

Check warning on line 66 in src/parameterized/gamma.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized/gamma.jl#L66

Added line #L66 was not covered by tests
end
6 changes: 3 additions & 3 deletions src/parameterized/gumbel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export Gumbel

@parameterized Gumbel()

basemeasure(::Gumbel{()}) = LebesgueMeasure()
basemeasure(::Gumbel{()}) = LebesgueBase()

@kwstruct Gumbel()

Expand All @@ -28,8 +28,8 @@ end

import Base

function Base.rand(rng::AbstractRNG, d::Gumbel{()})
u = rand(rng)
function Base.rand(rng::AbstractRNG, ::Type{T}, d::Gumbel{()}) where {T}
u = rand(rng, T)
-log(-log(u))
end

Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/inverse-gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@

function basemeasure(d::InverseGaussian{(:μ, :ϕ)})
ℓ = static(-0.5) * (static(float(log2π)) + log(d.ϕ))
weightedmeasure(ℓ, LebesgueMeasure())
weightedmeasure(ℓ, LebesgueBase())

Check warning on line 52 in src/parameterized/inverse-gaussian.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized/inverse-gaussian.jl#L52

Added line #L52 was not covered by tests
end
5 changes: 3 additions & 2 deletions src/parameterized/laplace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ end

logdensity_def(d::Laplace, x) = logdensity_def(proxy(d), x)

basemeasure(::Laplace{()}) = WeightedMeasure(static(-logtwo), LebesgueMeasure())
basemeasure(::Laplace{()}) = WeightedMeasure(static(-logtwo), LebesgueBase())

# @affinepars Laplace

function Base.rand(rng::AbstractRNG, ::Type{T}, μ::Laplace{()}) where {T}
rand(rng, Dists.Laplace())
T(rand(rng, Dists.Laplace()))
end

Base.rand(rng::AbstractRNG, ::Type{T}, μ::Laplace) where {T} = Base.rand(rng, T, proxy(μ))

≪(::Laplace, ::Lebesgue{X}) where {X<:Real} = true
Expand Down
4 changes: 2 additions & 2 deletions src/parameterized/lkj-cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@

@inline function basemeasure(d::LKJCholesky{(:k, :η)})
t = as(d)
base = Pushforward(t, LebesgueMeasure()^TV.dimension(t), False())
base = Pushforward(t, LebesgueBase()^TV.dimension(t), False())
WeightedMeasure(Dists.lkj_logc0(d.k, d.η), base)
end

@inline function basemeasure(d::LKJCholesky{(:k, :logη)})
t = as(d)
η = exp(d.logη)
base = Pushforward(t, LebesgueMeasure()^TV.dimension(t), False())
base = Pushforward(t, LebesgueBase()^TV.dimension(t), False())

Check warning on line 91 in src/parameterized/lkj-cholesky.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized/lkj-cholesky.jl#L91

Added line #L91 was not covered by tests
WeightedMeasure(Dists.lkj_logc0(d.k, η), base)
end

Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/multinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export Multinomial

@parameterized Multinomial(n, p)

basemeasure(d::Multinomial) = CountingMeasure()
basemeasure(d::Multinomial) = CountingBase()

@inline function insupport(d::Multinomial{(:n, :p)}, x)
length(x) == length(d.p) || return false
Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/negativebinomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Base

insupport(::NegativeBinomial, x) = isinteger(x) && x ≥ 0

basemeasure(::NegativeBinomial) = CountingMeasure()
basemeasure(::NegativeBinomial) = CountingBase()

testvalue(::NegativeBinomial) = 0

Expand Down
6 changes: 3 additions & 3 deletions src/parameterized/normal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
insupport(d::Normal) = Returns(true)

@inline logdensity_def(d::Normal{()}, x) = -x^2 / 2
@inline basemeasure(::Normal{()}) = WeightedMeasure(static(-0.5 * log2π), LebesgueMeasure())
@inline basemeasure(::Normal{()}) = WeightedMeasure(static(-0.5 * log2π), LebesgueBase())

@kwstruct Normal(μ)
@kwstruct Normal(σ)
Expand Down Expand Up @@ -147,7 +147,7 @@

@inline function basemeasure(d::Normal{(:σ²,)})
ℓ = static(-0.5) * (static(float(log2π)) + log(d.σ²))
weightedmeasure(ℓ, LebesgueMeasure())
weightedmeasure(ℓ, LebesgueBase())

Check warning on line 150 in src/parameterized/normal.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized/normal.jl#L150

Added line #L150 was not covered by tests
end

proxy(d::Normal{(:μ, :σ²)}) = affine((μ = d.μ,), Normal((σ² = d.σ²,)))
Expand All @@ -163,7 +163,7 @@

@inline function basemeasure(d::Normal{(:τ,)})
ℓ = static(-0.5) * (static(float(log2π)) - log(d.τ))
weightedmeasure(ℓ, LebesgueMeasure())
weightedmeasure(ℓ, LebesgueBase())

Check warning on line 166 in src/parameterized/normal.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized/normal.jl#L166

Added line #L166 was not covered by tests
end

proxy(d::Normal{(:μ, :τ)}) = affine((μ = d.μ,), Normal((τ = d.τ,)))
Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/snedecorf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@inline function basemeasure(d::SnedecorF{(:ν1, :ν2)})
ℓ = -logbeta(d.ν1 / 2, d.ν2 / 2)
weightedmeasure(ℓ, LebesgueMeasure())
weightedmeasure(ℓ, LebesgueBase())

Check warning on line 19 in src/parameterized/snedecorf.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized/snedecorf.jl#L19

Added line #L19 was not covered by tests
end

xform(::SnedecorF) = asℝ₊
Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/studentt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ end

@inline function basemeasure(d::StudentT{(:ν,)})
ℓ = loggamma((d.ν + 1) / 2) - loggamma(d.ν / 2) - log(π * d.ν) / 2
weightedmeasure(ℓ, LebesgueMeasure())
weightedmeasure(ℓ, LebesgueBase())
end

xform(::StudentT) = asℝ
Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/uniform.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export Uniform
insupport(::Uniform{()}) = in𝕀
insupport(::Uniform{()}, x) = in𝕀(x)

@inline basemeasure(::Uniform{()}) = LebesgueMeasure()
@inline basemeasure(::Uniform{()}) = LebesgueBase()

proxy(::Uniform{()}) = Dists.Uniform()

Expand Down
4 changes: 2 additions & 2 deletions src/transforms/corrcholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
return Cholesky(U, 'U', 0), ℓ, index
end

TV.inverse_eltype(t::CorrCholesky, x::AbstractMatrix) = TV.extended_eltype(x)
TV.inverse_eltype(t::CorrCholesky, x::AbstractMatrix) = eltype(x)

Check warning on line 33 in src/transforms/corrcholesky.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/corrcholesky.jl#L33

Added line #L33 was not covered by tests

TV.inverse_eltype(t::CorrCholesky, x::Cholesky) = TV.extended_eltype(x)
TV.inverse_eltype(t::CorrCholesky, x::Cholesky) = eltype(x)
gaurav-arya marked this conversation as resolved.
Show resolved Hide resolved

function TV.inverse_at!(x::AbstractVector, index, t::CorrCholesky, L::LowerTriangular)
return TV.inverse_at!(x, index, CorrCholeskyUpper(t.n), L')
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/corrcholeskylower.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
return U', ℓ, index
end

TV.inverse_eltype(t::CorrCholeskyLower, L::LowerTriangular) = TV.extended_eltype(L)
TV.inverse_eltype(t::CorrCholeskyLower, L::LowerTriangular) = eltype(L)

Check warning on line 41 in src/transforms/corrcholeskylower.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/corrcholeskylower.jl#L41

Added line #L41 was not covered by tests

function TV.inverse_at!(x::AbstractVector, index, t::CorrCholeskyLower, L::LowerTriangular)
return TV.inverse_at!(x, index, CorrCholeskyUpper(t.n), L')
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/ordered.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
return (y, ℓ, index)
end

TV.inverse_eltype(t::Ordered, y::AbstractVector) = TV.extended_eltype(y)
TV.inverse_eltype(t::Ordered, y::AbstractVector) = eltype(y)

Check warning on line 52 in src/transforms/ordered.jl

View check run for this annotation

Codecov / codecov/patch

src/transforms/ordered.jl#L52

Added line #L52 was not covered by tests

Ordered(n::Int) = Ordered(asℝ, n)

Expand Down
Loading
Loading