Skip to content

Commit

Permalink
Merge branch 'master' into add-accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
theogf authored Dec 15, 2023
2 parents 4c9cff6 + 84440f8 commit ae241df
Show file tree
Hide file tree
Showing 43 changed files with 504 additions and 588 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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.7'
- '1.8'
- '1.9'
os:
- ubuntu-latest
- macOS-latest
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
18 changes: 8 additions & 10 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 <[email protected]> and contributors"]
version = "0.18.4"
version = "0.19.1"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand All @@ -10,16 +10,15 @@ 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"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
KeywordCalls = "4d827475-d3e4-43d6-abe3-9688362ede9f"
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
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"
ForwardDiff = "0.10"
IfElse = "0.1"
Infinities = "0.1"
InverseFunctions = "0.1"
KeywordCalls = "0.2"
LazyArrays = "0.22"
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
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
27 changes: 16 additions & 11 deletions src/MeasureTheory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ using MLStyle
import TransformVariables
const TV = TransformVariables

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

import Base
import Distributions
const Dists = Distributions

export TV
export transform
Expand All @@ -27,14 +24,12 @@ export Lebesgue
export ℝ, ℝ₊, 𝕀
export
export SpikeMixture
export CountingMeasure
export TrivialMeasure
export Likelihood
export testvalue
export basekernel

using Infinities
using DynamicIterators
using KeywordCalls
using ConstructionBase
using Accessors
Expand All @@ -58,9 +53,12 @@ import MeasureBase:
paramnames,
∫,
𝒹,
∫exp
∫exp,
smf,
invsmf,
massof
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,13 +95,16 @@ 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
import DensityInterface: DensityKind
using DensityInterface

using ForwardDiff
using ForwardDiff: Dual

gentype::AbstractMeasure) = typeof(testvalue(μ))

# gentype(μ::AbstractMeasure) = gentype(basemeasure(μ))
Expand All @@ -117,20 +118,22 @@ xlogy(x, y) = x * log(y)
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")
include("combinators/for.jl")
# include("traits.jl")
include("parameterized.jl")

include("macros.jl")
include("combinators/affine.jl")
include("combinators/weighted.jl")
include("combinators/product.jl")
include("combinators/transforms.jl")
include("combinators/exponential-families.jl")
# include("combinators/exponential-families.jl")
include("resettable-rng.jl")
include("realized.jl")
include("combinators/chain.jl")
Expand Down Expand Up @@ -165,5 +168,7 @@ include("combinators/ifelse.jl")
include("transforms/corrcholesky.jl")
include("transforms/ordered.jl")

include("parameterized.jl")

include("distproxy.jl")
end # module
91 changes: 73 additions & 18 deletions src/combinators/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ logjac(f::AffineTransform{(:μ, :σ)}) = logjac(f.σ)
logjac(f::AffineTransform{(:μ, :λ)}) = -logjac(f.λ)
logjac(f::AffineTransform{(:σ,)}) = logjac(f.σ)
logjac(f::AffineTransform{(:λ,)}) = -logjac(f.λ)
logjac(f::AffineTransform{(:μ,)}) = 0.0
logjac(f::AffineTransform{(:μ,)}) = static(0.0)

###############################################################################

Expand Down Expand Up @@ -161,7 +161,7 @@ basemeasure(d::OrthoLebesgue) = d

logdensity_def(::OrthoLebesgue, x) = static(0.0)

struct AffinePushfwd{N,M,T} <: AbstractMeasure
struct AffinePushfwd{N,M,T} <: MeasureBase.AbstractPushforward
f::AffineTransform{N,T}
parent::M
end
Expand All @@ -172,6 +172,10 @@ function Pretty.tile(d::AffinePushfwd)
Pretty.list_layout([pars, Pretty.tile(d.parent)]; prefix = :AffinePushfwd)
end

@inline MeasureBase.transport_origin(d::AffinePushfwd) = d.parent
@inline MeasureBase.to_origin(d::AffinePushfwd, y) = inverse(getfield(d, :f))(y)
@inline MeasureBase.from_origin(d::AffinePushfwd, x) = getfield(d, :f)(x)

