stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.59k stars 369 forks source link

Problems when setting parameter limits in simple cases #1504

Closed steven-murray closed 9 years ago

steven-murray commented 9 years ago

I have a weird problem.

When I generate normally distributed mock data, supposedly people's heights, I use this model:

    data {
        int N; //number of data points
        real x[N]; //height data
    }
    parameters {
        real<lower=0> mu;
        real<lower=0> std;
    }
    model {
        x ~ normal(mu,std);
    }

But it gives this error when running samples:

terminate called after throwing an instance of 'std::domain_error'
what():  stan::prob::normal_log: Location parameter is inf, but must be finite!
Abort trap: 6

If I don't have the <lower=0> for the mu parameter, it runs fine. In this case, it doesn't really make a difference in the end if I leave it out, but I still find it very strange. Any idea why this could be happening? I get this problem when using PyStan on either Mac OsX or Ubuntu.

When I print out values of mu and std during iterations, I find that two successive iterations have the same value, and then something ridiculous is chosen (like mu=inf or sometimes mu=1e229), which I assume has to do with numerical error in the gradient?

bob-carpenter commented 9 years ago

Do you have a reproducible example for some data x?

I verified that it's not a problem with Stan, at least in RStan:

> prog <- "data { int N; real x[N]; } parameters { real<lower=0> mu; real<lower=0> sigma; } model { x ~ normal(mu,sigma); }"

> N <- 100

> x <- rnorm(N, 5.5, 0.5)

> fit <- stan(model_code=prog, data=c("N", "x"))

> print(fit)
Inference for Stan model: prog.
4 chains, each with iter=2000; warmup=1000; thin=1; 
post-warmup draws per chain=1000, total post-warmup draws=4000.

       mean se_mean   sd  2.5%   25%   50%   75% 97.5% n_eff Rhat
mu     5.51    0.00 0.05  5.42  5.48  5.51  5.54  5.60  2452    1
sigma  0.44    0.00 0.03  0.39  0.42  0.44  0.46  0.51  2156    1
lp__  32.99    0.03 1.00 30.25 32.61 33.28 33.71 33.96  1175    1

In general, we'd recommend priors on both mu and sigma to ensure that the posterior's proper. It shouldn't be a problem in this example if you have more than two data points for x that aren't the same.

On Jun 18, 2015, at 5:34 AM, Steven Murray notifications@github.com wrote:

I have a weird problem.

When I generate normally distributed mock data, supposedly people's heights, I use this model:

data {
    int N; //number of data points
    real x[N]; //height data
}
parameters {
    real<lower=0> mu;
    real<lower=0> std;
}
model {
    x ~ normal(mu,std);
}

But it gives this error when running samples:

terminate called after throwing an instance of 'std::domain_error' what(): stan::prob::normal_log: Location parameter is inf, but must be finite! Abort trap: 6

If I don't have the for the mu parameter, it runs fine. In this case, it doesn't really make a difference in the end if I leave it out, but I still find it very strange. Any idea why this could be happening? I get this problem when using PyStan on either Mac OsX or Ubuntu.

— Reply to this email directly or view it on GitHub.

steven-murray commented 9 years ago

Hi Bob,

Thanks for your reply. Here's my full working pystan program for reference:

import numpy as np
import pystan
import pickle
from hashlib import md5

#Don't worry about this its just the caching of the code
def stan_cache(model_code, model_name=None, dir=""):
    """Use just as you would `StanModel`"""
    code_hash = md5(model_code.encode('ascii')).hexdigest()
    if model_name is None:
        cache_fn = dir + 'cached-model-{}.pkl'.format(code_hash)
    else:
        cache_fn = dir + 'cached-{}-{}.pkl'.format(model_name, code_hash)
    try:
        sm = pickle.load(open(cache_fn, 'rb'))
    except:
        sm = pystan.StanModel(model_code=model_code)
        with open(cache_fn, 'wb') as f:
            pickle.dump(sm, f)
    else:
        print("Using cached StanModel")
    return sm

