Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fix and unfix functions for parameter fixing and unfixing #109

Merged
merged 4 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -62,6 +62,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
Loading