vi.get_samples {BayesFluxR} | R Documentation |
Draw samples form a variational family.
Description
Draw samples form a variational family.
Usage
vi.get_samples(vi, n = 1)
Arguments
vi |
obtained using |
n |
number of samples |
Value
a matrix whose columns are draws from the variational posterior
Examples
## Not run:
## Needs previous call to `BayesFluxR_setup` which is time
## consuming and requires Julia and BayesFlux.jl
BayesFluxR_setup(installJulia=TRUE, seed=123)
net <- Chain(RNN(5, 1))
like <- likelihood.seqtoone_normal(net, Gamma(2.0, 0.5))
prior <- prior.gaussian(net, 0.5)
init <- initialise.allsame(Normal(0, 0.5), like, prior)
data <- matrix(rnorm(10*1000), ncol = 10)
# Choosing sequences of length 10 and predicting one period ahead
tensor <- tensor_embed_mat(data, 10+1)
x <- tensor[1:10, , , drop = FALSE]
# Last value in each sequence is the target value
y <- tensor[11,,]
bnn <- BNN(x, y, like, prior, init)
vi <- bayes_by_backprop(bnn, 100, 100)
vi_samples <- vi.get_samples(vi, n = 1000)
pp <- posterior_predictive(bnn, vi_samples)
## End(Not run)
[Package BayesFluxR version 0.1.3 Index]