model = """
    data {
        int N; //number of data points
        real x[N]; //Data
        int debug; //Toggle debugging
    }
    parameters {
        real<lower=0> mu;
        real<lower=0> std;
    }
    model {
        if(debug>1) print("x: ", x);
        x ~ normal(mu,std);
        if(debug>0) print("mu, std, lp: ", mu," ",std, " ", get_lp());
    }
"""

#THE FOLLOWING IS THE CODE
if __name__ == "__main__":
    # Define the distribution
    mu = 1.8
    std = 0.2
    debug = 1

    # Create mock data
    data = np.random.normal(mu, std, size=40)
    print "mean, std: ", np.mean(data), np.std(data)
    print "min, max: ", np.min(data), np.max(data)
    print data

    # Setup Stan object
    data_dict = {"N":len(data),
                 "x":data,
                 "debug":debug}
    M = stan_cache(model_code=model, dir="simulation/stanCache/")

    # Do the sampling
    fit = M.sampling(data=data_dict, iter=1000, warmup=200, chains=1)
    print fit

Having just run it, I get the following output:

mean, std:  1.79912702184 0.168615334265
min, max:  1.37571602512 2.27626915985
[ 1.70111141  1.66939592  1.81352635  1.70462197  1.81692876  1.83537786
  1.56401468  1.82081866  1.7476216   1.85338689  1.7180552   1.68483402
  1.90805181  2.27626916  1.98753559  1.86491373  1.84767332  1.44795185
  1.54916086  1.88962943  2.09640825  1.86566779  1.55268145  1.91474707
  1.80278735  1.63484793  1.76550669  1.82178918  1.77834417  1.7920206
  1.88573401  1.75209283  2.05958794  1.99866976  1.99120389  1.37571603
  1.79380661  1.87401399  1.70892489  1.79965134] # <--- THE DATA I USED!
Using cached StanModel
mu, std, lp: 0.466976 0.2 -900.464 #<-- NOTE, same as next line...
mu, std, lp: 0.466976 0.2 -900.464 #<--- NOTE, same as previous line...
mu, std, lp: 7.11887e+134 0.2 -2.53392e+272 <-- NOTE, crazy values!
mu, std, lp: 0.466976 0.2 -900.464
mu, std, lp: 5.9427e+135 0.2 -1.76578e+274
mu, std, lp: 0.466976 0.2 -900.464
mu, std, lp: 1.95571e+33 0.2 -1.9124e+69
mu, std, lp: 0.466976 0.2 -900.464
mu, std, lp: 1.182e+08 0.2 -6.98557e+18
mu, std, lp: 0.466976 0.2 -900.464
mu, std, lp: 52.0734 0.2 -1.26376e+06
mu, std, lp: 0.466976 0.2 -900.464
mu, std, lp: 1.6001 0.2 -31.8372
Iteration:   1 / 1000 [  0%]  (Warmup) (Chain 0)
mu, std, lp: 0.466976 0.2 -900.464
mu, std, lp: 1.57854 0.2 -36.288
mu, std, lp: 1.57532 0.2 -36.9484
mu, std, lp: 21.1472 0.2 -187184
mu, std, lp: 1.57854 0.2 -36.288
terminate called after throwing an instance of 'std::domain_error'
  what():  stan::prob::normal_log: Location parameter is inf, but must be finite!
Abort trap: 6

I hope that makes things a bit more clear...

I also just tried your example (had to get Rstan set up first, but it seems to be working). I get very similar errors. So, just to be clear, I run the following:

prog <- "data { int N; real x[N]; } parameters { real<lower=0> mu; real<lower=0> sigma; } model { print(mu); print(sigma); x ~ normal(mu,sigma); }"
N<-100
x<-rnorm(100,1.8,0.2)
fit<-stan(model_code=prog,data=c("N","x"),chains=1)
print(fit)

Though it would seem clear that this is probably not about the data itself, for completion, the data generated was

  [1] 1.761284 1.930586 2.241595 1.642869 2.153253 1.653787 1.455835 1.449923 1.442179 1.484588 1.832982
 [12] 1.571020 1.931932 1.926399 1.480587 1.534197 1.584152 1.931132 2.241716 1.759768 1.817335 2.026592
 [23] 1.672885 1.853471 1.881422 1.785274 1.709694 1.633035 1.492166 1.565077 1.849872 2.121320 2.185442
 [34] 1.772569 1.888035 1.526460 1.958919 1.959744 1.544289 1.502391 1.647825 2.223417 1.516528 1.969358
 [45] 2.034885 1.876006 1.754031 1.408685 1.867123 2.352696 1.952763 1.511535 1.688733 1.815875 1.994664
 [56] 1.801293 1.897570 1.840546 1.796892 2.065086 1.897444 1.504593 1.948574 1.907096 1.670944 1.559161
 [67] 1.925603 1.908491 1.505382 1.862516 1.784340 1.924685 1.873087 1.842244 1.588550 1.908729 1.932409
 [78] 2.095017 1.807417 1.859346 1.775032 1.514854 1.600258 1.775150 1.831566 1.919390 2.162588 1.911475
 [89] 1.421646 1.591651 1.839322 1.783013 2.092320 1.963195 1.815046 1.729378 1.622455 1.687426 1.935269
[100] 1.945803

I've run this through several times, sometimes printing out the parameters during iterations, sometimes not. It has run right through twice, but all the rest of the times (5 or 6 more) it has failed with

Error in sampler$call_sampler(args_list[[i]]) : 
  c++ exception (unknown reason)
error occurred during calling the sampler; sampling not done

When printing out parameters, it is clear that it is the same problem as in pystan. When running without the <lower=0> on mu, it ran right through the three times I tried it when using 1 chain. However, when using 2 chains, it runs through the first chain fine, but chokes with the same problem on the second chain early on. I'm beginning to think this is not a conceptual problem, but a technical one....

I'm using R 3.1.2 with Rstudio 0.99, and just did a fresh install of rstan, so I'm assuming it's whatever the latest version is. This is all on Mac OSX 10.7.5.

bob-carpenter commented 9 years ago

Thanks --- that's really helpful. Let me see if I can recreate the issue in CmdStan, where I'll have a hope of tracking it down.

On Jun 19, 2015, at 1:13 AM, Steven Murray notifications@github.com wrote:

Hi Bob,

Thanks for your reply. Here's my full working pystan program for reference:

import numpy as np import pystan import pickle from hashlib import md5

Don't worry about this its just the caching of the code

def stan_cache(model_code, model_name=None, dir=""): """Use just as you would StanModel""" code_hash = md5(model_code.encode('ascii')).hexdigest() if model_name is None: cache_fn = dir + 'cached-model-{}.pkl'.format(code_hash) else: cache_fn = dir + 'cached-{}-{}.pkl'.format(model_name, code_hash) try: sm = pickle.load(open(cache_fn, 'rb')) except: sm = pystan.StanModel(model_code=model_code) with open(cache_fn, 'wb') as f: pickle.dump(sm, f) else: print("Using cached StanModel") return sm

model = """ data { int N; //number of data points real x[N]; //Data int debug; //Toggle debugging } parameters { real mu; real std; } model { if(debug>1) print("x: ", x); x ~ normal(mu,0.2); if(debug>0) print("mu, std, lp: ", mu," ",0.2, " ", get_lp()); } """

THE FOLLOWING IS THE CODE

if name == "main":

Define the distribution

mu = 1.8
std = 0.2
debug = 1
# Create mock data
data = np.random.normal(mu, std, size=40)
print "mean, std: ", np.mean(data), np.std(data)
print "min, max: ", np.min(data), np.max(data)
print data

# Setup Stan object
data_dict = {"N":len(data),
             "x":data,
             "debug":debug}
