acope3 / RibModelFramework

1 stars 14 forks source link

saving and loading MCMC object results in loss of first element #388

Open mikegilchrist opened 2 years ago

mikegilchrist commented 2 years ago

When working on testing routines R/testhat/testMCMCROC.R Elizabeth and I have run into the following behavior

> ## examine original mcmc object
> mcmc$getLogPosteriorTrace()
 [1]        0.0 -1214102.3 -1149896.9 -1091581.2 -1050189.8 -1018183.4
 [7]  -992014.6  -973346.5  -958094.0  -942493.0  -933180.1
> ## examine saved and reloaded version of `mcmc`
> mcmcSaved$getLogPosteriorTrace()
 [1] -1214102.3 -1149896.9 -1091581.2 -1050189.8 -1018183.4  -992014.6
 [7]  -973346.5  -958094.0  -942493.0  -933180.1

Note, this only seems to happen if we are using a newly created object. If we resave mcmcSaved the results are unaltered.

I suspect this has something to do with a non-zero initial_iterations, but am not sure.

acope3 commented 2 years ago

Following discussion with @mikegilchrist, we will modify src/MCMCAlgorithm.cpp to include the initial value of the logPosterior and logLikelihood in the traces. For concatenating traces via loadMCMCObject in R/mcmcObject.R, we will keep the initial value in the case of i = 1 (i.e. the first file provided), but skip over the initial logPosterior and logLikelihood values in the subsequent runs (i >= 2) because these should be the same as at the end of the previous run.