Log density with proportionality in ADVI drops more than constant
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.8k
- Forks
- 388
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 15
Description
Summary:
Log density with proportionality in ADVI drops more than constant
Description:
According to stan C++ guidance (https://github.com/stan-dev/stan/wiki/Model-Concept), the log probability of a stan model, with or without proportionality, can be calculated from
template <bool propto, bool jacobian_adjust_transforms, typename T>
T
log_prob(std::vector<T>& params_r,
std::vector<int>& params_i,
std::ostream* msgs = 0)
const;
But I find the difference between the exact and proportional log density in Stan ADVI code is not a constant.
Reproducible Steps:
In order to calculate both the exact log density and proportional log density in the unconstrained space, and to print their difference, add these lines before
https://github.com/stan-dev/stan/blob/12f031565df6265356bdc4c6b191d8df619151f5/src/stan/variational/advi.hpp#L540
double log_p_exact=0;
double log_p_prop=0;
log_p_exact = model_.template log_prob<false, true>(cont_params_);
log_p_prop = model_.template log_prob<true, true>(cont_params_);
std::stringstream ss;
ss << "constant dropped="<<log_p_exact-log_p_prop<<"======";
std::cout<<ss.str();
Then we can make cmdstan and run the bernoulli example:
examples/bernoulli/bernoulli variational algorithm=meanfield iter=1000 output_samples=30 data file=examples/bernoulli/bernoulli.data.R
Current Output:
We should expect the output being a constant for all posterior draws, which stands for the log constant term in densities. But it is not. For instance here is the first 6 lines of the output:
constant dropped==-5.24628
constant dropped==-5.20678
constant dropped==-5.78415
constant dropped==-5.37678
constant dropped==-5.02283
constant dropped==-5.59698
I check that the exact log density ( model_.template log_prob<false, true> ) does return the log density plus jacobian.
Current Version:
v2.17.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/stan/variational/advi.hpp around the referenced line and reproduce the discrepancy with the bernoulli CmdStan variational command. Compare model_.log_prob<false, true> and model_.log_prob<true, true> across posterior draws; done means determining why their difference is not constant and correcting the ADVI behavior or documenting the confirmed explanation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100