M = stan_cache(model_code=model, dir="simulation/stanCache/")

# Do the sampling
fit = M.sampling(data=data_dict, iter=1000, warmup=200, chains=1)
print fit

Having just run it, I get the following output:

mean, std: 1.79912702184 0.168615334265 min, max: 1.37571602512 2.27626915985 [ 1.70111141 1.66939592 1.81352635 1.70462197 1.81692876 1.83537786 1.56401468 1.82081866 1.7476216 1.85338689 1.7180552 1.68483402 1.90805181 2.27626916 1.98753559 1.86491373 1.84767332 1.44795185 1.54916086 1.88962943 2.09640825 1.86566779 1.55268145 1.91474707 1.80278735 1.63484793 1.76550669 1.82178918 1.77834417 1.7920206 1.88573401 1.75209283 2.05958794 1.99866976 1.99120389 1.37571603 1.79380661 1.87401399 1.70892489 1.79965134] # <--- THE DATA I USED! Using cached StanModel mu, std, lp: 0.466976 0.2 -900.464 #<-- NOTE, same as next line... mu, std, lp: 0.466976 0.2 -900.464 #<--- NOTE, same as previous line... mu, std, lp: 7.11887e+134 0.2 -2.53392e+272 <-- NOTE, crazy values! mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 5.9427e+135 0.2 -1.76578e+274 mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 1.95571e+33 0.2 -1.9124e+69 mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 1.182e+08 0.2 -6.98557e+18 mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 52.0734 0.2 -1.26376e+06 mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 1.6001 0.2 -31.8372 Iteration: 1 / 1000 0% (Chain 0) mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 1.57854 0.2 -36.288 mu, std, lp: 1.57532 0.2 -36.9484 mu, std, lp: 21.1472 0.2 -187184 mu, std, lp: 1.57854 0.2 -36.288 terminate called after throwing an instance of 'std::domain_error' what(): stan::prob::normal_log: Location parameter is inf, but must be finite! Abort trap: 6

I hope that makes things a bit more clear...

I also just tried your example (had to get Rstan set up first, but it seems to be working). I get very similar errors. So, just to be clear, I run the following:

prog <- "data { int N; real x[N]; } parameters { real mu; real sigma; } model { print(mu); print(sigma); x ~ normal(mu,sigma); }" N<-100 x<-rnorm(100,1.8,0.2) fit<-stan(model_code=prog,data=c("N","x"),chains=1) print(fit)

Though it would seem clear that this is probably not about the data itself, for completion, the data generated was

[1] 1.761284 1.930586 2.241595 1.642869 2.153253 1.653787 1.455835 1.449923 1.442179 1.484588 1.832982 [12] 1.571020 1.931932 1.926399 1.480587 1.534197 1.584152 1.931132 2.241716 1.759768 1.817335 2.026592 [23] 1.672885 1.853471 1.881422 1.785274 1.709694 1.633035 1.492166 1.565077 1.849872 2.121320 2.185442 [34] 1.772569 1.888035 1.526460 1.958919 1.959744 1.544289 1.502391 1.647825 2.223417 1.516528 1.969358 [45] 2.034885 1.876006 1.754031 1.408685 1.867123 2.352696 1.952763 1.511535 1.688733 1.815875 1.994664 [56] 1.801293 1.897570 1.840546 1.796892 2.065086 1.897444 1.504593 1.948574 1.907096 1.670944 1.559161 [67] 1.925603 1.908491 1.505382 1.862516 1.784340 1.924685 1.873087 1.842244 1.588550 1.908729 1.932409 [78] 2.095017 1.807417 1.859346 1.775032 1.514854 1.600258 1.775150 1.831566 1.919390 2.162588 1.911475 [89] 1.421646 1.591651 1.839322 1.783013 2.092320 1.963195 1.815046 1.729378 1.622455 1.687426 1.935269 [100] 1.945803

I've run this through several times, sometimes printing out the parameters during iterations, sometimes not. It has run right through twice, but all the rest of the times (5 or 6 more) it has failed with

