{"action":"opened","issue":{"url":"https://api.github.com/repos/stan-dev/stan/issues/1559","labels_url":"https://api.github.com/repos/stan-dev/stan/issues/1559/labels{/name}","comments_url":"https://api.github.com/repos/stan-dev/stan/issues/1559/comments","events_url":"https://api.github.com/repos/stan-dev/stan/issues/1559/events","html_url":"https://github.com/stan-dev/stan/issues/1559","id":96144971,"number":1559,"title":"nan exception with variational inference","user":{"login":"d10genes","id":379413,"avatar_url":"https://avatars.githubusercontent.com/u/379413?v=3","gravatar_id":"","url":"https://api.github.com/users/d10genes","html_url":"https://github.com/d10genes","followers_url":"https://api.github.com/users/d10genes/followers","following_url":"https://api.github.com/users/d10genes/following{/other_user}","gists_url":"https://api.github.com/users/d10genes/gists{/gist_id}","starred_url":"https://api.github.com/users/d10genes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/d10genes/subscriptions","organizations_url":"https://api.github.com/users/d10genes/orgs","repos_url":"https://api.github.com/users/d10genes/repos","events_url":"https://api.github.com/users/d10genes/events{/privacy}","received_events_url":"https://api.github.com/users/d10genes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-20T19:53:00Z","updated_at":"2015-07-20T19:53:00Z","closed_at":null,"body":"For the following model\r\n\r\n    data {\r\n        int N;\r\n        vector[N] p;\r\n        int Ngrps;\r\n        int<lower=1, upper=Ngrps> grp_index[N];\r\n    }\r\n    parameters {\r\n        vector<lower=0.0001, upper=100>[Ngrps] sigmaGrp;\r\n        vector<lower=-100, upper=1000>[Ngrps] muGrp;\r\n    }\r\n\r\n    model {\r\n        int grpi;\r\n        for (i in 1:N){\r\n            grpi <- grp_index[i];\r\n            p[i] ~ logistic(muGrp[grpi], sigmaGrp[grpi]);\r\n        };\r\n    }\r\n\r\nI'm trying to estimate group level parameters from the following data (I generated with python and saved data file test.R with pystan):\r\n\r\n    p = 63.1, 108.3, 1.0, 46.0, 22.9, 14.8, 28.8, 52.5, 60.1, 81.3\r\n    grp_index = [1, 1, 1, 1, 1, 1, 2, 3, 4, 5]\r\n\r\n    test_dat = dict(\r\n        N=len(p),\r\n        p=p,\r\n        grp_index=grp_index,\r\n        Ngrps=len(set(grp_index)),\r\n    )    \r\n\r\nWhen I compile and sample with advi using     \r\n\r\n    $ modeldir/model/test variational data file=modeldir/dat/test.R random seed=3021828106\r\n\r\nI get the exception:\r\n\r\n    Exception: stan::variational::normal_meanfield::set_mu: Input vector[7] is nan, but must not be nan!\r\n    Diagnostic information: \r\n    Dynamic exception type: std::domain_error\r\n    std::exception::what: stan::variational::normal_meanfield::set_mu: Input vector[7] is nan, but must not be nan!\r\n\r\nThis 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."}}