# Stan sampling near one mode only?

I have a model with a circular parameter and I would like Stan to sample all the modes, however for some reason Stan only samples around one mode. I would like to understand if this is by design or not. Referring to the code below, I know that there are modes at d={1,2.5,4,5.5} since I define the range of d to [0,6], however Stan only samples around d=2.5. Is there any way to circumvent this?

``````data {
vector[3] I;
real<lower=0> sigma; // sigma = 14
}

transformed data {
int N = 3;
real phi[3] = {0.0, 2.0*pi()/N, 4.0*pi()/N};

real f = 100e6;                  // [Hz]
real c = 299792458.0;      // [m/sec]
}

parameters {
real<lower=0> A;
real<lower=0,upper=6.0> d;
}

model {
I[1] ~ normal(A * cos(4*pi()*f / c * d + phi[1]), sigma);
I[2] ~ normal(A * cos(4*pi()*f / c * d + phi[2]), sigma);
I[3] ~ normal(A * cos(4*pi()*f / c * d + phi[3]), sigma);
}
``````

Thanks,

-Arrigo

I’m afraid not. Multimodal posteriors are notoriously tricky to sample. There’s nothing built into Stan to facilitate it. Sometimes you can get lucky if the modes do not have large troughs of low density between them. Otherwise, there’s no way for the Hamiltonian to get enough kinetic energy to move from one to the other.

You can evaluate the densities to see if you’re getting the right values. Also, this model could be coded more efficiently with a vectorized density:

``````I ~ normal(A * Cos(4 * pi() * f / c * d + phi, sigma);
``````

For real applications, you’ll probably also want priors.