Skip to content

Commit 41ccea4

Browse files
authored
Dev (#30)
* some refactoring * pretty printing * some updates for resettablerng * deepcopy on iterate * Move ResettableRNG to MeasureTheory * Make Pretty a const * drop extra spaces * formatting * formatting * formatting * add DensityInterface dependency * faster `rootmeasure` * updates * primitive measure docs * get tests passing * cleaning up * formatting * drop some unneeded methods * update for DensityInterface * updating densities to DensityInterface approach * update domains * moving things around * updates to IntegerBounds * more domain mucking * fix some exports * update deps * update `using` * working on tests * Working toward tests passing * some refactoring * working on tests * cleaning up * get tests to pass * tests passing * update logdensity_def for pointwise product * PrettyPrinting + tests * speed up `rootmeasure` * oops didn't mean to include that * tile(::FactoredBase) * Update Half and FactoredBase * drop exp.jl * simplify basemeasure * drop old `include` * drop redundant method * update compat Returns * add AbstractDensity * Move Affine to MeasureTheory * drop some old `For` code * update counting measure * add testvalue(::Type{T}) * bugfix * some dispatch adjustments * simplify show * formatting * transformed measures * ZeroSets * using LinearAlgebra, Statistics * working on MeasureTheory tests * updates * updates * typo * update default to mimic Base * fix tile(::Lebesgue) * Add test_interface function * small doc update * DensityKind(::Likelihood) * fixing show(::Likelihood) * adding some docs * update `rand` method * drop old integration code * add `rebase` * export rebase * law for ⊗ * typo * Make Likelihood more flexible * update kernel methods * add Likelihood method (avoid stack overflow) * refactoring * compat * Maybe Comat just works? * refactoring * some new stuff * working on tests * update powermeasure combinator * bugfix * comment out debugging lines * more refactoring * test @inferred basemeasure_depth(μ) * drop `constructor` (just use ConstructionBase.constructorof`) * debugging * update help * update interface * make tests harder * fixes * Dirac bugfix * formatting * improve type inference * working on type inference * update interface * udpates * get test passing * @test !isabstracttype(typejoin(...)) * work on show methods * update CI * remove old code * update productmeasure * prettyprinting stuff * Drop te @constprop :aggressive stuff (maybe don't need it?) * nerline * dropping some old code * update tbasemeasure_type(::PowerMeasure) * moar tests * update SpikeMixture * update superpose type parameter name * drop old tests * func_string * more updates * getting closer * almost there! * generated function for type stability * tests passing! * newline * more fixes * exports and bugfix * insupport(μ::Counting{T}, x) where {T<:Type} * working on MeasureTheory tests * MeasureTheory tests passing * drop some old code * inlining * improve inference * update `tile(::For)` * tighten down infrerence * update basemeasure(::For) for generators * loosen type bound on instance_type * drop debugging code * small update for Likelihood, and a test * fixing up likelihoods * improve `basemeasure_depth` dispatch * still some trouble with inferred basemeasure_depth * clean up `For` dispatch * simplify _logdensityof * optimize for Returns{True} case * rework basemeasure_depth * aggressive tests passing!! * drop type-level stuff * drop help * license * affero * copyright notice
1 parent 917304d commit 41ccea4

Some content is hidden

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

45 files changed

+68202
-1341
lines changed

.JuliaFormatter.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
indent = 4
2+
margin = 92
3+
always_for_in = true
4+
whitespace_typedefs = false
5+
whitespace_ops_in_indices = false
6+
remove_extra_newlines = true
7+
import_to_using = false
8+
pipe_to_function_call = false
9+
short_to_long_function_def = false
10+
always_use_return = false
11+
whitespace_in_kwargs = true
12+
annotate_untyped_fields_with_any = false
13+
format_docstrings = false
14+
align_struct_field = true
15+
align_conditional = true
16+
align_assignment = true
17+
align_pair_arrow = true
18+
conditional_to_if = true
19+
normalize_line_endings = "unix"
20+
align_matrix = false

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
version:
15-
- '1.3'
1615
- '1.6'
16+
- '1.7'
1717
- 'nightly'
1818
os:
1919
- ubuntu-latest

COPYRIGHT

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Copyright (c) 2022 Informative Prior, LLC
2+
Copyright (c) 2022 Chad Scherrer
3+
4+
This program is offered under a commercial and under the AGPL license.
5+
For commercial licensing, contact us. For AGPL licensing, see below.
6+
7+
AGPL licensing:
8+
This program is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Affero General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU Affero General Public License for more details.
17+
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>.
20+
21+
This file incorporates work covered by the following copyright and
22+
permission notice:
23+
24+
MIT License
25+
26+
Copyright (c) 2020-2021 Chad Scherrer <[email protected]> and contributors
27+
28+
Permission is hereby granted, free of charge, to any person obtaining a copy
29+
of this software and associated documentation files (the "Software"), to deal
30+
in the Software without restriction, including without limitation the rights
31+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32+
copies of the Software, and to permit persons to whom the Software is
33+
furnished to do so, subject to the following conditions:
34+
35+
The above copyright notice and this permission notice shall be included in all
36+
copies or substantial portions of the Software.
37+
38+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
44+
SOFTWARE.
45+

LICENSE

Lines changed: 661 additions & 21 deletions
Large diffs are not rendered by default.

Project.toml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,31 @@ authors = ["Chad Scherrer <[email protected]> and contributors"]
44
version = "0.5.1"
55

66
[deps]
7-
ConcreteStructs = "2569d6c7-a4a2-43d3-a901-331e8e4be471"
7+
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
88
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
9+
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
910
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
10-
KeywordCalls = "4d827475-d3e4-43d6-abe3-9688362ede9f"
1111
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1212
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
13-
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
1413
MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
1514
PrettyPrinting = "54e16d92-306c-5ea0-a30b-337be88ac337"
1615
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
16+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
17+
Static = "aedffcd0-7271-4cad-89d0-dc628f76c6d3"
18+
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
19+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1720
Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775"
1821

