Skip to content

Commit 84440f8

Browse files
authored
0.19 (#240)
* 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
1 parent 198ee9f commit 84440f8

39 files changed

+490
-573
lines changed

.github/workflows/Breakage.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
pkg: [
18-
"cscherrer/Soss.jl",
19-
"mschauer/Mitosis.jl"
18+
# "cscherrer/Soss.jl",
19+
# "mschauer/Mitosis.jl"
2020
]
2121
pkgversion: [latest, stable]
2222

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
fail-fast: false
2323
matrix:
2424
version:
25-
- '1.6'
26-
- '1.7'
25+
- '1.8'
26+
- '1.9'
2727
os:
2828
- ubuntu-latest
2929
- macOS-latest

Project.toml

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "MeasureTheory"
22
uuid = "eadaa1a4-d27c-401d-8699-e962e1bbc33b"
33
authors = ["Chad Scherrer <[email protected]> and contributors"]
4-
version = "0.18.4"
4+
version = "0.19.0"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
@@ -10,16 +10,15 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
1010
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
1111
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
1212
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
13-
DistributionMeasures = "35643b39-bfd4-4670-843f-16596ca89bf3"
1413
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1514
DynamicIterators = "6c76993d-992e-5bf1-9e63-34920a5a5a38"
1615
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
16+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1717
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
1818
Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
1919
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2020
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
2121
KeywordCalls = "4d827475-d3e4-43d6-abe3-9688362ede9f"
22-
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
2322
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2423
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
2524
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
@@ -47,30 +46,29 @@ Compat = "3.42, 4"
4746
ConcreteStructs = "0.2"
4847
ConstructionBase = "1.3"
4948
DensityInterface = "0.4"
50-
DistributionMeasures = "0.2"
5149
Distributions = "0.25"
5250
DynamicIterators = "0.4"
53-
FillArrays = "0.12, 0.13"
51+
FillArrays = "1"
52+
ForwardDiff = "0.10"
5453
IfElse = "0.1"
5554
Infinities = "0.1"
5655
InverseFunctions = "0.1"
5756
KeywordCalls = "0.2"
58-
LazyArrays = "0.22"
5957
LogExpFunctions = "0.3.3"
6058
MLStyle = "0.4"
6159
MacroTools = "0.5"
6260
MappedArrays = "0.4"
63-
MeasureBase = "0.13"
61+
MeasureBase = "0.14"
6462
NamedTupleTools = "0.13, 0.14"
6563
PositiveFactorizations = "0.2"
6664
PrettyPrinting = "0.3, 0.4"
6765
Reexport = "1"
6866
SpecialFunctions = "1, 2"
69-
Static = "0.5, 0.6"
67+
Static = "0.8"
7068
StaticArraysCore = "1"
71-
StatsBase = "0.32, 0.33"
69+
StatsBase = "0.34"
7270
StatsFuns = "0.9, 1"
73-
TransformVariables = "0.5, 0.6, 0.7"
71+
TransformVariables = "0.8"
7472
Tricks = "0.1"
7573
julia = "1.6"
7674

src/MeasureTheory.jl

+16-11
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ using MLStyle
88
import TransformVariables
99
const TV = TransformVariables
1010

11-
using DistributionMeasures
1211
using TransformVariables: asℝ₊, as𝕀, asℝ, transform
1312

1413
import Base
15-
import Distributions
16-
const Dists = Distributions
1714

1815
export TV
1916
export transform
@@ -27,14 +24,12 @@ export Lebesgue
2724
export ℝ, ℝ₊, 𝕀
2825
export
2926
export SpikeMixture
30-
export CountingMeasure
3127
export TrivialMeasure
3228
export Likelihood
3329
export testvalue
3430
export basekernel
3531

3632
using Infinities
37-
using DynamicIterators
3833
using KeywordCalls
3934
using ConstructionBase
4035
using Accessors
@@ -58,9 +53,12 @@ import MeasureBase:
5853
paramnames,
5954
∫,
6055
𝒹,
61-
∫exp
56+
∫exp,
57+
smf,
58+
invsmf,
59+
massof
6260
import MeasureBase:
63-
using MeasureBase: BoundedInts, BoundedReals, CountingMeasure, IntegerDomain, IntegerNumbers
61+
using MeasureBase: BoundedInts, BoundedReals, CountingBase, IntegerDomain, IntegerNumbers
6462
using MeasureBase: weightedmeasure, restrict
6563
using MeasureBase: AbstractTransitionKernel
6664

@@ -97,13 +95,16 @@ using MeasureBase: kernel
9795
using MeasureBase: Returns
9896
import MeasureBase: proxy, @useproxy
9997
import MeasureBase: basemeasure_depth
100-
using MeasureBase: LebesgueMeasure
98+
using MeasureBase: LebesgueBase
10199

102100
import DensityInterface: logdensityof
103101
import DensityInterface: densityof
104102
import DensityInterface: DensityKind
105103
using DensityInterface
106104

105+
using ForwardDiff
106+
using ForwardDiff: Dual
107+
107108
gentype::AbstractMeasure) = typeof(testvalue(μ))
108109

109110
# gentype(μ::AbstractMeasure) = gentype(basemeasure(μ))
@@ -117,20 +118,22 @@ xlogy(x, y) = x * log(y)
117118
xlog1py(x::Number, y::Number) = LogExpFunctions.xlog1py(x, y)
118119
xlog1py(x, y) = x * log(1 + y)
119120

121+
using MeasureBase: Φ, Φinv
120122
as(args...; kwargs...) = TV.as(args...; kwargs...)
121123

124+
# Type piracy until https://github.com/JuliaMath/MeasureBase.jl/issues/127 is fixed
125+
MeasureBase.rand(::FixedRNG, ::Type{Bool}) = true
126+
122127
include("utils.jl")
123128
include("const.jl")
124129
include("combinators/for.jl")
125-
# include("traits.jl")
126-
include("parameterized.jl")
127130

128131
include("macros.jl")
129132
include("combinators/affine.jl")
130133
include("combinators/weighted.jl")
131134
include("combinators/product.jl")
132135
include("combinators/transforms.jl")
133-
include("combinators/exponential-families.jl")
136+
# include("combinators/exponential-families.jl")
134137
include("resettable-rng.jl")
135138
include("realized.jl")
136139
include("combinators/chain.jl")
@@ -165,5 +168,7 @@ include("combinators/ifelse.jl")
165168
include("transforms/corrcholesky.jl")
166169
include("transforms/ordered.jl")
167170

171+
include("parameterized.jl")
172+
168173
include("distproxy.jl")
169174
end # module

src/combinators/affine.jl

+73-18
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ logjac(f::AffineTransform{(:μ, :σ)}) = logjac(f.σ)
128128
logjac(f::AffineTransform{(:μ, :λ)}) = -logjac(f.λ)
129129
logjac(f::AffineTransform{(:σ,)}) = logjac(f.σ)
130130
logjac(f::AffineTransform{(:λ,)}) = -logjac(f.λ)
131-
logjac(f::AffineTransform{(:μ,)}) = 0.0
131+
logjac(f::AffineTransform{(:μ,)}) = static(0.0)
132132

133133
###############################################################################
134134

@@ -161,7 +161,7 @@ basemeasure(d::OrthoLebesgue) = d
161161

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

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

175+
@inline MeasureBase.transport_origin(d::AffinePushfwd) = d.parent
176+
@inline MeasureBase.to_origin(d::AffinePushfwd, y) = inverse(getfield(d, :f))(y)
177+
@inline MeasureBase.from_origin(d::AffinePushfwd, x) = getfield(d, :f)(x)
178+
175179
@inline function testvalue(d::AffinePushfwd)
176180
f = getfield(d, :f)
177181
z = testvalue(parent(d))
@@ -282,7 +286,7 @@ end
282286
@inline function basemeasure(d::AffinePushfwd{N,L}) where {N,L<:Lebesgue}
283287
weightedmeasure(-logjac(d), d.parent)
284288
end
285-
@inline function basemeasure(d::AffinePushfwd{N,L}) where {N,L<:LebesgueMeasure}
289+
@inline function basemeasure(d::AffinePushfwd{N,L}) where {N,L<:LebesgueBase}
286290
weightedmeasure(-logjac(d), d.parent)
287291
end
288292

@@ -313,19 +317,6 @@ supportdim(nt::NamedTuple{(:σ,),T}) where {T} = colsize(nt.σ)
313317
supportdim(nt::NamedTuple{(:λ,),T}) where {T} = rowsize(nt.λ)
314318
supportdim(nt::NamedTuple{(:μ,),T}) where {T} = size(nt.μ)
315319

