Andrew Gelman
unread,Jun 21, 2014, 3:13:58 AM6/21/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to stan...@googlegroups.com
Hi all. Following my conversation with Bob the other day, here are a first draft of specs for the next rstan. Bob can connect me if I’ve garbled anything.
A
The logic will be to consider a sequence of files or objects:
foo.stan [Stan program: a text file]
foo.so [compiled model: a dynamic shared object that exists in the R workspace]
foo.rda [compiled model: stored as a file in the working directory for R, or maybe in a library directory of compiled Stan models]
foo.instantiated [instantiated model: I assume this is a dynamic shared object too, it is created by putting the data into the compiled model]
foo.adapt [adaptation information for 1 chain: a stan object of some sort]
foo.fit.single [fitted model for 1 chains: a stan object]
foo.fit.multiple [fitted model for multiple chains: a stan object that includes the simulations, R-hat, and n_eff, and the scramble code]
foo.fit.mle [fitted point estimate with cov matrix, conf intervals, possibly simulations]
And now the functions (I’ve tried to follow Bob’s principles here and keep the number of arguments to a minimum):
First, the sequence of primitives that lead to a fitted stan model:
foo.so <- stan_compile(“foo.stan”, boost_lib, eigen_lib, verbosity)
foo.instantiated <- stan_instantiate(foo.so, data, verbosity)
foo.adapt <- stan_adapt(foo.instantiated, algorithm(sub_arguments), init, seed, chain_id, n_warmup, verbosity)
foo.fit.single <- stan_simulate(foo.instantiated, foo.adapt, algorithm(sub_arguments), parameters_to_save, init, seed, chain_id, n_iter, verbosity)
foo.fit.multiple <- stan_combine(list(foo.fit.single.1,foo.fit.single.2,…), seed, verbosity)
Next, the primitives that do other things:
point.estimate <- stan_optimize(foo.instantiated, algorithm(sub_arguments), init, seed, verbosity)
log.prob <- stan_logprob(foo.instantiated, parameters, format)
gradient <- stan_gradient(foo.instantiated, parameters, format)
hessian <- stan_hessian(foo.instantiated, parameters, format)
In the above 3 functions, the “format” argument tells whether these are on the original or transformed scale, also they could be supplied as a list of named parameters or as a vector with all of them strung together.
parameters_new <- stan_transform(foo.instantiated, parameters) to transform forward and back
Next, the make function:
stan_make (“foo.stan”, data, file_save)
This creates (if necessary) the compiled model foo.so in the R workspace, and, if file_save=TRUE, also saves it as foo.rda. If data are supplied, this function call also creates (if necessary) the instantiated model and saves it as foo.instantiated in the R workspace. This function can also have a bunch of optional arguments telling it what directory to use and what names to call the R object and the files.
And, finally, the user-facing functions:
foo.fit.multiple <- stan(“foo.stan”, algorithm(sub_arguments), parallelism, parameters_to_save, init, seed, n_iter, n_warmup, thin, n_chains, verbosity)
foo.fit.mle <- stan(“foo.stan”, algorithm(sub_arguments), parameters_to_save, init, seed, verbosity)
and various extractor functions, for example:
sims <- stan_sims(foo.fit.multiple)
diagnostics <- stan_diagnostics(foo.fit.multiple)
estimates <- stan_estimate(foo.fit.mle)
stderrs <- stan_se(foo.fit.mle)
sims <- stan_sims(foo.fit.mle, algorithm(sub_arguments)), here the algorithm could be normal approx, stabilized importance sampling, or wedge sampling
I’m probably missing a few things but the above is the basic idea.