stan-dev / stan-dev/rstan

get_inits not working with vb output

Open
#515 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

Summary:

Please provide a short summary (no more than a sentence or two).

get_inits is not working correctly for the output of vb on at least one of the example models.

Description:

Describe the issue as clearly as possible.

The output of get_inits applied to vb output does not match the declared parameter dimensions of the model. A simple script that reproduces the problem is below. Note that the output of get_inits has the wrong dimension for sigma, and cannot be passed to unconstrain_pars, whereas the same commands work for ordinary sampling.

Reproducible Steps:

Please report steps to reproduce the issue. If it's not possible to reproduce, please include a description of how you discovered the issue.

If you have a reproducible example, please include it.

library(rstan)
options(mc.cores=4)

rstan_options(auto_write=TRUE)

# In example-models/ARM/Ch.17 on your local computer
setwd("/home/rgiordan/Documents/git_repos/example-models/ARM/Ch.17")
model <- stan_model("17.4_multilevel_logistic.stan")

# Load the data and hyperparameters.
stan_data <- new.env()
source("17.4_multilevel_logistic.data.R", local=stan_data)
stan_data <- as.list(stan_data)

num_samples <- 1000
chains <- 1
sampling_result <- sampling(model, data=stan_data, chains=chains, iter=num_samples)
advi_result <- vb(model, data=stan_data, iter=num_samples)

draw_list <- get_inits(sampling_result, iter=1)[[1]]
length(draw_list$sigma) # should be 1, and is 1
unconstrain_pars(sampling_result, draw_list) # Works as expected

vb_draw_list <- get_inits(advi_result, iter=1)
length(vb_draw_list$sigma)  # should be 1, and is 93
unconstrain_pars(advi_result, vb_draw_list) # fails with the message:
# Error in object@.MISC$stan_fit_instance$unconstrain_pars(pars) : 
#  mismatch in number dimensions declared and found in context; processing stage=initialization; variable 
# name=sigma; dims declared=(); dims found=(93)
Current Output:

If applicable, any relevant output from RStan.

Should be clear from the above example.

Expected Output:

If applicable, the output you expected from RStan.

Should be clear from the above example.

RStan Version:

The version of RStan you are running (e.g., from packageVersion("rstan"))

2.17.3

R Version:

The version of R you are running (e.g., from R.version.string)

R version 3.4.4 (2018-03-15)

Operating System:

Your operating system (e.g., OS X 10.11.3)

Ubuntu 16.04

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided R reproduction with example-models/ARM/Ch.17/17.4_multilevel_logistic.stan, comparing get_inits output from sampling and vb. Trace how get_inits handles vb_draw_list and check the sigma dimensions passed to unconstrain_pars; done means vb output matches the declared dimensions and unconstrain_pars succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.