//
// This Stan program defines a simple model, with a
// vector of values 'y' modeled as normally distributed
// with mean 'mu' and standard deviation 'sigma'.
//
// Learn more about model development with Stan at:
//
//    http://mc-stan.org/users/interfaces/rstan.html
//    https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
//
// The input data is a vector 'y' of length 'N'.
data {
  int<lower=1> D; //Number of parameters
  int<lower=1> N; // Number of observations
  int<lower=1> L; //Number of categories
  int<lower=1, upper=L> ll[N];
  row_vector[D] x[N];
}
generated quantities {
    //preallocate
    real mu[D];
    real sigma[D];
    vector[D] beta[L];
    real p[N]; // what I have priors about
    //sample parameters
    for (d in 1:D) {
        mu[d] = normal_rng(0,1);
        sigma[d] = gamma_rng(2,1);
    }
    for (l in 1:L) {
        for (d in 1:D) {
            beta[l,d] = normal_rng(mu[d],sigma[d]);
        }
    }
    //generate probabilities
    {
        vector[D] b[N];//local var
        for (n in 1:N){
            b[n] = beta[ll[n]];
            p[n] = logit(  x[n] * b[n] );
        }
    }
}

CXXFLAGS = -g -O2 -fdebug-prefix-map=/build/r-base-MkHsSu/r-base-4.2.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 $(LTO)