Error in sampler$call_sampler(args_list[[i]]) : c++ exception (unknown reason) error occurred during calling the sampler; sampling not done

When printing out parameters, it is clear that it is the same problem as in pystan. When running without the on mu, it ran right through the three times I tried it when using 1 chain. However, when using 2 chains, it runs through the first chain fine, but chokes with the same problem on the second chain early on. I'm beginning to think this is not a conceptual problem, but a technical one....

I'm using R 3.1.2 with Rstudio 0.99, and just did a fresh install of rstan, so I'm assuming it's whatever the latest version is. This is all on Mac OSX 10.7.5.

— Reply to this email directly or view it on GitHub.

bob-carpenter commented 9 years ago

OK, that makes the problem clear. I'll try to track it down.

I've prioritized this issue for 2.7.0++ and assigned it to myself, so hopefully it'll be fixed (or at least understood) by the release after 2.7 (which will be any day now).

On Jun 19, 2015, at 1:13 AM, Steven Murray notifications@github.com wrote:

Hi Bob,

Thanks for your reply. Here's my full working pystan program for reference:

import numpy as np import pystan import pickle from hashlib import md5

Don't worry about this its just the caching of the code

def stan_cache(model_code, model_name=None, dir=""): """Use just as you would StanModel""" code_hash = md5(model_code.encode('ascii')).hexdigest() if model_name is None: cache_fn = dir + 'cached-model-{}.pkl'.format(code_hash) else: cache_fn = dir + 'cached-{}-{}.pkl'.format(model_name, code_hash) try: sm = pickle.load(open(cache_fn, 'rb')) except: sm = pystan.StanModel(model_code=model_code) with open(cache_fn, 'wb') as f: pickle.dump(sm, f) else: print("Using cached StanModel") return sm

model = """ data { int N; //number of data points real x[N]; //Data int debug; //Toggle debugging } parameters { real mu; real std; } model { if(debug>1) print("x: ", x); x ~ normal(mu,0.2); if(debug>0) print("mu, std, lp: ", mu," ",0.2, " ", get_lp()); } """

THE FOLLOWING IS THE CODE

if name == "main":

Define the distribution

mu = 1.8
std = 0.2
debug = 1
# Create mock data
data = np.random.normal(mu, std, size=40)
print "mean, std: ", np.mean(data), np.std(data)
print "min, max: ", np.min(data), np.max(data)
print data

# Setup Stan object
data_dict = {"N":len(data),
             "x":data,
             "debug":debug}
M = stan_cache(model_code=model, dir="simulation/stanCache/")

# Do the sampling
fit = M.sampling(data=data_dict, iter=1000, warmup=200, chains=1)
print fit

Having just run it, I get the following output:

mean, std: 1.79912702184 0.168615334265 min, max: 1.37571602512 2.27626915985 [ 1.70111141 1.66939592 1.81352635 1.70462197 1.81692876 1.83537786 1.56401468 1.82081866 1.7476216 1.85338689 1.7180552 1.68483402 1.90805181 2.27626916 1.98753559 1.86491373 1.84767332 1.44795185 1.54916086 1.88962943 2.09640825 1.86566779 1.55268145 1.91474707 1.80278735 1.63484793 1.76550669 1.82178918 1.77834417 1.7920206 1.88573401 1.75209283 2.05958794 1.99866976 1.99120389 1.37571603 1.79380661 1.87401399 1.70892489 1.79965134] # <--- THE DATA I USED! Using cached StanModel mu, std, lp: 0.466976 0.2 -900.464 #<-- NOTE, same as next line... mu, std, lp: 0.466976 0.2 -900.464 #<--- NOTE, same as previous line... mu, std, lp: 7.11887e+134 0.2 -2.53392e+272 <-- NOTE, crazy values! mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 5.9427e+135 0.2 -1.76578e+274 mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 1.95571e+33 0.2 -1.9124e+69 mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 1.182e+08 0.2 -6.98557e+18 mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 52.0734 0.2 -1.26376e+06 mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 1.6001 0.2 -31.8372 Iteration: 1 / 1000 0% (Chain 0) mu, std, lp: 0.466976 0.2 -900.464 mu, std, lp: 1.57854 0.2 -36.288 mu, std, lp: 1.57532 0.2 -36.9484 mu, std, lp: 21.1472 0.2 -187184 mu, std, lp: 1.57854 0.2 -36.288 terminate called after throwing an instance of 'std::domain_error' what(): stan::prob::normal_log: Location parameter is inf, but must be finite! Abort trap: 6

I hope that makes things a bit more clear...

I also just tried your example (had to get Rstan set up first, but it seems to be working). I get very similar errors. So, just to be clear, I run the following:

prog <- "data { int N; real x[N]; } parameters { real mu; real sigma; } model { print(mu); print(sigma); x ~ normal(mu,sigma); }" N<-100 x<-rnorm(100,1.8,0.2) fit<-stan(model_code=prog,data=c("N","x"),chains=1) print(fit)

Though it would seem clear that this is probably not about the data itself, for completion, the data generated was

[1] 1.761284 1.930586 2.241595 1.642869 2.153253 1.653787 1.455835 1.449923 1.442179 1.484588 1.832982 [12] 1.571020 1.931932 1.926399 1.480587 1.534197 1.584152 1.931132 2.241716 1.759768 1.817335 2.026592 [23] 1.672885 1.853471 1.881422 1.785274 1.709694 1.633035 1.492166 1.565077 1.849872 2.121320 2.185442 [34] 1.772569 1.888035 1.526460 1.958919 1.959744 1.544289 1.502391 1.647825 2.223417 1.516528 1.969358 [45] 2.034885 1.876006 1.754031 1.408685 1.867123 2.352696 1.952763 1.511535 1.688733 1.815875 1.994664 [56] 1.801293 1.897570 1.840546 1.796892 2.065086 1.897444 1.504593 1.948574 1.907096 1.670944 1.559161 [67] 1.925603 1.908491 1.505382 1.862516 1.784340 1.924685 1.873087 1.842244 1.588550 1.908729 1.932409 [78] 2.095017 1.807417 1.859346 1.775032 1.514854 1.600258 1.775150 1.831566 1.919390 2.162588 1.911475 [89] 1.421646 1.591651 1.839322 1.783013 2.092320 1.963195 1.815046 1.729378 1.622455 1.687426 1.935269 [100] 1.945803

I've run this through several times, sometimes printing out the parameters during iterations, sometimes not. It has run right through twice, but all the rest of the times (5 or 6 more) it has failed with

Error in sampler$call_sampler(args_list[[i]]) : c++ exception (unknown reason) error occurred during calling the sampler; sampling not done

When printing out parameters, it is clear that it is the same problem as in pystan. When running without the on mu, it ran right through the three times I tried it when using 1 chain. However, when using 2 chains, it runs through the first chain fine, but chokes with the same problem on the second chain early on. I'm beginning to think this is not a conceptual problem, but a technical one....

I'm using R 3.1.2 with Rstudio 0.99, and just did a fresh install of rstan, so I'm assuming it's whatever the latest version is. This is all on Mac OSX 10.7.5.

— Reply to this email directly or view it on GitHub.

bob-carpenter commented 9 years ago

I can't recreate this issue in RStan 2.6.0 on not quite latest R (3.1.3) on Mac OS X using latest clang++ (Apple LLVM version 6.1.0 (clang-602.0.53)) through XCode.

@steven-murray Do you know what C++ compiler and libs (or version of Xcode) you're using through R and is it the same in Python?

The code (without print statements) is just copied from the top of the issue.

> maxes <- rep(0, 100);

> for (n in 1:100) {
  fit <- stan("posnorm.stan", seed=n, fit=fit, data=list(N = 100, x = rnorm(100, 1.8, 0.2)));
  maxes[n] <- max(extract(fit)$mu);
}

