Multinomial Example in section 11.5 of Manual

444 views
Skip to first unread message

Sanjog Misra

unread,
Sep 4, 2012, 6:07:01 PM9/4/12
to stan-...@googlegroups.com
Hi All,

I was trying to replicate the example in section 11.5 and run into an error suggesting that the softmax function isn't found. My guess is that Im doing something silly but cant figure out what!
Also while I'm at it may I ask what the appropriate syntax is for the multinomial distribution (i.e. rather that using the categorical distribution in the example, how would we use the multinomial)

The error and code are appended below.

thanks
Sanjog


Error Message
==================

Error in stanc(model.code, model.name) : 

  Failed to parse Stan model 'anon_model' and error message provided as:

LOCATION:  file=input; line=22, column=40


  y[n] ~ categorical(softmax(beta*x[n]));

                                       ^-- here


DIAGNOSTIC(S) FROM PARSER:


no matches for function name="softmax"

    arg 0 type=vector

expression is ill formed

Parser expecting: <eps>



Code
=============

library(rstan)

scode <- "

data {

int<lower=0> N;

int<lower=0> D;

int<lower=0> K;

int<lower=1,upper=K> y[N];

vector[D] x[N];

}


parameters {

matrix[K,D] beta;

}



model {


for (k in 1:K) 

for (d in 1:D) 

beta[k,d] ~ normal(0,5);

  

for (n in 1:N) 

  y[n] ~ categorical(softmax(beta*x[n]));

}

"



y = c(1,2,3,3,1,1,3,2,1,1)

x = c(5,6,8,9,6,3,10,6,6,1)

N = length(y)

D = 1

K = 3

dat = list(x=x,y=y,K=K,D=D,N=N)


s.f <- stan(model.code = scode,data=dat , n.inter = 1000, n.chains = 1, verbose = FALSE) 




Daniel Lee

unread,
Sep 4, 2012, 6:38:49 PM9/4/12
to stan-...@googlegroups.com
Sanjog,

Thank you for bringing that to our attention.

1) softmax() is not available in v1.0.0. We are working to have it
available in the next patch release.
2) The Multi-Logit Regression model in Section 9.5 has an additional
error. We will also patch the model in the documentation.

We hope to have that available in the next couple of days.


Daniel

Sanjog Misra

unread,
Sep 4, 2012, 8:00:57 PM9/4/12
to stan-...@googlegroups.com
Thanks Daniel. While you are patching examples the Ordered Logit and Probit examples in the same section are also broken.

The Ordered Logit: matrix[D] should be vector[D]. The model then compiles and simulates draws but gives an error upon print
Error in rstan.ess(sim, n) : 

  argument to variance must have size >= 2; found v.size()=1


The Ordered Probit: 

Numerous issues:  
Matrix[D] should be vector[D] for beta
Dont know if Phi is defined or should be using erf
Indexing of c using () should be [] ?
Model wont compile gives error....

best
Sanjog

Jiqiang Guo

unread,
Sep 4, 2012, 8:41:05 PM9/4/12
to stan-...@googlegroups.com
This is an issue in version of Rstan before releasing.  Please update to the latest version or wait for the next version with some patches , which should come out soon.

Jiqiang 
Reply all
Reply to author
Forward
0 new messages