Skip to content

Commit

Permalink
Merge b72a963 into cc6439e
Browse files Browse the repository at this point in the history
  • Loading branch information
sethaxen authored Oct 28, 2024
2 parents cc6439e + b72a963 commit d1ab5bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
AbstractMCMC = "2, 3, 4, 5"
Accessors = "0.1"
DensityInterface = "0.4"
JSON = "0.19 - 0.21"
Random = "1.6"
StatsBase = "0.32, 0.33"
julia = "~1.6.6, 1.7.3"
26 changes: 26 additions & 0 deletions src/abstractprobprog.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using AbstractMCMC
using DensityInterface
using Random
using StatsBase


"""
Expand Down Expand Up @@ -121,3 +122,28 @@ end
function Base.rand(model::AbstractProbabilisticProgram)
return rand(Random.default_rng(), NamedTuple, model)
end

"""
predict(
[rng::AbstractRNG=Random.default_rng(),]
[T=NamedTuple,]
model::AbstractProbabilisticProgram,
params,
) -> T
Draw a sample from the predictive distribution specified by `model` with its parameters fixed to `params`.
The sample will be returned as format specified by `T`.
"""
function StatsBase.predict(rng::AbstractRNG, T::Type, model::AbstractProbabilisticProgram, params)
return rand(rng, T, fix(model, params))
end
function StatsBase.predict(T::Type, model::AbstractProbabilisticProgram, params)
return StatsBase.predict(Random.default_rng(), T, model, params)
end
function StatsBase.predict(model::AbstractProbabilisticProgram, params)
return StatsBase.predict(NamedTuple, model, params)
end
function StatsBase.predict(rng::AbstractRNG, T::Type, model::AbstractProbabilisticProgram, params)
return StatsBase.predict(rng, NamedTuple, model, params)
end

0 comments on commit d1ab5bc

Please sign in to comment.