316-
asparams(::AffinePushfwd, ::StaticSymbol{:μ}) = asℝ
317-
asparams(::AffinePushfwd, ::StaticSymbol{:σ}) = asℝ₊
318-
asparams(::Type{A}, ::StaticSymbol{:μ}) where {A<:AffinePushfwd} = asℝ
319-
asparams(::Type{A}, ::StaticSymbol{:σ}) where {A<:AffinePushfwd} = asℝ₊
320-
321-
function asparams(d::AffinePushfwd{N,M,T}, ::StaticSymbol{:μ}) where {N,M,T<:AbstractArray}
322-
as(Array, asℝ, size(d.μ))
323-
end
324-
325-
function asparams(d::AffinePushfwd{N,M,T}, ::StaticSymbol{:σ}) where {N,M,T<:AbstractArray}
326-
as(Array, asℝ, size(d.σ))
327-
end
328-
329320
function Base.rand(rng::Random.AbstractRNG, ::Type{T}, d::AffinePushfwd) where {T}
330321
z = rand(rng, T, parent(d))
331322
f = getfield(d, :f)
@@ -336,8 +327,8 @@ end
336327
insupport(d.parent, inverse(d.f)(x))
337328
end
338329

339-
@inline function Distributions.cdf(d::AffinePushfwd, x)
340-
cdf(parent(d), inverse(d.f)(x))
330+
@inline function MeasureBase.smf(d::AffinePushfwd, x)
331+
smf(parent(d), inverse(d.f)(x))
341332
end
342333

343334
@inline function mean(d::AffinePushfwd)
@@ -364,3 +355,67 @@ end
364355
@inline function std(d::AffinePushfwd{(:μ, :λ)})
365356
std(parent(d)) / d.λ
366357
end
358+
359+
###############################################################################
360+
# smf
361+
362+
@inline function smf(d::AffinePushfwd{(:μ,)}, x)
363+
f = getfield(d, :f)
364+
smf(parent(d), inverse(f)(x))
365+
end
366+
367+
@inline function smf(d::AffinePushfwd{(:μ, :σ)}, x)
368+
f = getfield(d, :f)
369+
p = smf(parent(d), inverse(f)(x))
370+
d.σ > 0 ? p : one(p) - p
371+
end
372+
373+
@inline function smf(d::AffinePushfwd{(:σ,)}, x)
374+
f = getfield(d, :f)
375+
p = smf(parent(d), inverse(f)(x))
376+
d.σ > 0 ? p : one(p) - p
377+
end
378+
379+
@inline function smf(d::AffinePushfwd{(:λ,)}, x)
380+
f = getfield(d, :f)
381+
p = smf(parent(d), inverse(f)(x))
382+
d.λ > 0 ? p : one(p) - p
383+
end
384+
385+
@inline function smf(d::AffinePushfwd{(:μ, :λ)}, x)
386+
f = getfield(d, :f)
387+
p = smf(parent(d), inverse(f)(x))
388+
d.λ > 0 ? p : one(p) - p
389+
end
390+
391+
###############################################################################
392+
# invsmf
393+
394+
@inline function invsmf(d::AffinePushfwd{(:μ,)}, p)
395+
f = getfield(d, :f)
396+
f(invsmf(parent(d), p))
397+
end
398+
399+
@inline function invsmf(d::AffinePushfwd{(:μ, :σ)}, p)
400+
p = d.σ > 0 ? p : one(p) - p
401+
f = getfield(d, :f)
402+
f(invsmf(parent(d), p))
403+
end
404+
405+
@inline function invsmf(d::AffinePushfwd{(:σ,)}, p)
406+
p = d.σ > 0 ? p : one(p) - p
407+
f = getfield(d, :f)
408+
f(invsmf(parent(d), p))
409+
end
410+
411+
@inline function invsmf(d::AffinePushfwd{(:λ,)}, p)
412+
p = d.λ > 0 ? p : one(p) - p
413+
f = getfield(d, :f)
414+
f(invsmf(parent(d), p))
415+
end
416+
417+
@inline function invsmf(d::AffinePushfwd{(:μ, :λ)}, p)
418+
p = d.λ > 0 ? p : one(p) - p
419+
f = getfield(d, :f)
420+
f(invsmf(parent(d), p))
421+
end

0 commit comments

Comments
 (0)