Skip to content

Commit

Permalink
Merge branch 'cs-mb-0.14' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
cscherrer committed Aug 22, 2023
2 parents 5a25a51 + 07074d6 commit 744c4a4
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 56 deletions.
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
2 changes: 1 addition & 1 deletion CITATION.bib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@misc{MeasureTheory.jl,
author = {Chad Scherrer <chad.scherrer@gmail.com> and contributors},
title = {MeasureTheory.jl},
url = {https://github.com/cscherrer/MeasureTheory.jl},
url = {https://github.com/JuliaMath/MeasureTheory.jl},
version = {v0.2.2},
year = {2021},
month = {1}
Expand Down
9 changes: 5 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ ConcreteStructs = "0.2"
ConstructionBase = "1.3"
DensityInterface = "0.4"
Distributions = "0.25"
FillArrays = "0.12, 0.13"
DynamicIterators = "0.4"
FillArrays = "1"
ForwardDiff = "0.10"
IfElse = "0.1"
Infinities = "0.1"
Expand All @@ -63,11 +64,11 @@ 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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# MeasureTheory

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://cscherrer.github.io/MeasureTheory.jl/stable)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://cscherrer.github.io/MeasureTheory.jl/dev)
[![Build Status](https://github.com/cscherrer/MeasureTheory.jl/workflows/CI/badge.svg)](https://github.com/cscherrer/MeasureTheory.jl/actions)
[![Coverage](https://codecov.io/gh/cscherrer/MeasureTheory.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/cscherrer/MeasureTheory.jl)
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaMath.github.io/MeasureTheory.jl/stable)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaMath.github.io/MeasureTheory.jl/dev)
[![Build Status](https://github.com/JuliaMath/MeasureTheory.jl/workflows/CI/badge.svg)](https://github.com/JuliaMath/MeasureTheory.jl/actions)
[![Coverage](https://codecov.io/gh/JuliaMath/MeasureTheory.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaMath/MeasureTheory.jl)
[![DOI](https://proceedings.juliacon.org/papers/10.21105/jcon.00092/status.svg)](https://doi.org/10.21105/jcon.00092)

`MeasureTheory.jl` is a package for building and reasoning about measures.
Expand All @@ -21,15 +21,15 @@ To install `MeasureTheory.jl`, open the Julia Pkg REPL (by typing `]` in the sta
pkg> add MeasureTheory
```

To get an idea of the possibilities offered by this package, go to the [documentation](https://cscherrer.github.io/MeasureTheory.jl/stable).
To get an idea of the possibilities offered by this package, go to the [documentation](https://JuliaMath.github.io/MeasureTheory.jl/stable).



## Coordination and support

For interaction and shorter usage questions, there is the dedicated channel [#measuretheory on Julia's Zulip chat julialang.zulipchat.com](https://julialang.zulipchat.com/#narrow/stream/259730-measuretheory.2Ejl) and the #measuretheory channel on the [Julia language Slack chat](https://julialang.org/slack/) and for broader discussions [Julia's discourse forum](https://discourse.julialang.org).

Development takes place on Github with [Github's issue ticker](https://github.com/cscherrer/MeasureTheory.jl/issues) for bug reports and coordination.
Development takes place on Github with [Github's issue ticker](https://github.com/JuliaMath/MeasureTheory.jl/issues) for bug reports and coordination.

We adhere to the [community standards set forward by the Julia community.](https://julialang.org/community/standards/)

Expand All @@ -39,4 +39,4 @@ We adhere to the [community standards set forward by the Julia community.](https

## Stargazers over time

[![Stargazers over time](https://starchart.cc/cscherrer/MeasureTheory.jl.svg)](https://starchart.cc/cscherrer/MeasureTheory.jl)
[![Stargazers over time](https://starchart.cc/JuliaMath/MeasureTheory.jl.svg)](https://starchart.cc/JuliaMath/MeasureTheory.jl)
4 changes: 2 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pages = [
makedocs(;
modules = [MeasureBase, MeasureTheory],
authors = "Chad Scherrer <[email protected]> and contributors",
repo = "https://github.com/cscherrer/MeasureTheory.jl/blob/{commit}{path}#L{line}",
repo = "https://github.com/JuliaMath/MeasureTheory.jl/blob/{commit}{path}#L{line}",
sitename = "MeasureTheory.jl",
format = Documenter.HTML(;
prettyurls = get(ENV, "CI", "false") == "true",
Expand All @@ -30,4 +30,4 @@ makedocs(;
pages = pages,
)

deploydocs(; repo = "github.com/cscherrer/MeasureTheory.jl")
deploydocs(; repo = "github.com/JuliaMath/MeasureTheory.jl")
6 changes: 3 additions & 3 deletions docs/src/old_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://cscherrer.github.io/MeasureTheory.jl/stable)
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://cscherrer.github.io/MeasureTheory.jl/dev)
[![Build Status](https://github.com/cscherrer/MeasureTheory.jl/workflows/CI/badge.svg)](https://github.com/cscherrer/MeasureTheory.jl/actions)
[![Coverage](https://codecov.io/gh/cscherrer/MeasureTheory.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/cscherrer/MeasureTheory.jl)
[![Build Status](https://github.com/JuliaMath/MeasureTheory.jl/workflows/CI/badge.svg)](https://github.com/JuliaMath/MeasureTheory.jl/actions)
[![Coverage](https://codecov.io/gh/JuliaMath/MeasureTheory.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaMath/MeasureTheory.jl)

Check out our [JuliaCon submission](https://github.com/cscherrer/MeasureTheory.jl/blob/paper/paper/paper.pdf)
Check out our [JuliaCon submission](https://github.com/JuliaMath/MeasureTheory.jl/blob/paper/paper/paper.pdf)

`MeasureTheory.jl` is a package for building and reasoning about measures.

Expand Down
5 changes: 4 additions & 1 deletion 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 Down Expand Up @@ -122,6 +121,10 @@ xlog1py(x::Number, y::Number) = LogExpFunctions.xlog1py(x, y)
xlog1py(x, y) = x * log(1 + y)

using MeasureBase: Φ, Φinv
as(args...; kwargs...) = TV.as(args...; kwargs...)

# 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")
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)
2 changes: 0 additions & 2 deletions src/parameterized.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ function as(d::ProductMeasure{<:Base.Generator})
as(Array, as(d1), size(marginals(d))...)

Check warning on line 162 in src/parameterized.jl

View check run for this annotation

Codecov / codecov/patch

src/parameterized.jl#L160-L162

Added lines #L160 - L162 were not covered by tests
end

as(args...; kwargs...) = TV.as(args...; kwargs...)

as(::Beta) = as𝕀
as(::Cauchy) = asℝ
as(d::Dirichlet{(:α,)}) = TV.UnitSimplex(length(d.α))
Expand Down
4 changes: 2 additions & 2 deletions src/parameterized/binomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ end
x (0, 1)
end

function Base.rand(rng::AbstractRNG, ::Type, d::Binomial{(:n, :p)})
rand(rng, Dists.Binomial(d.n, d.p))
function Base.rand(rng::AbstractRNG, ::Type{T}, d::Binomial{(:n, :p)}) where {T}
rand(rng, T, Dists.Binomial(d.n, d.p))
end

Binomial(n) = Binomial(n, 0.5)
Expand Down
3 changes: 3 additions & 0 deletions src/parameterized/cauchy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function density_def(d::Cauchy{()}, x)
end

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
Expand All @@ -45,6 +46,8 @@ end

HalfCauchy(σ) = HalfCauchy= σ)

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

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

View check run for this annotation

Codecov / codecov/patch

src/parameterized/cauchy.jl#L49

Added line #L49 was not covered by tests

insupport(::Cauchy, x) = true

function smf(::Cauchy{()}, x)
Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/gumbel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end
import Base

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

Expand Down
2 changes: 1 addition & 1 deletion src/parameterized/lkj-cholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ logdensity_def(d::LKJCholesky, C::Cholesky) = logdensity_def(d, C.UL)
# z = diag(L)
# sum(log.(z) .* ((k:-1:1) .+ 2*(η-1)))

# Note: https://github.com/cscherrer/MeasureTheory.jl/issues/100#issuecomment-852428192
# Note: https://github.com/JuliaMath/MeasureTheory.jl/issues/100#issuecomment-852428192
c = d.k + 2- 1)
n = size(L, 1)
s = sum(1:n) do i
Expand Down
8 changes: 8 additions & 0 deletions src/resettable-rng.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ for T in vcat(subtypes(Signed), subtypes(Unsigned), subtypes(AbstractFloat))
end
end

function Base.rand(r::ResettableRNG, d::AbstractMeasure)
rand(r.rng, d)
end

function Base.rand(r::ResettableRNG, ::Type{T}, d::AbstractMeasure) where {T}
rand(r.rng, T, d)
end

Base.iterate(r::ResettableRNG) = iterate(r, nothing)

function Base.iterate(r::ResettableRNG, ::Nothing)
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 @@ function TV.transform_with(flag::TV.LogJacFlag, t::CorrCholesky, x::AbstractVect
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)

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 @@ function TV.transform_with(
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 @@ function TV.transform_with(flag::TV.LogJacFlag, t::Ordered, x, index::T) where {
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
34 changes: 9 additions & 25 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ test_measures = Any[
MvNormal= σ)
MvNormal= λ)
Uniform()
# Counting(Float64)
Dirac(0.0) + Normal()
]

Expand Down Expand Up @@ -104,6 +103,10 @@ end
@test logdensity_def(Binomial(; n, logitp), y)
@test logdensity_def(Binomial(; n, probitp), y)

rng = ResettableRNG(Random.MersenneTwister())
@test rand(rng, Binomial(n=0, p=1.0)) == 0
@test rand(rng, Binomial(n=10, p=1.0)) == 10

@test_broken logdensity_def(Binomial(n, p), CountingBase(ℤ[0:n]), x)
binomlogpdf(n, p, x)
end
Expand Down Expand Up @@ -298,7 +301,7 @@ using DynamicIterators: trace, TimeLift

@testset "rootmeasure/logpdf" begin
x = rand(Normal())
@test log𝒹(Normal(), rootmeasure(Normal()))(x) logdensityof(Normal(), x)
@test logdensity_rel(Normal(), rootmeasure(Normal()), x) logdensityof(Normal(), x)
end

@testset "Transforms" begin
Expand Down Expand Up @@ -465,45 +468,26 @@ end
end
end

@testset "Density measures and Radon-Nikodym" begin
x = randn()
# let d = ∫(𝒹(Cauchy(), Normal()), Normal())
# @test logdensity_rel(𝒹(d, Cauchy()), x) ≈ 0 atol = 1e-12
# end

let f = 𝒹((x -> x^2, Normal()), Normal())
@test f(x) x^2
end

# let d = ∫exp(log𝒹(Cauchy(), Normal()), Normal())
# @test logdensity_rel(d, Cauchy(), x) ≈ 0 atol=1e-12
# end

let f = log𝒹(∫exp(x -> x^2, Normal()), Normal())
@test f(x) x^2
end
end

@testset "Half measures" begin
@testset "HalfNormal" begin
d = Normal= 3)
h = HalfNormal(3)
x = rand(h)
@test density_rel(h, Lebesgue(ℝ), x) 2 * density_rel(d, Lebesgue(ℝ), x)
@test densityof(h, x) 2 * densityof(d, x)
end

@testset "HalfCauchy" begin
d = Cauchy= 3)
h = HalfCauchy(3)
x = rand(h)
@test density_rel(h, Lebesgue(ℝ), x) 2 * density_rel(d, Lebesgue(ℝ), x)
@test densityof(h, x) 2 * densityof(d, x)
end

@testset "HalfStudentT" begin
d = StudentT= 2, σ = 3)
h = HalfStudentT(2, 3)
x = rand(h)
@test density_rel(h, Lebesgue(ℝ), x) 2 * density_rel(d, Lebesgue(ℝ), x)
@test densityof(h, x) 2 * densityof(d, x)
end
end

Expand Down Expand Up @@ -642,7 +626,7 @@ end
end
end

@testset "https://github.com/cscherrer/MeasureTheory.jl/issues/217" begin
@testset "https://github.com/JuliaMath/MeasureTheory.jl/issues/217" begin
d = For(rand(3), rand(3)) do x, y
Normal(x, y)
end
Expand Down

0 comments on commit 744c4a4

Please sign in to comment.