Skip to content

Commit

Permalink
Merge branch 'main' into predict
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxd3 authored Oct 28, 2024
2 parents 01b6acf + cc6439e commit 4a5eb0c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uuid = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
keywords = ["probablistic programming"]
license = "MIT"
desc = "Common interfaces for probabilistic programming"
version = "0.9.0"
version = "0.10.0"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
2 changes: 2 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ string_to_varname
AbstractProbabilisticProgram
condition
decondition
fix
unfix
logdensityof
AbstractContext
evaluate!!
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export VarName,


# Abstract model functions
export AbstractProbabilisticProgram, condition, decondition, logdensityof, densityof, AbstractContext, evaluate!!
export AbstractProbabilisticProgram, condition, decondition, fix, unfix, logdensityof, densityof, AbstractContext, evaluate!!

# Abstract traces
export AbstractModelTrace
Expand Down
41 changes: 41 additions & 0 deletions src/abstractprobprog.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,47 @@ should hold for generative models `m` and arbitrary `obs`.
"""
function condition end

"""
fix(model, params)
Fix the values of parameters specified in `params` within the probabilistic model `model`.
This operation is equivalent to treating the fixed parameters as being drawn from a point mass
distribution centered at the values specified in `params`. Thus these parameters no longer contribute
to the accumulated log density.
Conceptually, this is similar to Pearl's do-operator in causal inference, where we intervene
on variables by setting them to specific values, effectively cutting off their dependencies
on their usual causes in the model.
The invariant
```
m == unfix(fix(m, params))
```
should hold for any model `m` and parameters `params`.
"""
function fix end


"""
unfix(model)
Remove any fixed parameters from the model `model`, returning a new model without the fixed parameters.
This function reverses the effect of `fix` by removing parameter constraints that were previously set.
It returns a new model where all previously fixed parameters are allowed to vary according to their
original distributions in the model.
The invariant
```
m == unfix(fix(m, params))
```
should hold for any model `m` and parameters `params`.
"""
function unfix end

"""
rand([rng=Random.default_rng()], [T=NamedTuple], model::AbstractProbabilisticProgram) -> T
Expand Down

0 comments on commit 4a5eb0c

Please sign in to comment.