You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To implement the state, we need to keep track of a couple of things:
107
+
-`index`: the index of the sampler used in this `step`.
108
+
-`transition`: the transition resulting from this `step`.
109
+
-`states`: the current states of _all_ the components.
110
+
Two aspects of this might seem a bit strange:
111
+
1. We need to keep track of the states of _all_ components rather than just the state for the sampler we used previously.
112
+
2. We need to put the `transition` from the `step` into the state.
113
+
The reason for (1) is that lots of samplers keep track of more than just the previous realizations of the variables, e.g. in `AdvancedHMC.jl` we keep track of the momentum used, the metric used, etc.
114
+
For (2) the reason is similar: some samplers might keep track of the variables _in the state_ differently, e.g. maybe the sampler is working in a transformed space but returns the samples in the original space, or maybe the sampler is even independent from the current realizations and the state is simply `nothing`. Hence, we need the `transition`, which should always contain the realizations, to make sure we can resume from the same point in the space in the next `step`.
115
+
```julia
116
+
struct MixtureState{T,S}
117
+
index::Int
118
+
transition::T
119
+
states::S
120
+
end
121
+
```
122
+
The `step` for a `MixtureSampler` is defined by the following generative process
123
+
```math
124
+
\begin{aligned}
125
+
i &\sim \mathrm{Categorical}(w_1, \dots, w_k) \\
126
+
X_t &\sim \mathcal{K}_i(\cdot \mid X_{t - 1})
127
+
\end{aligned}
128
+
```
129
+
where ``\mathcal{K}_i`` denotes the i-th kernel/sampler, and `w_i` denotes the weight/probability of choosing the i-th sampler.
130
+
[`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:
131
+
132
+
```julia
133
+
# Update the corresponding state, i.e. `state.states[i]`, using
134
+
# the state and transition from the previous iteration.
0 commit comments