prep_saves {LDATS} | R Documentation |
Prepare and update the data structures to save the ptMCMC output
Description
prep_saves
creates the data structure used to save the
output from each iteration of the ptMCMC algorithm, which is added via
update_saves
. Once the ptMCMC is complete, the saved data objects
are then processed (burn-in iterations are dropped and the remaining
iterations are thinned) via process_saves
.
This set of functions was designed to work within TS
and
specifically est_changepoints
. They are still hardcoded to
do so, but have the capacity to be generalized to work with any
estimation via ptMCMC with additional coding work.
Usage
prep_saves(nchangepoints, control = list())
update_saves(i, saves, steps, swaps)
process_saves(saves, control = list())
Arguments
nchangepoints |
|
control |
A |
i |
|
saves |
The existing list of saved data objects. |
steps |
Chain configuration after within-temperature steps. |
swaps |
Chain configuration after among-temperature swaps. |
Value
list
of ptMCMC objects: change points ($cpts
),
log-likelihoods ($lls
), chain ids ($ids
), step acceptances
($step_accepts
), and swap acceptances ($swap_accepts
).
Examples
data(rodents)
document_term_table <- rodents$document_term_table
document_covariate_table <- rodents$document_covariate_table
LDA_models <- LDA_set(document_term_table, topics = 2)[[1]]
data <- document_covariate_table
data$gamma <- LDA_models@gamma
weights <- document_weights(document_term_table)
data <- data[order(data[,"newmoon"]), ]
saves <- prep_saves(1, TS_control())
inputs <- prep_ptMCMC_inputs(data, gamma ~ 1, 1, "newmoon", weights,
TS_control())
cpts <- prep_cpts(data, gamma ~ 1, 1, "newmoon", weights, TS_control())
ids <- prep_ids(TS_control())
for(i in 1:TS_control()$nit){
steps <- step_chains(i, cpts, inputs)
swaps <- swap_chains(steps, inputs, ids)
saves <- update_saves(i, saves, steps, swaps)
cpts <- update_cpts(cpts, swaps)
ids <- update_ids(ids, swaps)
}
process_saves(saves, TS_control())