Error : Rejecting initial value when parameter is ~ uniform(0, 1);

783 views
Skip to first unread message

Nikolay Evdokimov

unread,
Apr 5, 2016, 1:46:27 PM4/5/16
to Stan users mailing list



Hello, I want to realize simple idea  - to simulate poisson process with following code in Matlab:

>> lambda = 0.2;
int_times = (1/lambda)*-log(rand(10,1))

int_times =

    2.9671
    0.2108
    3.5610
    7.4034
   10.9117
    9.0102
    0.5532
    7.1497
    2.0342
    6.9926



So i try to make a model in Stan and run it.


model_dat <- list(rowsN = 100, creationsN=5, creationsLambda = 0.2)
fit <- stan(file = '.R/StockModels/Agents1.stan',data = model_dat,  iter = 100, chains = 1)

-----------
data {
  int<lower=0> rowsN; 
  int<lower=0> creationsN; 
  real creationsLambda;
}

parameters {
  vector[creationsN] interarrivalTime_U;
}

transformed parameters {
    vector[creationsN] interarrivalTime;
    vector[creationsN] arrivalTime;
    interarrivalTime <- 1/creationsLambda*-log(interarrivalTime_U);
    arrivalTime <- cumulative_sum(interarrivalTime);
}

model {
  interarrivalTime_U ~ uniform(0, 1);
}

But I get following error:

SAMPLING FOR MODEL 'Agents1' NOW (CHAIN 1).
  [1] "Error : Rejecting initial value:"                                                                     
  [2] "  Log probability evaluates to log(0), i.e. negative infinity."                                       
  [3] "  Stan can't start sampling from this initial value."                                                 
  [4] "Rejecting initial value:" 

What am I doing wrong here?

Ben Goodrich

unread,
Apr 5, 2016, 1:58:21 PM4/5/16
to Stan users mailing list
On Tuesday, April 5, 2016 at 1:46:27 PM UTC-4, Nikolay Evdokimov wrote:

What am I doing wrong here?

Not constraining the parameter to the (0,1) interval, i.e.
parameters {
  vector
<lower=0,upper=1>[creationsN] interarrivalTime_U;
}


at which point, having

interarrivalTime_U ~ uniform(0,1);

in the model block is redundant.

Ben

Reply all
Reply to author
Forward
0 new messages