# NOT RUN {
# Simulate from a Normal Distribution, unknown location and known scale with uninformative prior
# Run sgmcmc step by step and calculate estimate of location on the fly to reduce storage
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)
sgnht = sgnhtSetup(logLik, dataset, params, stepsize)
nIters = 10^4L
# Initialize location estimate
locEstimate = 0
# Initialise TensorFlow session
sess = initSess(sgnht)
for ( i in 1:nIters ) {
sgmcmcStep(sgnht, sess)
locEstimate = locEstimate + 1 / nIters * getParams(sgnht, sess)$theta
}
# For more examples see vignettes
# }
Run the code above in your browser using DataLab