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

nan exception with variational inference #1559

Closed
wcbeard opened this issue Jul 20, 2015 · 3 comments
Closed

nan exception with variational inference #1559

wcbeard opened this issue Jul 20, 2015 · 3 comments
Milestone

Comments

@wcbeard
Copy link

wcbeard commented Jul 20, 2015

For the following model

data {
    int N;
    vector[N] p;
    int Ngrps;
    int<lower=1, upper=Ngrps> grp_index[N];
}
parameters {
    vector<lower=0.0001, upper=100>[Ngrps] sigmaGrp;
    vector<lower=-100, upper=1000>[Ngrps] muGrp;
}

model {
    int grpi;
    for (i in 1:N){
        grpi <- grp_index[i];
        p[i] ~ logistic(muGrp[grpi], sigmaGrp[grpi]);
    };
}

I'm trying to estimate group level parameters from the following data (I generated with python and saved data file test.R with pystan):

p = 63.1, 108.3, 1.0, 46.0, 22.9, 14.8, 28.8, 52.5, 60.1, 81.3
grp_index = [1, 1, 1, 1, 1, 1, 2, 3, 4, 5]

test_dat = dict(
    N=len(p),
    p=p,
    grp_index=grp_index,
    Ngrps=len(set(grp_index)),
)    

When I compile and sample with advi using

$ modeldir/model/test variational data file=modeldir/dat/test.R random seed=3021828106

I get the exception:

Exception: stan::variational::normal_meanfield::set_mu: Input vector[7] is nan, but must not be nan!
Diagnostic information: 
Dynamic exception type: std::domain_error
std::exception::what: stan::variational::normal_meanfield::set_mu: Input vector[7] is nan, but must not be nan!

This is a small dataset, and the error can be avoided if I run with most other random seeds, but I originally ran into this every time with a larger data set, that presumably has some groups only represented once in the grp_index array. I could get rid of those groups in the dataset, but wondered if this is a bug with the variational algorithm.

@bob-carpenter
Copy link
Contributor

Thanks for filing the issue. This is a known bug with the way
errors are currently being trapped, which is why it hasn't
been ported to RStan yet --- this would've crashed RStan if
we'd included it.

We should have this fixed (and a version in RStan) by the
next release.

  • Bob

On Jul 20, 2015, at 3:53 PM, Chris notifications@github.com wrote:

For the following model

data {
int N;
vector[N] p;
int Ngrps;
int<lower=1, upper=Ngrps> grp_index[N];
}
parameters {
vector<lower=0.0001, upper=100>[Ngrps] sigmaGrp;
vector<lower=-100, upper=1000>[Ngrps] muGrp;
}

model {
int grpi;
for (i in 1:N){
grpi <- grp_index[i];
p[i] ~ logistic(muGrp[grpi], sigmaGrp[grpi]);
};
}

I'm trying to estimate group level parameters from the following data (I generated with python and saved data file test.R with pystan):

p = 63.1, 108.3, 1.0, 46.0, 22.9, 14.8, 28.8, 52.5, 60.1, 81.3
grp_index = [1, 1, 1, 1, 1, 1, 2, 3, 4, 5]

test_dat = dict(
N=len(p),
p=p,
grp_index=grp_index,
Ngrps=len(set(grp_index)),
)

When I compile and sample with advi using

$ modeldir/model/test variational data file=modeldir/dat/test.R random seed=3021828106

I get the exception:

Exception: stan::variational::normal_meanfield::set_mu: Input vector[7] is nan, but must not be nan!
Diagnostic information:
Dynamic exception type: std::domain_error
std::exception::what: stan::variational::normal_meanfield::set_mu: Input vector[7] is nan, but must not be nan!

This is a small dataset, and the error can be avoided if I run with most other random seeds, but I originally ran into this every time with a larger data set, that presumably has some groups only represented once in the grp_index array. I could get rid of those groups in the dataset, but wondered if this is a bug with the variational algorithm.


Reply to this email directly or view it on GitHub.

@bgoodri
Copy link
Contributor

bgoodri commented Jul 20, 2015

Specifically it is #1544 and there is a pull request (that needs some work) for it. So, I think we can close this issue.

@bgoodri bgoodri closed this as completed Jul 20, 2015
@dustinvtran
Copy link
Member

Yup, hopefully when I have time later this week, I can repush some changes to the current pull request as it isn't working at the moment.

@syclik syclik modified the milestone: v2.9.0 Dec 4, 2015
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

5 participants