// The input data required to fit the model
data {
  int<lower=1> n; // number of observations
  int<lower=2> K;
  vector[n] y;    // observations
}

// The parameters of our model
parameters {
  simplex[K] alpha;    // mixing proportions
  ordered[K] mu;       // means of components
  real<lower=0> sigma; // standard deviations of components
}

// The posterior specification
model {
  // priors
  target += gamma_lpdf(1/sigma^2 | 1, 1);
  target += normal_lpdf(mu | 70, 5);
  target += dirichlet_lpdf(alpha | rep_vector(1, K));

  // likelihood
  for(i in 1:n){
    vector[K] temp = log(alpha);
    
    for(k in 1:K){
      temp[k] += normal_lpdf(y[i] | mu[k], sigma);
    }
    
    target += log_sum_exp(temp);
  }
}

CXXFLAGS = -O2 -Wall $(DEBUGFLAG) -mfpmath=sse -msse2 -mstackrealign $(LTO)

std::vector<double, std::allocator<double> > constrain_pars(std::vector<double, std::allocator<double> >)

std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > constrained_param_names(bool, bool)

Rcpp::NumericVector grad_log_prob(std::vector<double, std::allocator<double> >, bool)

Rcpp::NumericVector log_prob(std::vector<double, std::allocator<double> >, bool, bool)

std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > param_fnames_oi()

std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > param_names()

std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > param_names_oi()

Rcpp::List param_oi_tidx(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >)