Skip to content

Commit 50d90d7

Browse files
authored
Dev (#193)
* Dirichlet(k::Integer, α) = Dirichlet(Fill(α, k)) * export TransformVariables as TV * drop redundant import * 0.0 => zero(Float64) * drop outdated Dists.logpdf * update StudentT * drop redundant import * update Uniform * bump MeasureBase version * reworking beta * small update to StudentT * basemeasure for discrete Distributions * using LogExpFunctions => import LogExpFunctions * quoteof(::Chain) * prettyprinting and chain-mucking * Some refactoring for Markov chains * import MeasureBase: ≪ * version bound for PrettyPrinting * copy(rng) might change its type (e.g. GLOBAL_RNG) * tests pass * cleaning up * more cleanup * big update * get tests passing * formatting * oops typo * move affine to MeasureTheory * updating * Val => StaticSymbol * more fixes * fix fix fix * more logdesnity => logdensity_def * more logdesnity fixes * debugging * formatting * bugfixes * working on tests * updates * working on tests * tests passing! * refactor * working on tests * drop static weight for now * fix sampling from ProductMeasure{<:Base.Generator} * tests passing!! * more stuff * constructor => constructorof * constructor =? construtorof * updates * working on tests * fix Dirichlet * update Bernoulli * working on tests * bugfixes for RealizedSamples * tests passing!! * tighten down inference * as(::PowerMeasure) * drop type-level stuff * using InverseFunctions.jl * update license * affero * copyright * update CI to 1.6 * xform => TV.as * oops missed a conflict * fix merge corruption * typo * fix license * Update README.md * merge * enumerate instead of zip * bugfix * inline rand * drop `static` from `insupport` results * update proxies * Move ConditionalMeasure to MeasureBase * IfElse.ifelse(p::Bernoulli, t, f) * IfElseMeasure * update some base measures * test broken :( * fix some redundancies * instance_type => Core.Typeof * update testvalue for Bernoulli and Binomial * un-break broken test (now passing) * Fall-back `For` method for when inference fails * drop extra spaces * more whitespace * bump MeasureBase dependency version * add newline * tidy up * ifelse tests * OEF newline * avoid type piracy * add Julia 1.7 to CI * make Julia 1.6 happy * approx instead of == * Require at least Julia 1.6 * Try Sebastian's idea test_measures ::Any[] * Another Any[] * Drop Likelihood test * drop 1.7 CI (seems buggy?) * bump version * export likelihood * Snedecor's F * Gamma distribution * more gamma stuff * Beroulli() * inverse Gaussian * Getting modifed GLM.jl tests to pass * drop pdf and logpdf * Poisson bugfix * update Normal(μ, σ²) * Gamma(μ, ϕ) for GLMs * updates for GLM support * start on truncated * update parameterized measures * drop FactoredBase * drop old LazyArrays dependency * insupport(::Distribution) * Left out"Dists." * don't export `ifelse` (#192) * Kleisli => TransitionKernel * depend on StatsBase * tests passing * bump MeasureBase version * work on truncated and censored * improve func_string * Simplify logdensity_def(::For, x) * Move truncated and censored updates to separate branches * newline * comment out in-progress stuff * newline * bump version * update formatting spec * more formatting * tweedie docs * drop redundant exports * update exports * omega => lambda * drop SequentialEx * get tests passing * add kernel tests * gitignore * better `Pretty.tile` for Affine and AffineTransforms * formatting * kleisli => kernel * update tile(::For) * update Compat version * bump MB version * update gamma * Let's come back to InverseGaussian * CI on 1.7 * update IfElse * formatting
1 parent d8210ef commit 50d90d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+563
-271
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ whitespace_ops_in_indices = false
66
remove_extra_newlines = true
77
import_to_using = false
88
pipe_to_function_call = false
9-
short_to_long_function_def = false
9+
short_to_long_function_def = true
1010
always_use_return = false
1111
whitespace_in_kwargs = true
1212
annotate_untyped_fields_with_any = false

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
matrix:
2424
version:
2525
- '1.6'
26+
- '1.7'
2627
os:
2728
- ubuntu-latest
2829
- macOS-latest

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@
99
/.vscode/
1010
/coverage
1111
coverage-lcov.info
12+
paper/paper.aux
13+
paper/paper.bbl
14+
paper/paper.blg
15+
paper/paper.fdb_latexmk
16+
paper/paper.fls
17+
paper/paper.log
18+
paper/paper.out
19+
paper/paper.synctex.gz

Project.toml

Lines changed: 7 additions & 8 deletions
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.15.1"
4+
version = "0.16.0"
55

66
[deps]
77
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
@@ -12,14 +12,12 @@ ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
1212
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
1313
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1414
DynamicIterators = "6c76993d-992e-5bf1-9e63-34920a5a5a38"
15-
FLoops = "cc61a311-1640-44b5-9fba-1b764f453329"
1615
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1716
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
1817
Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
1918
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2019
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
2120
KeywordCalls = "4d827475-d3e4-43d6-abe3-9688362ede9f"
22-
LazyArrays = "5078a376-72f3-5289-bfd5-ec5146d43c02"
2321
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
2422
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
2523
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
@@ -35,31 +33,31 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
3533
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
3634
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
3735
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
36+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
37+
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
3838
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
3939
TransformVariables = "84d833dd-6860-57f9-a1a7-6da5db126cff"
4040
Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"
4141

4242
[compat]
4343
Accessors = "0.1"
4444
ChangesOfVariables = "0.1"
45-
Compat = "3.35"
45+
Compat = "3.35, 4"
4646
ConcreteStructs = "0.2"
4747
ConstructionBase = "1.3"
4848
DensityInterface = "0.4"
4949
Distributions = "0.25"
5050
DynamicIterators = "0.4"
51-
FLoops = "0.2"
5251
FillArrays = "0.12, 0.13"
5352
IfElse = "0.1"
5453
Infinities = "0.1"
5554
InverseFunctions = "0.1"
5655
KeywordCalls = "0.2"
57-
LazyArrays = "0.21, 0.22"
5856
LogExpFunctions = "0.3.3"
5957
MLStyle = "0.4"
6058
MacroTools = "0.5"
6159
MappedArrays = "0.4"
62-
MeasureBase = "0.7"
60+
MeasureBase = "0.9"
6361
NamedTupleTools = "0.13, 0.14"
6462
NestedTuples = "0.3"
6563
PositiveFactorizations = "0.2"
@@ -68,7 +66,8 @@ Reexport = "1"
6866
SpecialFunctions = "1, 2"
6967
Static = "0.5, 0.6"
7068
StaticArrays = "1.3"
71-
StatsFuns = "0.9"
69+
StatsBase = "0.32, 0.33"
70+
StatsFuns = "0.9, 1"
7271
TransformVariables = "0.5, 0.6"
7372
Tricks = "0.1"
7473
julia = "1.6"

docs/src/affine.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ Here the `- logdet(σ)` is the "log absolute Jacobian", required to account for
6969

7070
The above requires solving a linear system, which adds some overhead. Even with the convenience of a lower triangular system, it's still not quite as efficient as multiplication.
7171

72-
In addition to the covariance ``Σ``, it's also common to parameterize a multivariate normal by its _precision matrix_, defined as the inverse of the covariance matrix, ``Ω = Σ⁻¹``. Similar to our use of ``σ`` for the lower Cholesky factor of `Σ`, we'll use ``ω`` for the lower Cholesky factor of ``Ω``.
72+
In addition to the covariance ``Σ``, it's also common to parameterize a multivariate normal by its _precision matrix_, defined as the inverse of the covariance matrix, ``Ω = Σ⁻¹``. Similar to our use of ``σ`` for the lower Cholesky factor of `Σ`, we'll use ``λ`` for the lower Cholesky factor of ``Ω``.
7373

7474
This parameterization enables more efficient calculation of the log-density using only multiplication and addition,
7575

7676
```julia
77-
logdensity_def(d::Normal{(:μ,:ω)}, x) = logdensity_def(d.ω * (x - d.μ)) + logdet(d.ω)
77+
logdensity_def(d::Normal{(:μ,:λ)}, x) = logdensity_def(d.λ * (x - d.μ)) + logdet(d.λ)
7878
```
7979

8080
## `AffineTransform`
8181

82-
Transforms like ``z → σ z + μ`` and ``z → ω \ z + μ`` can be specified in MeasureTheory.jl using an `AffineTransform`. For example,
82+
Transforms like ``z → σ z + μ`` and ``z → λ \ z + μ`` can be specified in MeasureTheory.jl using an `AffineTransform`. For example,
8383

8484
```julia
8585
julia> f = AffineTransform((μ=3.=2.))
@@ -91,11 +91,11 @@ julia> f(1.0)
9191

9292
In the univariate case this is relatively simple to invert. But if `σ` is a matrix, matrix inversion becomes necessary. This is not always possible as lower triangular matrices are not closed under matrix inversion and as such are not guaranteed to exist.
9393

94-
With multiple parameterizations of a given family of measures, we can work around these issues. The inverse transform of a ``(μ,σ)`` transform will be in terms of ``(μ,ω)``, and vice-versa. So
94+
With multiple parameterizations of a given family of measures, we can work around these issues. The inverse transform of a ``(μ,σ)`` transform will be in terms of ``(μ,λ)``, and vice-versa. So
9595

9696
```julia
9797
julia> f⁻¹ = inverse(f)
98-
AffineTransform{(:μ, :ω), Tuple{Float64, Float64}}((μ = -1.5, ω = 2.0))
98+
AffineTransform{(:μ, :λ), Tuple{Float64, Float64}}((μ = -1.5, λ = 2.0))
9999

100100
julia> f(f⁻¹(4))
101101
4.0

src/MeasureTheory.jl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
module MeasureTheory
22

33
using Random
4-
using FLoops
54

65
using MeasureBase
76
using MLStyle
87
using NestedTuples
98
import TransformVariables
109
const TV = TransformVariables
1110

12-
using TransformVariables: as, asℝ₊, as𝕀, asℝ
11+
using TransformVariables: asℝ₊, as𝕀, asℝ, transform
1312

1413
import Base
1514
import Distributions
1615
const Dists = Distributions
1716

1817
export TV
18+
export transform
1919
export
2020
export gentype
2121
export For
@@ -30,7 +30,7 @@ export CountingMeasure
3030
export TrivialMeasure
3131
export Likelihood
3232
export testvalue
33-
export basekleisli
33+
export basekernel
3434

3535
using Infinities
3636
using DynamicIterators
@@ -45,15 +45,14 @@ import LogExpFunctions
4545
import NamedTupleTools
4646
import InverseFunctions: inverse
4747
export inverse
48-
export ifelse
4948

5049
import MeasureBase: insupport, instance, marginals
5150
import MeasureBase:
5251
testvalue,
5352
logdensity_def,
5453
density_def,
5554
basemeasure,
56-
kleisli,
55+
kernel,
5756
params,
5857
paramnames,
5958
∫,
@@ -62,7 +61,13 @@ import MeasureBase:
6261
import MeasureBase:
6362
using MeasureBase: BoundedInts, BoundedReals, CountingMeasure, IntegerDomain, IntegerNumbers
6463
using MeasureBase: weightedmeasure, restrict
65-
using MeasureBase: AbstractKleisli
64+
using MeasureBase: AbstractTransitionKernel
65+
66+
import Statistics: mean, var, std
67+
68+
import MeasureBase: likelihood
69+
export likelihood
70+
export log_likelihood_ratio
6671

6772
using StaticArrays
6873

@@ -74,8 +79,8 @@ import Base: rand
7479

7580
using Reexport
7681
@reexport using MeasureBase
77-
import IfElse: ifelse
78-
@reexport using IfElse
82+
import IfElse
83+
using IfElse
7984

8085
using Tricks: static_hasmethod
8186

@@ -87,6 +92,7 @@ export AffineTransform
8792
export insupport
8893
export For
8994

95+
using MeasureBase: kernel
9096
using MeasureBase: Returns
9197
import MeasureBase: proxy, @useproxy
9298
import MeasureBase: basemeasure_depth
@@ -101,10 +107,6 @@ gentype(μ::AbstractMeasure) = typeof(testvalue(μ))
101107

102108
# gentype(μ::AbstractMeasure) = gentype(basemeasure(μ))
103109

104-
import Distributions: logpdf, pdf
105-
106-
export pdf, logpdf
107-
108110
xlogx(x::Number) = LogExpFunctions.xlogx(x)
109111
xlogx(x, y) = x * log(x)
110112

@@ -114,6 +116,8 @@ xlogy(x, y) = x * log(y)
114116
xlog1py(x::Number, y::Number) = LogExpFunctions.xlog1py(x, y)
115117
xlog1py(x, y) = x * log(1 + y)
116118

119+
as(args...; kwargs...) = TV.as(args...; kwargs...)
120+
117121
include("utils.jl")
118122
include("const.jl")
119123
include("combinators/for.jl")
@@ -126,7 +130,6 @@ include("combinators/weighted.jl")
126130
include("combinators/product.jl")
127131
include("combinators/transforms.jl")
128132
include("combinators/exponential-families.jl")
129-
130133
include("resettable-rng.jl")
131134
include("realized.jl")
132135
include("combinators/chain.jl")
@@ -151,6 +154,9 @@ include("parameterized/binomial.jl")
151154
include("parameterized/multinomial.jl")
152155
include("parameterized/lkj-cholesky.jl")
153156
include("parameterized/negativebinomial.jl")
157+
include("parameterized/gamma.jl")
158+
include("parameterized/snedecorf.jl")
159+
include("parameterized/inverse-gaussian.jl")
154160

155161
include("combinators/ifelse.jl")
156162

0 commit comments

Comments
 (0)