@inline function testvalue(d::AffinePushfwd)
f = getfield(d, :f)
z = testvalue(parent(d))
Expand Down Expand Up @@ -282,7 +286,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 Expand Up @@ -313,19 +317,6 @@ supportdim(nt::NamedTuple{(:σ,),T}) where {T} = colsize(nt.σ)
supportdim(nt::NamedTuple{(:λ,),T}) where {T} = rowsize(nt.λ)
supportdim(nt::NamedTuple{(:μ,),T}) where {T} = size(nt.μ)

asparams(::AffinePushfwd, ::StaticSymbol{:μ}) = asℝ
asparams(::AffinePushfwd, ::StaticSymbol{:σ}) = asℝ₊
asparams(::Type{A}, ::StaticSymbol{:μ}) where {A<:AffinePushfwd} = asℝ
asparams(::Type{A}, ::StaticSymbol{:σ}) where {A<:AffinePushfwd} = asℝ₊

function asparams(d::AffinePushfwd{N,M,T}, ::StaticSymbol{:μ}) where {N,M,T<:AbstractArray}
as(Array, asℝ, size(d.μ))
end

function asparams(d::AffinePushfwd{N,M,T}, ::StaticSymbol{:σ}) where {N,M,T<:AbstractArray}
as(Array, asℝ, size(d.σ))
end

function Base.rand(rng::Random.AbstractRNG, ::Type{T}, d::AffinePushfwd) where {T}
z = rand(rng, T, parent(d))
f = getfield(d, :f)
Expand All @@ -336,8 +327,8 @@ end
insupport(d.parent, inverse(d.f)(x))
end

@inline function Distributions.cdf(d::AffinePushfwd, x)
cdf(parent(d), inverse(d.f)(x))
@inline function MeasureBase.smf(d::AffinePushfwd, x)
smf(parent(d), inverse(d.f)(x))
end

@inline function mean(d::AffinePushfwd)
Expand All @@ -364,3 +355,67 @@ end
@inline function std(d::AffinePushfwd{(:μ, :λ)})
std(parent(d)) / d.λ
end

###############################################################################
# smf

@inline function smf(d::AffinePushfwd{(:μ,)}, x)
f = getfield(d, :f)
smf(parent(d), inverse(f)(x))
end

@inline function smf(d::AffinePushfwd{(:μ, :σ)}, x)
f = getfield(d, :f)
p = smf(parent(d), inverse(f)(x))
d.σ > 0 ? p : one(p) - p
end

@inline function smf(d::AffinePushfwd{(:σ,)}, x)
f = getfield(d, :f)
p = smf(parent(d), inverse(f)(x))
d.σ > 0 ? p : one(p) - p
end

@inline function smf(d::AffinePushfwd{(:λ,)}, x)
f = getfield(d, :f)
p = smf(parent(d), inverse(f)(x))
d.λ > 0 ? p : one(p) - p
end

@inline function smf(d::AffinePushfwd{(:μ, :λ)}, x)
f = getfield(d, :f)
p = smf(parent(d), inverse(f)(x))
d.λ > 0 ? p : one(p) - p
end

###############################################################################
# invsmf

@inline function invsmf(d::AffinePushfwd{(:μ,)}, p)
f = getfield(d, :f)
f(invsmf(parent(d), p))
end

@inline function invsmf(d::AffinePushfwd{(:μ, :σ)}, p)
p = d.σ > 0 ? p : one(p) - p
f = getfield(d, :f)
f(invsmf(parent(d), p))
end

@inline function invsmf(d::AffinePushfwd{(:σ,)}, p)
p = d.σ > 0 ? p : one(p) - p
f = getfield(d, :f)
f(invsmf(parent(d), p))
end

@inline function invsmf(d::AffinePushfwd{(:λ,)}, p)
p = d.λ > 0 ? p : one(p) - p
f = getfield(d, :f)
f(invsmf(parent(d), p))
end

@inline function invsmf(d::AffinePushfwd{(:μ, :λ)}, p)
p = d.λ > 0 ? p : one(p) - p
f = getfield(d, :f)
f(invsmf(parent(d), p))
end
Loading

0 comments on commit ae241df

Please sign in to comment.