Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.42.1

`InitFromParams(mode_estimate)`, where `mode_estimate` was obtained from an optimisation on a Turing model, now accepts a second optional argument which provides a fallback initialisation strategy if some parameters are missing from `mode_estimate`.

This also means that you can now invoke `returned(model, mode_estimate)` to calculate a model's return values given the parameters in `mode_estimate`.

# 0.42.0

## DynamicPPL 0.39
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Turing"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.42.0"
version = "0.42.1"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
14 changes: 10 additions & 4 deletions src/optimisation/Optimisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,18 @@ function Base.show(io::IO, m::ModeResult)
end

"""
InitFromParams(m::ModeResult)
InitFromParams(
m::ModeResult,
fallback::Union{AbstractInitStrategy,Nothing}=InitFromPrior()
)

Initialize a model from the parameters stored in a `ModeResult`.
Initialize a model from the parameters stored in a `ModeResult`. The `fallback` is used if
some parameters are missing from the `ModeResult`.
"""
function DynamicPPL.InitFromParams(m::ModeResult)
return DynamicPPL.InitFromParams(m.params)
function DynamicPPL.InitFromParams(
m::ModeResult, fallback::Union{DynamicPPL.AbstractInitStrategy,Nothing}=InitFromPrior()
)
return DynamicPPL.InitFromParams(m.params, fallback)
end

# Various StatsBase methods for ModeResult
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Combinatorics = "1"
Distributions = "0.25"
DistributionsAD = "0.6.3"
DynamicHMC = "2.1.6, 3.0"
DynamicPPL = "0.39"
DynamicPPL = "0.39.2"
FiniteDifferences = "0.10.8, 0.11, 0.12"
ForwardDiff = "0.10.12 - 0.10.32, 0.10, 1"
HypothesisTests = "0.11"
Expand Down
13 changes: 13 additions & 0 deletions test/optimisation/Optimisation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,19 @@ using Turing
@test chain[:σ][1] == mle.params[@varname(σ)]
end

@testset "returned on ModeResult" begin
@model function f()
x ~ Normal()
2.0 ~ Normal(x)
return x + 1.0
end
model = f()
result = maximum_a_posteriori(model)
@test returned(model, result) == result.params[@varname(x)] + 1.0
result = maximum_likelihood(model)
@test returned(model, result) == result.params[@varname(x)] + 1.0
end

# Issue: https://discourse.julialang.org/t/turing-mixture-models-with-dirichlet-weightings/112910
@testset "Optimization with different linked dimensionality" begin
@model demo_dirichlet() = x ~ Dirichlet(2 * ones(3))
Expand Down