> print(maxes)
  [1] 1.854467 1.895107 1.844675 1.910459 1.870540 1.878266 1.898369 1.882678
  [9] 1.813843 1.905899 1.909939 1.867651 1.851600 1.850868 1.848274 1.839109
 [17] 1.851720 1.904543 1.877397 1.915734 1.888707 1.884525 1.861014 1.855196
 [25] 1.859845 1.905841 1.908846 1.844400 1.884709 1.827633 1.837655 1.859023
 [33] 1.860880 1.921772 1.904404 1.871744 1.880645 1.890129 1.870713 1.848461
 [41] 1.880945 1.885438 1.897236 1.882847 1.858529 1.843648 1.856255 1.896213
 [49] 1.861807 1.875560 1.866784 1.869959 1.895668 1.877894 1.897101 1.881371
 [57] 1.872455 1.911993 1.901575 1.876710 1.836005 1.842173 1.881965 1.874546
 [65] 1.901971 1.885622 1.891651 1.933040 1.859925 1.904741 1.876200 1.880287
 [73] 1.850927 1.911868 1.873627 1.870514 1.902043 1.864400 1.868236 1.870532
 [81] 1.847946 1.947983 1.899085 1.922828 1.841858 1.822299 1.841754 1.868418
 [89] 1.865960 1.862460 1.892699 1.912899 1.864093 1.894394 1.854282 1.858839
 [97] 1.885960 1.953880 1.883785 1.893284

Oh, and I ran it once first to get the fit object. I never had a version without lower bound and I recompiled again just to be sure.

steven-murray commented 9 years ago

Hi Bob, Sorry, I'm not quite sure how to get this info. Typing clang++ --version yields:

Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix

The version of Xcode I've got is 4.6.3 -- I tried just updating it, but it won't let me, saying I need OSX 10.10 or higher (but I don't want to do that at the moment, since I'm a couple of months out from PhD submission...)

bob-carpenter commented 9 years ago

[new subject]

To bring people up to date, Steven Murray submitted an erroneous sampling (getting the wrong answer) issue which he gets using Xcode 4.6.3 and clang++ 3.1 (LLVM 3.1), but that I can't recreate in the current versions, Xcode 6.3.2 and clang++ 6.1 (LLVM 3.6).

Given that I can't recreate this issue with current compilers, I'm not sure what we should do.

Steven doesn't want to update Xcode because it requires updating the Mac OS, so do we just tell him he's out of luck, or what?

I filed an issue comment

https://github.com/stan-dev/cmdstan/issues/86#issuecomment-114594962

to update our supported compilers, which themselves are way out of date (and we do promise to support 3.1, even though it was ages ago and we really have no easy way to do it).

On Jun 23, 2015, at 3:01 AM, Steven Murray notifications@github.com wrote:

Hi Bob, Sorry, I'm not quite sure how to get this info. Typing clang++ --version yields:

Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn) Target: x86_64-apple-darwin11.4.2 Thread model: posix

The version of Xcode I've got is 4.6.3 -- I tried just updating it, but it won't let me, saying I need OSX 10.10 or higher (but I don't want to do that at the moment, since I'm a couple of months out from PhD submission...)

— Reply to this email directly or view it on GitHub.

steven-murray commented 9 years ago

I just realised how to check the compiler used (just use verbose option duh). In R, it's using the clang++, so it is definitely that version. In PyStan, it is using GCC 4.2.1, which seems quite old. I do have GCC 4.7.1 installed on my system, so I'm not sure why it's using that old version. This is probably screwing things up.

steven-murray commented 9 years ago

I'm just checking this with another machine (Ubuntu with g++ 4.8.4) now. It runs fine, but gives several warnings along the way:

Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
stan::prob::normal_log(N4stan5agrad3varE): Location parameter is inf:0, but must be finite!
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

and

Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is 0:0, but must be > 0!
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

These are similar messages to what I previously got, except that it doesn't halt the program in this case.

