// [[Rcpp::depends(RcppArmadillo)]] #include "RcppArmadillo.h" using namespace arma; // use the Armadillo library for matrix computations using namespace Rcpp; // [[Rcpp::export]] List BA(mat X, vec beta, double lambda, vec mu, mat states, int nobs){ // Blahut Arimoto algorithm (design: inside brands + outside good + price + bonus) // X here is only the design with simple attributes // states is the matrix of all the realization of states // mu is the prior // lambda is the cost of information acquisition int nstates = states.n_cols; double nalt = states.n_rows; int nvar = beta.n_elem; vec oldProbs = zeros(nalt); vec cProbs = oldProbs; mat oldCondProbs = zeros(nalt,nstates); mat cCondProbs = oldCondProbs; mat post = zeros(nalt,nstates); // Calculate Omega (states) | beta //////// mat Xbeta = X*beta(span(0,nvar-1 - 1)); //last beta is the costly attribute (bonus) //////// mat Omega = zeros(nalt,nstates); for(int j=0;jprecision && counter