Skip to content

Commit 4a5eb0c

Browse files
authored
Merge branch 'main' into predict
2 parents 01b6acf + cc6439e commit 4a5eb0c

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
@@ -63,6 +63,47 @@ should hold for generative models `m` and arbitrary `obs`.
6363
"""
6464
function condition end
6565

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

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

0 commit comments

Comments
 (0)