@@ -108,8 +108,9 @@ greta_stash$numerical_messages <- c(
108
108
# ' argument `trace_batch_size` can be modified to trade-off speed against
109
109
# ' memory usage.
110
110
# '
111
- # ' @note to set a seed with MCMC you must use [tensorflow::set_random_seed()].
112
- # ' This is due to an internal API with tensorflow. See \url{https://github.com/greta-dev/greta/issues/559} for a thread exploring this.
111
+ # ' @note to set a seed with MCMC you can use [set.seed()], or
112
+ # ' [tensorflow::set_random_seed()]. They both given identical results. See
113
+ # ' examples below.
113
114
# '
114
115
# ' @return `mcmc`, `stashed_samples` & `extra_samples` - a
115
116
# ' `greta_mcmc_list` object that can be analysed using functions from the
@@ -183,6 +184,27 @@ greta_stash$numerical_messages <- c(
183
184
# ' m3 <- model(params)
184
185
# ' o <- opt(m3, hessian = TRUE)
185
186
# ' o$hessian
187
+ # '
188
+ # ' # using set.seed or tensorflow::set_random_seed to set RNG for MCMC
189
+ # ' a <- normal(0, 1)
190
+ # ' y <- normal(a, 1)
191
+ # ' m <- model(y)
192
+ # '
193
+ # ' set.seed(12345)
194
+ # ' one <- mcmc(m, n_samples = 1, chains = 1)
195
+ # ' set.seed(12345)
196
+ # ' two <- mcmc(m, n_samples = 1, chains = 1)
197
+ # ' # same
198
+ # ' all.equal(as.numeric(one), as.numeric(two))
199
+ # ' tensorflow::set_random_seed(12345)
200
+ # ' one_tf <- mcmc(m, n_samples = 1, chains = 1)
201
+ # ' tensorflow::set_random_seed(12345)
202
+ # ' two_tf <- mcmc(m, n_samples = 1, chains = 1)
203
+ # ' # same
204
+ # ' all.equal(as.numeric(one_tf), as.numeric(two_tf))
205
+ # ' # different
206
+ # ' all.equal(as.numeric(one), as.numeric(one_tf))
207
+ # '
186
208
# ' }
187
209
mcmc <- function (
188
210
model ,
0 commit comments