Skip to content

Commit cc6439e

Browse files
authored
Add fix and unfix functions for parameter fixing and unfixing (#109)
* Add fix() and unfix() functions for parameter fixing and unfixing * bump version and add export * add to doc * add sentence following Penny's comment
1 parent 82e1e4a commit cc6439e

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
33
keywords = ["probablistic programming"]
44
license = "MIT"
55
desc = "Common interfaces for probabilistic programming"
6-
version = "0.9.0"
6+
version = "0.10.0"
77

88
[deps]
99
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"

docs/src/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ string_to_varname
2929
AbstractProbabilisticProgram
3030
condition
3131
decondition
32+
fix
33+
unfix
3234
logdensityof
3335
AbstractContext
3436
evaluate!!

src/AbstractPPL.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export VarName,
1818

1919

2020
# Abstract model functions
21-
export AbstractProbabilisticProgram, condition, decondition, logdensityof, densityof, AbstractContext, evaluate!!
21+
export AbstractProbabilisticProgram, condition, decondition, fix, unfix, logdensityof, densityof, AbstractContext, evaluate!!
2222

2323
# Abstract traces
2424
export AbstractModelTrace

src/abstractprobprog.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,47 @@ should hold for generative models `m` and arbitrary `obs`.
6262
"""
6363
function condition end
6464

65+
"""
66+
fix(model, params)
67+
68+
Fix the values of parameters specified in `params` within the probabilistic model `model`.
69+
This operation is equivalent to treating the fixed parameters as being drawn from a point mass
70+
distribution centered at the values specified in `params`. Thus these parameters no longer contribute
71+
to the accumulated log density.
72+
73+
Conceptually, this is similar to Pearl's do-operator in causal inference, where we intervene
74+
on variables by setting them to specific values, effectively cutting off their dependencies
75+
on their usual causes in the model.
76+
77+
The invariant
78+
79+
```
80+
m == unfix(fix(m, params))
81+
```
82+
83+
should hold for any model `m` and parameters `params`.
84+
"""
85+
function fix end
86+
87+
88+
"""
89+
unfix(model)
90+
91+
Remove any fixed parameters from the model `model`, returning a new model without the fixed parameters.
92+
93+
This function reverses the effect of `fix` by removing parameter constraints that were previously set.
94+
It returns a new model where all previously fixed parameters are allowed to vary according to their
95+
original distributions in the model.
96+
97+
The invariant
98+
99+
```
100+
m == unfix(fix(m, params))
101+
```
102+
103+
should hold for any model `m` and parameters `params`.
104+
"""
105+
function unfix end
65106

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

0 commit comments

Comments
 (0)