--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I'll try this out tomorrow, but I think I can solve my sampling problem by using a MVN approximation to logits.
Using logits rather than raw probabilities is easy enough when using 2 groups, but harder with > 2 groups.
If dirichlet, like beta, can't be sampled well due to probability near constraints (and thus, basically, walls), I wonder if I can:
Use softmax regression to estimate logits of groups, then place a MVN(logits[n], 5*1.6*Identity) prior on that as an approximation to a dirichlet.
That is, rather than using: pi[n,1:K] ~ dirichlet(somePredicted/Hierarchical parameters), I could use pi_logit[n,1:K] ~ multinormal(somePredicted/Hierarchical parameters, scaling to adjust multinormal akin to using N(0,1.6) as logistic approx).
I'll play with this tomorrow.
On Thursday, September 29, 2016 at 10:33:14 PM UTC-5, Stephen Martin wrote:Hey everyone,
I'm fitting a fairly weird model (one that I've posted here in the past) that contains mixtures.
Because I want to favor categorization, I prefer sampling mixture weights (per case) from, e.g., a beta or dirichlet where the parameters are < 1. That puts more probability over 0s and 1s, and helps 'encourage' assignment to one cluster over others.
However, I noticed today that when using beta(.2,.2) as a prior, for example, that sampling was *slow* (like, 45 minutes later, and only hitting 10%, slow), and I assume that it's because so MUCH probability is over 0 and 1, and the geometry of that is awful to sample from (the negative log of that would be like an inverted U, constrained at 0 and 1).
Because of that, is it preferred to instead parameterize as log-odds and sample from a wide logistic?
That is, is it preferred to use:
vector[N] pi_logit;
pi_logit ~ logistic(pi_logit_mean, 5); pi_logit_mean ~ logistic(0,5);
as opposed to:
vector[N] pi;
pi ~ dbeta(alpha*scale,beta*scale); alpha = (pi_mean); beta = 1 - pi_mean; scale = .2; pi_mean ~ uniform(0,1)
I assume the logistic is easier to sample from, geometrically, than a beta/dirichlet that is highly pointed near bounded areas (0 and 1). Am I correct in thinking about this?
--
Well, the stan model I'm using is fairly massive and novel, and would only obfuscate things if I posted the full thing here. Tomorrow I'll make a smaller, toy example of the aspect of the model that's causing me issues. Really, the part of the model that is currently concerning me is a mixture modeling component.
Just some points
- I do use simplex for pi when K > 2, otherwise I use real<lower=0,upper=1>
- I'm not sure I follow. For mixtures, I assume each person has a probability of belonging to cluster 1 or 2 (for k = 2, vector<lower=0,upper=1>[N] pi), pi ~ beta(alpha, beta); alpha = mean*scale, beta = (1 - mean)*scale; scale = .2; mean ~ uniform). This gives me an overall mean, and allows individuals to individually load on each cluster with some probability pi. The scale essentially inverts the beta and places greater probability on 0 or 1, thus informing the model to try 'harder' to assign people to one cluster or another.
- Stan does have the beta distribution. I've used beta several times. Hell, my model actually works, I'm just trying to extend it to include a softmax regression within it, so you can predict group membership probabilities, but also try and encourage high probability clustering.
- haven't tried simulating data /from/ it, but have fit the model *to* simulated data.
data {
int N;
vector[N] x;
int K;
real dirichlet_scale;
}
parameters{
ordered[K] means;
vector<lower=0>[K] sds;
// simplex[K] pi[N];
vector<lower=0>[K] pi_logit[N];
vector<lower=0>[K] beta0;
}
transformed parameters{
simplex[K] pi_mean;
simplex[K] pi[N];
pi_mean = softmax(beta0);
for(n in 1:N){
pi[n] = softmax(pi_logit[n]);
}
}
model{
vector[K] lp_nk[N];
vector[N] lp_n;
means ~ normal(0,4);
sds ~ cauchy(0,3);
beta0 ~ logistic(0,1);
for(n in 1:N){
for(k in 1:K){
pi_logit[n,k] ~ logistic(beta0[k],3);
}
// pi[n] ~ dirichlet(pi_mean*dirichlet_scale);
}
for(n in 1:N){
for(k in 1:K){
lp_nk[n,k] = log(pi[n,k]) + normal_lpdf(x[n] | means[k], sds[k]);
}
lp_n[n] = log_sum_exp(lp_nk[n]);
}
target += sum(lp_n);
}data {
int N;
int J;
int K;
vector[N] x;
matrix[N,J] predictor;
}
parameters{
ordered[K] means;
vector<lower=0>[K] sds;
vector<lower=0>[K] pi_logit[N];
vector<lower=0>[K] beta0;
matrix[J,K] beta;
}
transformed parameters{
simplex[K] pi[N];
// vector[K] pi_logit[N];
for(n in 1:N){
pi[n] = softmax(pi_logit[n]);
}
}
model{
vector[K] lp_nk[N];
vector[N] lp_n;
means ~ normal(0,4);
sds ~ cauchy(0,3);
beta0 ~ logistic(0,3);
for(k in 1:K){
beta[1:J,k] ~ logistic(0,3);
}
for(n in 1:N){
for(k in 1:K){
pi_logit[n,k] ~ logistic(beta0[k] + predictor[n]*beta[1:J,k],1);
}
}
for(n in 1:N){
for(k in 1:K){
lp_nk[n,k] = log(pi[n,k]) + normal_lpdf(x[n] | means[k], sds[k]);
}
lp_n[n] = log_sum_exp(lp_nk[n]);
}
target += sum(lp_n);
}From what I can tell, all parameters are defined. However, the problem is that the model is putting noone on cluster 1, so the cluster 1 parameters are not being estimated from the data and are purely draws from the priors (pi[n,1] is essentially 0). Again, I'm not sure why it is any different from a non-scaled simplex regression. I may play with this some more tomorrow and post the code. I just finished cleaning up the working model to be faster (22 seconds for a multinomial logistic model predicting latent class membership; not too shabby!), so I'd have to undo a lot of that to be parameterized using K-1 logits with one fixed to 0.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.