I don't know what the R package blockcluster does, but
our categoricals are indexed from 1 through K.
Your problem is here:model {int rclass[N,D];...rclass[i,j] ~ categorical(pi[i]);
You don't ever set rclass. The default value is 0, and then
that causes a problem because 0 is not an appropriate outcome
for a categorical.
It looks like what you're trying to do is sample from the
categorical(pi[i]) and assign the result to rclass[i,j], which
is NOT how Stan sampling statements work. They just increment
the log probability with the value of
log(Categorical(rclass[i,j] | pi[i]))
which presupposes that rclass[i,j] is set to a valid value.
Also, given that you have a parameter declarationsimplex[L] pj[D];
you almost certainly don't want to be doing this:cclass[i,j] ~ categorical(softmax(pj[j]));
pj[j] is already declared to be a simplex, so it's already
the right kind of thing to be a parameter to categorical().
Now you're transforming it again by exponentiating the
values in pj[j] and then normalizing.
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/LK0kGNdyGdE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/LK0kGNdyGdE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/LK0kGNdyGdE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
I fixed a little bit for you. The error said all. your return type should be int instead of vector.Also, your use of rank is not correct (check input arguments in the manual). I do not know what is the purpose of rank, but I do not think which.max is equivalent to rank anyway.
Assuming you use rank as alternative to which.max, here is your code with my fixes(at least compiled, but not sure this is what you want).
data {int<lower=1> N;int<lower=1> D;int<lower=1> K; // Number of row clustersint<lower=1> L; // Number of col clustersint<lower=0,upper=1> x[N,D];vector<lower=0>[K] alpha1;vector<lower=0>[L] alpha2;}parameters {real<lower=0,upper=1> theta[K,L];simplex[K] pi[N];simplex[L] pj[D];}model {
//vector[K] rowSegVec;int rowSegVec[K];//vector[L] colSegVec;int colSegVec[L];
real ps[N,D];for(k in 1:K){ # prior on theta - binomial prob for co-clustersfor(l in 1:L){theta[k,l] ~ beta(1, 1);}}for(i in 1:N) { # hierarchical prior on rowspi[i] ~ dirichlet(alpha1); # the individual class prob pi}for(j in 1:D) { # hierarchical prior on columnspj[j] ~ dirichlet(alpha2); # the individual class prob pj}for(i in 1:N){ # likelihood
int row_max;int col_max;
rowSegVec ~ categorical(pi[i]);for(j in 1:D){colSegVec ~ categorical(pj[j]);for(l in 1:L){for (k in 1:K){
row_max <- 0; // first candidatecol_max <- 0; // first candidatefor(kk in 1:K){// not sure what to do if where are two max or more.if(rowSegVec[kk] > row_max){row_max <- kk;}}for(ll in 1:L){if(colSegVec[ll] > row_max){col_max <- ll;}}
if (row_max == K-1 && col_max == L-1)
increment_log_prob(x[i,j]*log(theta[k,l])+(1-x[i,j])*log1m(theta[k,l]));}}}}}
Enjoy!