Skip to content

Commit 21f4d56

Browse files
committed
improved MixtureState example
1 parent bce436d commit 21f4d56

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

docs/src/api.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ i &\sim \mathrm{Categorical}(w_1, \dots, w_k) \\
126126
X_t &\sim \mathcal{K}_i(\cdot \mid X_{t - 1})
127127
\end{aligned}
128128
```
129-
where ``\mathcal{K}_i`` denotes the i-th kernel/sampler, and `w_i` denotes the weight/probability of choosing the i-th sampler.
129+
where ``\mathcal{K}_i`` denotes the i-th kernel/sampler, and ``w_i`` denotes the weight/probability of choosing the i-th sampler.
130130
[`AbstractMCMC.updatestate!!`](@ref) comes into play in defining/computing ``\mathcal{K}_i(\cdot \mid X_{t - 1})`` since ``X_{t - 1}`` could be coming from a different sampler. If we let `state` be the current `MixtureState`, `i` the current component, and `i_prev` is the previous component we sampled from, then this translates into the following piece of code:
131131

132132
```julia
@@ -160,7 +160,7 @@ function AbstractMCMC.step(rng, model::AbstractMCMC.AbstractModel, sampler::Mixt
160160

161161
# Take a `step` for this sampler using the updated state.
162162
transition, state_current = AbstractMCMC.step(
163-
rng, model, sampler_current, sampler_state;
163+
rng, model, sampler_current, state_current;
164164
kwargs...
165165
)
166166

@@ -204,7 +204,7 @@ function AbstractMCMC.step(rng, model::AbstractMCMC.AbstractModel, sampler::Mixt
204204
end
205205
```
206206

207-
To use `MixtureSampler`, one could then do something like
207+
To use `MixtureSampler` with two samplers `sampler1` and `sampler2` as components, we'd simply do
208208

209209
```julia
210210
sampler = MixtureSampler((0.1, 0.9), (sampler1, sampler2))
@@ -214,3 +214,4 @@ while ...
214214
end
215215
```
216216

217+
As a final note, there is one potential issue we haven't really addressed in the above implementation: a lot of samplers have their own implementations of `AbstractMCMC.AbstractModel` which means that we would also have to ensure that all the different samplers we are using would be compatible with the same model. A very easy way to fix this would be to just add a struct called `ManyModels` supporting `getindex`, e.g. `models[i]` would return the i-th `model`, and then the above `step` would just extract the `model` corresponding to the current sampler. This issue should eventually disappear as the community moves towards a unified approach to implement `AbstractMCMC.AbstractModel`.

0 commit comments

Comments
 (0)