Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log density with proportionality in ADVI drops more than constant #2518

Open
yao-yl opened this issue Apr 26, 2018 · 2 comments
Open

Log density with proportionality in ADVI drops more than constant #2518

yao-yl opened this issue Apr 26, 2018 · 2 comments

Comments

@yao-yl
Copy link
Collaborator

yao-yl commented Apr 26, 2018

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

if (msg2.str().length() > 0)

            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

@syclik
Copy link
Member

syclik commented Apr 26, 2018 via email

@bob-carpenter
Copy link
Contributor

The problem seems to be that there are calls from within ADVI that use double values, so all the constants get dropped. The reason to fix this is to make our interfaces uniform and to make these things usable on the outside. The reason not to is that it'll be slower if it's currently being called with double values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants