hi,
I’m trying to work out how to use Stan for time series clustering. I thought I would start with the soft k-means example in the User guide and github.
However it seems that array
is not a valid syntax to declare arrays on line 5. Has the syntax changed since this example was written? What would be the correct syntax?
data {
int<lower=0> N; // number of data points
int<lower=1> D; // number of dimensions
int<lower=1> K; // number of clusters
array[N] vector[D] y; // observations
}
transformed data {
real<upper=0> neg_log_K;
neg_log_K = -log(K);
}
parameters {
array[K] vector[D] mu; // cluster means
}
transformed parameters {
array[N, K] real<upper=0> soft_z; // log unnormalized clusters
for (n in 1:N) {
for (k in 1:K) {
soft_z[n, k] = neg_log_K - 0.5 * dot_self(mu[k] - y[n]);
}
}
}
model {
// prior
for (k in 1:K) {
mu[k] ~ std_normal();
}
// likelihood
for (n in 1:N) {
target += log_sum_exp(soft_z[n]);
}
}
Thanks in advance,
Rich