Description Usage Arguments Value Author(s) References See Also Examples
The function zvcv
is used to perform (regularised) ZVCV given a set of samples, derivatives and function evaluations.
1 2 3 4 5 6 7 8 9 10 11 
integrand 
An N by k matrix of integrands (evaluations of the functions of interest) 
samples 
An N by d matrix of samples from the target 
derivatives 
An N by d matrix of derivatives of the log target with respect to the parameters 
log_weights 
(optional) A vector of length N containing log weights of the samples. The default is equal weights. 
integrand_logged 
(optional) Sometimes it is better to input the integrand on the logged scale for stability. If the actual integrand is the exponential of 
est_inds 
(optional) A vector of indices for the estimationonly samples. The default when 
options 
A list of control variate specifications. This can be a single list containing the elements below (the defaults are used for elements which are not specified). Alternatively, it can be a list of lists containing any or all of the elements below. Where the latter is used, the function

folds 
The number of folds used in kfold crossvalidation for selecting the optimal control variate. Depending on the 
A list is returned, containing the following components:
expectation
: The estimates of the expectations.
num_select
: The number of nonzero coefficients in the polynomial.
mse
: The mean square error for the evaluation set.
coefs
: The estimated coefficients for the regression (columns are for the different integrands).
integrand_logged
: The integrand_logged
input stored for reference.
est_inds
: The est_inds
input stored for reference.
polyorder
: The polyorder
value used in the final estimate.
regul_reg
: The regul_reg
flag used in the final estimate.
alpha_elnet
: The alpha_elnet
value used in the final estimate.
nfolds
: The nfolds
value used in the final estimate.
apriori
: The apriori
vector used in the final estimate.
intercept
: The intercept
flag used in the final estimate.
polyorder_max
: The polyorder_max
flag used in the final estimate, if multiple options
are specified.
Leah F. South
Mira, A., Solgi, R., & Imparato, D. (2013). Zero variance Markov chain Monte Carlo for Bayesian estimators. Statistics and Computing, 23(5), 653662.
South, L. F., Oates, C. J., Mira, A., & Drovandi, C. (2019). Regularised zero variance control variates for highdimensional variance reduction. https://arxiv.org/abs/1811.05073
See ZVCV and VDP
for additional examples. See evidence
for functions which use zvcv
to estimate the normalising constant of the posterior.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48  # An example where ZVCV can result in zerovariance estimators
# Estimating some expectations when theta is bivariate normally distributed with:
mymean < c(1.5,1.5)
mycov < matrix(c(1,0.5,0.5,2),nrow=2)
# Perfect draws from the target distribution (could be replaced with
# approximate draws from e.g. MCMC or SMC)
N < 30
require(mvtnorm)
set.seed(1)
samples < rmvnorm(N, mean = mymean, sigma = mycov)
# derivatives of Gaussian wrt x
derivatives < t( apply(samples,1,function(x) solve(mycov)%*%(x  mymean)) )
# The integrands are the marginal posterior means of theta, the variances and the
# covariance (true values are c(1.5,1.5,1,2,0.5))
integrand < cbind(samples[,1],samples[,2],(samples[,1]  mymean[1])^2,
(samples[,2]  mymean[2])^2, (samples[,1]  mymean[1])*(samples[,2]  mymean[2]))
# Estimates without ZVCV (i.e. vanilla Monte Carlo integration)
# Vanilla Monte Carlo
sprintf("%.15f",colMeans(integrand))
# ZVCV with fixed specifications
# For this example, polyorder = 1 with OLS is exact for the first two integrands and
# polyorder = 2 with OLS is exact for the last three integrands
# ZVCV with 2nd order polynomial, OLS and a polynomial based on only x_1.
# For diagonal mycov, this would be exact for the first and third expectations.
sprintf("%.15f",zvcv(integrand, samples, derivatives,
options = list(polyorder = 2, regul_reg = FALSE, apriori = 1))$expectation)
# ZVCV with 1st order polynomial and OLS (exact for the first two integrands)
sprintf("%.15f",zvcv(integrand, samples, derivatives,
options = list(polyorder = 1, regul_reg = FALSE))$expectation)
# ZVCV with 2nd order polynomial and OLS (exact for all)
sprintf("%.15f",zvcv(integrand, samples, derivatives,
options = list(polyorder = 2, regul_reg = FALSE))$expectation)
# ZVCV with cross validation
myopts < list(list(polyorder = Inf, regul_reg = FALSE),list(polyorder = Inf, nfolds = 4))
temp < zvcv(integrand,samples,derivatives,options = myopts, folds = 2)
temp$polyorder # The chosen control variate order
temp$regul_reg # Flag for if the chosen control variate uses regularisation
# Crossval ZVCV to choose the polynomial order and whether to perform OLS or LASSO
sprintf("%.15f",temp$expectation) # Estimate based on the chosen control variate

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.