@bgoodri and @jonah: I’m at the point where I need your help.

I’m on branch: `feature/stan-services`

in RStan. Here’s what I’m doing to build it:

```
R CMD build StanHeaders/
R CMD INSTALL StanHeaders_*.tar.gz
cd rstan
make build; make install
```

Below is what I’ve done to test all of it. It all works, at calling the C++, but we need to get the writers in place so that we get samples pushed through to the stan fit object.

```
library(rstan)
stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'
mod <- stan_model(model_code = stancode)
smwd <- new("stanmodel_with_data", model = mod, data = list(y_mean = 2))
init = list(); seed = 1; id = 0; init_radius = 2
## diagnose
smwd@model$diagnose(init, seed, id, init_radius, 1e-6, 1e-6)
## optimize
smwd@model$optimize_bfgs(init, seed, id, init_radius, 0.001, 1e-12, 10000, 1e-8, 10000000, 1e-8, 2000, 1, 10)
smwd@model$optimize_lbfgs(init, seed, id, init_radius, 5, 0.001, 1e-12, 10000, 1e-8, 10000000, 1e-8, 2000, 1, 10)
smwd@model$optimize_newton(init, seed, id, init_radius, 2000, 1)
smwd@model$sample_fixed_param(init, seed, id, init_radius, 1000, 1, 100)
## sample
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; max_depth = 10
smwd@model$sample_hmc_nuts_dense_e(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, max_depth)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; max_depth = 10; delta = 0.8; gamma = 0.05; kappa = 0.75; t0 = 10; init_buffer = 75; term_buffer = 50; window = 25
smwd@model$sample_hmc_nuts_dense_e_adapt(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, max_depth, delta, gamma, kappa, t0, init_buffer, term_buffer, window)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; max_depth = 10;
smwd@model$sample_hmc_nuts_diag_e(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, max_depth)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; max_depth = 10; delta = 0.8; gamma = 0.05; kappa = 0.75; t0 = 10; init_buffer = 75; term_buffer = 50; window = 25
smwd@model$sample_hmc_nuts_diag_e_adapt(init, seed, id, init_radius,num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, max_depth, delta, gamma, kappa, t0, init_buffer, term_buffer, window)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; max_depth = 10;
smwd@model$sample_hmc_nuts_unit_e(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, max_depth)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; delta = 0.8; gamma = 0.05; kappa = 0.75; t0 = 10;
smwd@model$sample_hmc_nuts_unit_e_adapt(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, max_depth, delta, gamma, kappa, t0)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; int_time = 2 * pi
smwd@model$sample_hmc_static_dense_e(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, int_time)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; int_time = 2 * pi; delta = 0.8; gamma = 0.05; kappa = 0.75; t0 = 10; init_buffer = 75; term_buffer = 50; window = 25
smwd@model$sample_hmc_static_dense_e_adapt(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0, init_buffer, term_buffer, window)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0;
smwd@model$sample_hmc_static_diag_e(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, int_time)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; int_time = 2 * pi; delta = 0.8; gamma = 0.05; kappa = 0.75; t0 = 10; init_buffer = 75; term_buffer = 50; window = 25;
smwd@model$sample_hmc_static_diag_e_adapt(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0, init_buffer, term_buffer, window)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; int_time = 2 * pi;
smwd@model$sample_hmc_static_unit_e(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, int_time)
num_warmup = 1000; num_samples = 1000; num_thin = 1; save_warmup = 0; refresh = 100; stepsize = 1; stepsize_jitter = 0; int_time = 2 * pi; delta = 0.8; gamma = 0.05; kappa = 0.75; t0 = 10;
smwd@model$sample_hmc_static_unit_e_adapt(init, seed, id, init_radius, num_warmup, num_samples, num_thin, save_warmup, refresh, stepsize, stepsize_jitter, int_time, delta, gamma, kappa, t0)
##experimental: variational
grad_samples = 1; elbo_samples = 100; max_iterations = 10000; tol_rel_obj = 0.01; eta = 1.0; adapt_engaged = 1; adapt_iterations = 50; eval_elbo = 100; output_samples = 1000
smwd@model$experimental_advi_fullrank(init, seed, id, init_radius, grad_samples, elbo_samples, max_iterations, tol_rel_obj, eta, adapt_engaged, adapt_iterations, eval_elbo, output_samples)
smwd@model$experimental_advi_meanfield(init, seed, id, init_radius, grad_samples, elbo_samples, max_iterations, tol_rel_obj, eta, adapt_engaged, adapt_iterations, eval_elbo, output_samples)
```

The remaining items that we need to deal with:

- setting up writers so the values get back to R
- getting the defaults from Stan into the right parameters
- wish: change the level of the functions so they apply to
`smwd`

directly and not on`smwd@model`

. Is that possible? (so`smwd@sample_hmc_nuts_dense_e_adapt(...)`

instead of`smwd@model$sample_hmc_nuts_dense_e_adapt(...)`