Learn R Programming

ZVCV (version 1.0.0)

VDP: Example of estimation using SMC

Description

This example illustrates how ZV-CV can be used for post-processing of results from SMC. In particular, we use ZV-CV to estimate posterior expectations and the evidence for a single SMC run of this example based on the Van der Pol oscillatory differential equations (Van der Pol, 1926). Further details about this example and applications to ZV-CV can be found in Oates et al. (2017) and South et al. (2019).

Given that the focus of this R package is on ZV-CV, we assume that samples have already been obtained from SMC and put into the correct format. One could use the R package RcppSMC or implement their own sampler in order to obtain results like this. The key is to make sure the derivatives of the log likelihood and log prior are stored, along with the inverse temperatures.

Usage

data(VDP)

Arguments

Format

A list containing the following :

N

The size of the SMC population

rho

The tolerance for the new temperatures, which are selected so that the CESS at each temperature is \(\rho*N\) where \(N\) is the population size.

temperatures

A vector of length \(T\) of inverse power posterior temperatures

samples

An \(N\) by \(d\) by \(T\) matrix of samples from the \(T\) power posteriors, where \(d\) is the dimension of the target distribution. The samples are transformed to be on the log scale and all derivatives are with respect to log samples.

loglike

An \(N\) by \(T\) matrix of log likelihood values corresponding to samples

logprior

An \(N\) by \(T\) matrix of log prior values corresponding to samples

der_loglike

An \(N\) by \(d\) by \(T\) matrix of the derivatives of the log likelihood with respect to the parameters, with parameter values corresponding to samples

der_logprior

An \(N\) by \(d\) by \(T\) matrix of the derivatives of the log prior with respect to the parameters, with parameter values corresponding to samples

References

Oates, C. J., Girolami, M. & Chopin, N. (2017). Control functionals for Monte Carlo integration. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 79(3), 695-718.

South, L. F., Oates, C. J., Mira, A., & Drovandi, C. (2019). Regularised zero-variance control variates for high-dimensional variance reduction.

Van der Pol, B. (1926). On relaxation-oscillations. The London, Edinburgh and Dublin Philosophical Magazine and Journal of Science, 2(11), 978-992.

See Also

See ZVCV for more package details.

Examples

Run this code
# NOT RUN {
set.seed(1)

# Load the SMC results
data(VDP) 

# Set up the list of control variates to choose from 
options <- list()
# Vanilla Monte Carlo
options[[1]] <- list(polyorder = 0)
# Standard ZV-CV with polynomial order selected through cross-validation
options[[2]] <- list(polyorder = Inf, regul_reg = FALSE)

##############################
# Posterior expectation - The true expectation is 0.9852 to 4 decimal places
##############################

# Note the exp() because samples and derivatives were stored on the log scale
# but we are interested in the expectation on the original scale
posterior <- zvcv(exp(VDP$samples[,,8]), VDP$samples[,,8],
VDP$der_loglike[,,8] + VDP$der_logprior[,,8], options = options) 
posterior$expectation # The posterior expectation estimate
posterior$polyorder # The selected polynomial order

##############################
# Evidence estimation - The true logged evidence is 10.36 to 2 decimal places
##############################

# }
# NOT RUN {
# Getting additional temperatures based on maintaing a CESS of 0.99N rather than 0.9N
temp <- Expand_Temperatures(VDP$temperatures, VDP$loglike, 0.99)
VDP$temperatures_new <- temp$temperatures_all # the new temperatures
VDP$most_recent <- temp$relevant_samples # the samples associated with the new temperatures
# }
# NOT RUN {
# }
# NOT RUN {
# Evidence estimation using the SMC identity
Z_SMC <- evidence_SMC(VDP$samples, VDP$loglike, VDP$der_loglike, VDP$der_logprior,
VDP$temperatures, VDP$temperatures_new, VDP$most_recent, options = options)
Z_SMC$log_evidence

# Evidence estimation using the CTI identity
Z_CTI <- evidence_CTI(VDP$samples, VDP$loglike, VDP$der_loglike, VDP$der_logprior,
VDP$temperatures, VDP$temperatures_new, VDP$most_recent, options = options)
Z_CTI$log_evidence_PS2
# }

Run the code above in your browser using DataLab