1922
[compat]
20-
ConcreteStructs = "0.2"
23+
Compat = "3.35"
2124
ConstructionBase = "1.3"
25+
DensityInterface = "0.4"
2226
FillArrays = "0.12"
23-
KeywordCalls = "0.2"
2427
LogExpFunctions = "0.3"
25-
MLStyle = "0.4"
2628
MappedArrays = "0.4"
2729
PrettyPrinting = "0.3"
30+
Reexport = "1"
31+
Static = "0.4"
2832
Tricks = "0.1"
2933
julia = "1.3"
3034

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
[![Build Status](https://github.com/cscherrer/MeasureBase.jl/workflows/CI/badge.svg)](https://github.com/cscherrer/MeasureBase.jl/actions)
66
[![Coverage](https://codecov.io/gh/cscherrer/MeasureBase.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/cscherrer/MeasureBase.jl)
77

8+
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
9+
810
This package is a lightweight version of [MeasureTheory](https://github.com/cscherrer/MeasureTheory.jl). It contains only the basic functionalities needed to define and use measures.

src/MeasureBase.jl

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,112 @@ const logtwo = log(2.0)
44

55
using Random
66
import Random: rand!
7+
import Random: gentype
8+
using Statistics
9+
using LinearAlgebra
10+
11+
import DensityInterface: logdensityof
12+
import DensityInterface: densityof
13+
import DensityInterface: DensityKind
14+
using DensityInterface
15+
16+
import ConstructionBase
17+
using ConstructionBase: constructorof
18+
19+
using PrettyPrinting
20+
const Pretty = PrettyPrinting
721

822
using FillArrays
9-
using ConcreteStructs
10-
using MLStyle
23+
using Static
1124

1225
export
13-
export sampletype
26+
export gentype
27+
export rebase
1428

1529
export AbstractMeasure
1630

1731
abstract type AbstractMeasure end
1832

19-
import PrettyPrinting
33+
using Static: @constprop
2034

21-
const Pretty = PrettyPrinting
35+
function Pretty.tile(d::M) where {M<:AbstractMeasure}
36+
the_names = fieldnames(typeof(d))
37+
result = Pretty.literal(repr(M))
38+
isempty(the_names) && return result * Pretty.literal("()")
39+
Pretty.list_layout(Pretty.tile.([getfield(d, n) for n in the_names]); prefix=result)
40+
end
2241

23-
sampletype::AbstractMeasure) = typeof(testvalue(μ))
42+
@inline DensityKind(::AbstractMeasure) = HasDensity()
2443

25-
# sampletype(μ::AbstractMeasure) = sampletype(basemeasure(μ))
44+
gentype::AbstractMeasure) = typeof(testvalue(μ))
2645

27-
export logdensity
46+
# gentype(μ::AbstractMeasure) = gentype(basemeasure(μ))
47+
48+
export logdensity_def
2849
export basemeasure
29-
export basekernel
50+
export basekleisli
3051

3152
using LogExpFunctions: logsumexp
3253

3354
"""
34-
logdensity(μ::AbstractMeasure{X}, x::X)
55+
logdensity_def(μ::AbstractMeasure{X}, x::X)
3556
3657
Compute the logdensity of the measure μ at the point x. This is the standard way
3758
to define `logdensity` for a new measure. the base measure is implicit here, and
3859
is understood to be `basemeasure(μ)`.
3960
4061
Methods for computing density relative to other measures will be
4162
"""
42-
function logdensity end
43-
44-
if VERSION < v"1.7.0-beta1.0"
45-
@eval begin
46-
struct Returns{T}
47-
value::T
48-
end
63+
function logdensity_def end
4964

50-
(f::Returns)(x) = f.value
51-
end
52-
end
65+
using Compat
5366

54-
include("kernel.jl")
67+
include("proxies.jl")
68+
include("kleisli.jl")
5569
include("parameterized.jl")
56-
include("combinators/mapsto.jl")
5770
include("combinators/half.jl")
58-
include("exp.jl")
5971
include("domains.jl")
72+
include("primitive.jl")
6073
include("utils.jl")
6174
include("absolutecontinuity.jl")
62-
include("macros.jl")
6375

64-
include("primitive.jl")
6576
include("primitives/counting.jl")
6677
include("primitives/lebesgue.jl")
6778
include("primitives/dirac.jl")
6879
include("primitives/trivial.jl")
6980

81+
include("combinators/bind.jl")
82+
include("combinators/transformedmeasure.jl")
7083
include("combinators/factoredbase.jl")
7184
include("combinators/weighted.jl")
7285
include("combinators/superpose.jl")
7386
include("combinators/product.jl")
7487
include("combinators/for.jl")
7588
include("combinators/power.jl")
76-
include("combinators/affine.jl")
7789
include("combinators/spikemixture.jl")
7890
include("combinators/likelihood.jl")
7991
include("combinators/pointwise.jl")
8092
include("combinators/restricted.jl")
8193
include("combinators/smart-constructors.jl")
94+
include("combinators/conditional.jl")
8295

8396
include("rand.jl")
8497

8598
include("density.jl")
99+
module Interface
86100

87-
end
101+
using Reexport
102+
using MeasureBase
103+
using MeasureBase:basemeasure_depth, proxy
104+
@reexport using Test
105+
106+
export test_interface
107+
export basemeasure_depth
108+
export proxy
109+
110+
include("interface.jl")
111+
end # module Interface
112+
113+
using .Interface
114+
115+
end # module MeasureBase

0 commit comments

Comments
 (0)