Simulates from the posterior defined by the functions logLik and logPrior using stochastic gradient Langevin Dynamics with an improved gradient estimate using Control Variates. The function uses TensorFlow, so needs TensorFlow for python installed.

sgldcv(logLik, dataset, params, stepsize, optStepsize, logPrior = NULL,
minibatchSize = 0.01, nIters = 10^4L, nItersOpt = 10^4L,
verbose = TRUE, seed = NULL)

Arguments

logLik function which takes parameters and dataset (list of TensorFlow variables and placeholders respectively) as input. It should return a TensorFlow expression which defines the log likelihood of the model. list of numeric R arrays which defines the datasets for the problem. The names in the list should correspond to those referred to in the logLik and logPrior functions list of numeric R arrays which define the starting point of each parameter. The names in the list should correspond to those referred to in the logLik and logPrior functions list of numeric values corresponding to the SGLD stepsizes for each parameter The names in the list should correspond to those in params. Alternatively specify a single numeric value to use that stepsize for all parameters. numeric value specifying the stepsize for the optimization to find MAP estimates of parameters. The TensorFlow GradientDescentOptimizer is used. optional. Default uninformative improper prior. Function which takes parameters (list of TensorFlow variables) as input. The function should return a TensorFlow tensor which defines the log prior of the model. optional. Default 0.01. Numeric or integer value that specifies amount of dataset to use at each iteration either as proportion of dataset size (if between 0 and 1) or actual magnitude (if an integer). optional. Default 10^4L. Integer specifying number of iterations to perform. optional. Default 10^4L. Integer specifying number of iterations of initial optimization to perform. optional. Default TRUE. Boolean specifying whether to print algorithm progress optional. Default NULL. Numeric seed for random number generation. The default does not declare a seed for the TensorFlow session.

Value

Returns list of arrays for each parameter containing the MCMC chain. Dimension of the form (nIters,paramDim1,paramDim2,...)

Examples

# NOT RUN {
# Simulate from a Normal Distribution with uninformative prior
dataset = list("x" = rnorm(1000))
params = list("theta" = 0)
logLik = function(params, dataset) {
distn = tf$distributions$Normal(params$theta, 1) return(tf$reduce_sum(distn$log_prob(dataset$x)))
}
stepsize = list("theta" = 1e-4)
optStepsize = 1e-1
output = sgldcv(logLik, dataset, params, stepsize, optStepsize)
# }