Hi,
I implemented a mixed distribution after Mardia and Sutton with a von Mises distribution and a normal distribution.
functions{
real d_mu_c_helper_fct(real d_mu, real d_sigma, real kappa,
real rho_1, real rho_2, real angle, real a_mu) {
real d_mu_c = d_mu + d_sigma * sqrt(kappa)
* (rho_1 *(cos(angle) - cos(a_mu)) + rho_2*(sin(angle) - sin(a_mu)));
return d_mu_c;
}
data {
int K; // number classes
int N; // number of all data points
vector[N] angle;
vector[N] dist;
}
parameters{
vector<lower=0, upper=6.28318530718> [K] a_mu;
vector<lower=0, upper=8>[K] kappa;
vector<lower=0, upper=18> [K] d_mu;
vector<lower=0, upper=6> [K] d_sigma;
real<lower=0, upper=1> rho_1;
real<lower=0, upper=1-rho_1> rho_2;
}
transformed parameters{
real rho = sqrt(pow(rho_1,2) + pow(rho_2,2)); //eq 1.3
vector[K] d_sigma_c;
for (k in 1:K){
d_sigma_c[k] = pow(d_sigma[k],2) * (1 - pow(rho,2)); //eq 1.3
}
}
model{
d_mu ~ normal (5, 5);
kappa ~ normal (5, 5);
rho_1 ~ normal (1, 1);
rho_2 ~ normal (1, 1);
d_sigma ~ normal (2,2);
a_mu ~ von_mises (4, 2);
for (n in 1:N) {
vector [K] pb;
vector[K] d_mu_c;
for (k in 1:K) {
// calculate d_mu_c with the helper function
d_mu_c[k] = d_mu_c_helper_fct(d_mu[k], d_sigma[k], kappa[k], rho_1, rho_2, angle[n], a_mu[k]);
//calculate real function
pb[k] = von_mises_lpdf(angle[n] | a_mu[k], kappa[k]) + normal_lpdf(dist[n] | d_mu_c[k] , d_sigma_c[k]);
}
target += log_sum_exp(pb);
}
}
It works fine but my model eventually always finds two cluster really close together and I don’t know why this happens or if there is a possibility to join them?
stan.o109552_plot.pdf (19.0 KB)