I am also trying with Pystan on this system, which is using GCC 4.4.7 (I think this is set to the compiler within the Anaconda python distribution). It gives the same warnings, but runs through fine.

Interestingly, if I take out the two <lower=0> statements, I get a lot MORE of these warnings. If I take out just the <lower=0> on the mu parameter, I still get the second warning about as much as before, but don't get the inf warning any more. Using <lower=0,upper=4> on mu gives pretty much the same. However, if add upper limits on both parameters, there are no warnings at all.

bob-carpenter commented 9 years ago

Thanks for looking into this further on your end.

This is good --- that's all expected behavior.

The informational warnings are from early iteration numerical divergences (almost always underflow or overflow leading to infinite or divide-by-zero [NaN] results). Those are OK. They're happening here because early iterations are taking too large a step. You can almost certainly get rid of these by setting

control = list(stepsize=0.1)

or maybe even 0.01. That'll make the steps before adaptation more conservative and less likely to over/under-flow.

The problem with lower=0 on sd is that if you remove it, you'll actually get negative draws and jumps much more, which you don't want --- Stan programs should have constraints declared for parameters that match the support in the model block.

On Jun 23, 2015, at 8:47 PM, Steven Murray notifications@github.com wrote:

I'm just checking this with another machine (Ubuntu with g++ 4.8.4) now. It runs fine, but gives several warnings along the way:

Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: stan::prob::normal_log(N4stan5agrad3varE): Location parameter is inf:0, but must be finite! If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

and

Informational Message: The current Metropolis proposal is about to be rejected because of the following issue: stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is 0:0, but must be > 0! If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine, but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

These are similar messages to what I previously got, except that it doesn't halt the program in this case.

I am also trying with Pystan on this system, which is using GCC 4.4.7 (I think this is set to the compiler within the Anaconda python distribution). It gives the same warnings, but runs through fine.

Interestingly, if I take out the two statements, I get a lot MORE of these warnings. If I take out just the on the mu parameter, I still get the second warning about as much as before, but don't get the inf warning any more. Using on mu gives pretty much the same. However, if add upper limits on both parameters, there are no warnings at all.

— Reply to this email directly or view it on GitHub.

bob-carpenter commented 9 years ago

@steven-murray Any idea if this is still a problem with the latest PyStan and RStan? Given that we can't recreate the issue on our end, I'm going to close it. But if it's still an issue with the most recent PyStan and RStan, we can re-open.

steven-murray commented 9 years ago

Unfortunately (or fortunately), I ended up upgrading my system to Yosemite, getting the newer compilers and everything worked. So I can't test if the older compilers with the new Stan versions reproduce the problem. I guess keep this closed unless someone else has the problem!

On Thu, Aug 13, 2015 at 11:01 AM, Bob Carpenter notifications@github.com wrote:

Closed #1504 https://github.com/stan-dev/stan/issues/1504.

— Reply to this email directly or view it on GitHub https://github.com/stan-dev/stan/issues/1504#event-381015652.

bob-carpenter commented 9 years ago

Thanks for the update. It's a huge pain trying to maintain backward compatiblity, so I think we'll just drop support for older Mac versions. Apple's very aggressive about making people update for all sorts of functionality --- no wonder they still don't own the corporate computing world.

On Aug 12, 2015, at 11:04 PM, Steven Murray notifications@github.com wrote:

Unfortunately (or fortunately), I ended up upgrading my system to Yosemite, getting the newer compilers and everything worked. So I can't test if the older compilers with the new Stan versions reproduce the problem. I guess keep this closed unless someone else has the problem!

On Thu, Aug 13, 2015 at 11:01 AM, Bob Carpenter notifications@github.com wrote:

Closed #1504 https://github.com/stan-dev/stan/issues/1504.

— Reply to this email directly or view it on GitHub https://github.com/stan-dev/stan/issues/1504#event-381015652.

— Reply to this email directly or view it on GitHub.