Skip to content

Commit

Permalink
Merge pull request ReactiveBayes#20 from biaslab/dev_addons
Browse files Browse the repository at this point in the history
Add addons
  • Loading branch information
bvdmitri authored Dec 21, 2022
2 parents a7b6aea + c243baa commit 5df9e47
Show file tree
Hide file tree
Showing 17 changed files with 3,816 additions and 446 deletions.
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ Rocket = "df971d30-c9d6-4b37-b8ff-e965b2cb3a40"
TupleTools = "9d95972d-f1c8-5527-a6e0-b4b365fa01f6"

[compat]
Distributions = "0.25"
DataStructures = "0.18"
Distributions = "0.25"
DomainSets = "0.5.2, 0.6"
GraphPPL = "3.1.0"
MacroTools = "0.5.6"
Optim = "1.0.0"
ProgressMeter = "1.0.0"
ReactiveMP = "~3.2.0"
ReactiveMP = "~3.3.0"
Reexport = "1.2.0"
Rocket = "1.6.0"
TupleTools = "1.2.0"
julia = "1.6"

Expand All @@ -37,10 +36,10 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
BenchmarkCI = "20533458-34a3-403d-a444-e18f38190b5b"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Coverage = "a2441757-f6aa-5fb2-8edb-039e3f45d037"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ makedocs(;
"Overview" => "manuals/inference/overview.md",
"Static dataset" => "manuals/inference/inference.md",
"Real-time dataset / reactive inference" => "manuals/inference/rxinference.md",
"Inference results postprocessing" => "manuals/inference/postprocess.md",
"Manual inference specification" => "manuals/inference/manual.md"
]
],
Expand Down
2 changes: 1 addition & 1 deletion docs/src/manuals/inference/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ For manual inference specification see the [Manual Inference](@ref user-guide-ma
```@docs
inference
InferenceResult
```
```
14 changes: 14 additions & 0 deletions docs/src/manuals/inference/postprocess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# [Inference results postprocessing](@id user-guide-inference-postprocess)

Both [`inference`](@ref) and [`rxinference`](@ref) allow users to postprocess
the inference result with the `postprocess = ...` keyword argument. The inference engine
operates on __wrapper__ types to distinguish between marginals and messages. By default
these wrapper types are removed from the inference results if no addons option is present.
Together with the enabled addons, however, the wrapper types are preserved in the
inference result output value. Use the options below to change this behaviour:

```@docs
DefaultPostprocess
UnpackMarginalPostprocess
NoopPostprocess
```
8 changes: 7 additions & 1 deletion examples/.meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ return [
description = "This example implements one of the Gamma mixture experiments outlined in https://biaslab.github.io/publication/mp-based-inference-in-gmm/ .",
hidden = false
),
(
path = "Universal Mixtures.ipynb",
title = "Universal Mixtures",
description = "Universal mixture modeling.",
hidden = false
),
(
path = "Global Parameter Optimisation.ipynb",
title = "Global Parameter Optimisation",
Expand Down Expand Up @@ -192,5 +198,5 @@ return [
title = "Tiny Benchmark",
description = "Tiny Benchmark for Internal testing.",
hidden = true
)
),
]
161 changes: 7 additions & 154 deletions examples/Active Inference Mountain car.ipynb

Large diffs are not rendered by default.

266 changes: 228 additions & 38 deletions examples/Infinite Data Stream.ipynb

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
ReactiveMP = "a194aa59-28ba-4574-a09c-4a745416d6e3"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Rocket = "df971d30-c9d6-4b37-b8ff-e965b2cb3a40"
RxInfer = "86711068-29c9-4ff7-b620-ae75d7495b3d"
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Expand Down
441 changes: 225 additions & 216 deletions examples/Tiny Benchmark.ipynb

Large diffs are not rendered by default.

3,018 changes: 3,018 additions & 0 deletions examples/Universal Mixtures.ipynb

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion scripts/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,15 @@ function Base.run(examplesrunner::ExamplesRunner)
# Check if example failed with an error
# TODO: we might have better heurstic here? But I couldn't find a way to tell `Weave.jl` if an error has occured
# TODO: try to improve this later
if !isnothing(findnext("```\nError:", mdtext, 1))
erroridx = findnext("```\nError:", mdtext, 1)
if !isnothing(erroridx)
@error "`Error` block found in the `$(mdpath)` example. Check the logs for more details."
# We print a part of the file, which (hopefully) should be enough to identify the issue
# For more logs check the actual output
errwindow = 500 # We need to iterate over the text with `prevind` and `nextind`, because strings are UTF8
errstart = reduce((idx, _) -> max(firstindex(mdtext), prevind(mdtext, idx)), 1:errwindow; init = first(erroridx))
errend = reduce((idx, _) -> min(lastindex(mdtext), nextind(mdtext, idx)), 1:errwindow; init = last(erroridx))
@error "Part of the error message:\n\n$(mdtext[errstart:errend])\n"
error(-1)
end

Expand Down
12 changes: 12 additions & 0 deletions src/constraints/form/form_point_mass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ function default_point_mass_form_constraint_optimizer(::Type{Univariate}, ::Type
end
end

function default_point_mass_form_constraint_optimizer(::Type{Univariate}, ::Type{Discrete}, constraint::PointMassFormConstraint, distribution)

# fetch probvec
p = probvec(distribution)

# create new probvec
p_new = zeros(length(p))
p_new[argmax(p)] = 1

return PointMass(p_new)
end

function default_point_mass_form_constraint_boundaries(::Type{Univariate}, ::Type{Continuous}, constraint::PointMassFormConstraint, distribution)
support = Distributions.support(distribution)
lower = Distributions.minimum(support)
Expand Down
Loading

0 comments on commit 5df9e47

Please sign in to comment.