Skip to content

Commit 9db5a94

Browse files
committed
Expand constraints docs
1 parent f5c0668 commit 9db5a94

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

docs/src/plugins/constraint_specification.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,42 @@ We can specify constraints over the first `toy_model` submodel using the followi
6969
end
7070
```
7171

72+
## Default constraints
73+
While we can specify constraints over all instances of a submodel at a specific layer of the hierarchy, we're not guaranteed to have all instances of a submodel at a specific layer of the hierarchy. To this extent, we can specify default constraints that apply to all instances of a specific submodel. For example, we can define the following model, where we have a `recursive_model` instance at every layer of the hierarchy:
74+
```@example constraints
75+
@model function recursive_model(n, x, y)
76+
z ~ Normal(x, y)
77+
if n > 0
78+
y ~ recursive_model(n = n - 1, x = x)
79+
else
80+
y ~ Normal(0, 1)
81+
end
82+
end
83+
```
84+
We can specify default constraints over the `recursive_model` submodel using the following code:
85+
```@example constraints
86+
GraphPPL.default_constraints(::typeof(recursive_model)) = @constraints begin
87+
q(x, y, z) = q(x)q(y)q(z)
88+
end
89+
```
90+
When a model of type `recursive_model` is now created, the default constraints will be applied to all instances of the `recursive_model` submodel. Note that default constraints are overwritten by constraints passed to the top-level model, if they concern the same instance of a submodel.
91+
92+
## Prespecified constraints
93+
`GraphPPL` provides a set of prespecified constraints that can be used to specify constraints over the variational posterior. These constraint sets are aliases for their corresponding equivalent constriant sets, and can be used for convenience. The following prespecified constraints are available:
94+
95+
```@docs
96+
GraphPPL.MeanField
97+
GraphPPL.BetheFactorization
98+
```
99+
100+
This means that we can write the following:
101+
```@example constraints
102+
@constraints begin
103+
q(x, y, z) = MeanField() # Equivalent to q(x, y, z) = q(x)q(y)q(z)
104+
q(a, b, c) = BetheFactorization() # Equivalent to q(a, b, c) = q(a, b, c), can be used to overwrite default constraints.
105+
end
106+
```
107+
72108
## Plugin's internals
73109

74110
```@docs
@@ -78,8 +114,6 @@ GraphPPL.SpecificSubModelConstraints
78114
GraphPPL.GeneralSubModelConstraints
79115
GraphPPL.FactorizationConstraint
80116
GraphPPL.FactorizationConstraintEntry
81-
GraphPPL.MeanField
82-
GraphPPL.BetheFactorization
83117
84118
GraphPPL.MarginalFormConstraint
85119
GraphPPL.MessageFormConstraint

0 commit comments

Comments
 (0)