Skip to content

Commit

Permalink
0.19 (#240)
Browse files Browse the repository at this point in the history
* First steps toward factoring out TransformVariables

* factor out exponential-families and tweedie

* AffinePushfwd <: AbstractPushforward

* don't export `mydot`

* moving things around

* drop TV functionality

* bugfix

* bugfix

* format

* factor out Chain (let's move it to a new package)

* fix type instability

* update Bernoulli

* import massof

* bugfix

* add some methods

* Revert "First steps toward factoring out TransformVariables"

This reverts commit c78c166.

* smfinv => invsmf

* update MeasureBase version

* add some smfs

* edits

* fix typo

* fix laplace

* fix bernoulli

* fix beta

* fix StudentT

* Fix Uniform

* fix Gumbel

* fix Dirichlet

* minor Dirichlet update

* more Dirichlet

* drop as(m::DistributionMeasures.DistributionMeasure) (for now)

* drop tests for Chain

* drop DistributionMeasures dependency (for now)

* fix cauchy

* fixing Binomial

* small updates

* update

* updates

* drop brokwn measures

* fix normal

* asparams methods

* update tests

* smfAD macro

* update tests

* smf(::Normal)

* move import

* add ForwardDiff

* dep constraint

* fix tests

* smf for affine pushfwd

* update tests

* update test name

* tests

* tests

* update StudentT

* tests

* Some `For` updates

* optimize `Normal`

* update insupport for Normal

* update basemeasure for For measures

* some affine updates

* some fixes

* bump version

* formatting

* oops didn't mean to add that

* format

* MeasureBase 0.14 + other updates

* compatibility fixes

* updates

* more fixes

* fixes

* more fixes

* tests passing

* bump version

* drop breakage CI for now

* update Julia versions for CI

* Drop commented-out code
  • Loading branch information
cscherrer authored Aug 22, 2023
1 parent 198ee9f commit 84440f8
Show file tree
Hide file tree
Showing 39 changed files with 490 additions and 573 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
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 <chad.scherrer@gmail.com> and contributors"]
version = "0.18.4"
version = "0.19.0"

[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
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

2 comments on commit 84440f8

@cscherrer
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90104

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.19.0 -m "<description of version>" 84440f82df0e470bd9865f0b072ad23689c22fd5
git push origin v0.19.0

Please sign in to comment.