Initialization Failed

Hi all,

I’m trying to setup a simple model. I defined a custom generalized Gaussian distribution (see code). However, running the data, I get the error that the initialization failed. Can someone guide me with this?

functions {
  real generalized_gaussian_lpdf(real x, real mu, real scale, real beta){
    return log(beta) - log(2) - log(scale) - lgamma(1 / beta) - pow((fabs(x-mu) / scale), beta);
  }
}

data {
  int N;                                                  // number of points
  vector[N] Y;                                            // demonstration segment
  vector[2] bounds;                                       // bounds of space (for discretization)
}

parameters {
  real<lower=bounds[1], upper=bounds[2]> center;
  real<lower=0, upper=bounds[2]-bounds[1]> width;
}

transformed parameters {
  ordered[2] intervals;
  intervals[1] = center - (width / 2);
  intervals[2] = center + (width / 2);
}

model {
  // priors
  //lower_interval ~ uniform(bounds[1], bounds[2]);
  //upper_interval ~ uniform(bounds[1], bounds[2]);

   //likelihood
  for (i in 1:N)
    Y[i] ~ generalized_gaussian(center, width/2, 5);
}

Any direction is appreciated!

Huh. Change this

to this

with a period at the end and it should work. This is super counterintuitive and should probably be filed as a bug.

Not sure who is responsible / decides this.

Reason for misbehavior:

    Y[i] ~ generalized_gaussian(center, width/2, 5);

treats the last parameter beta as an int, such that 1/beta evaluates to zero.

1 Like