bayes/matlab/varbvs-R/src/varbvsnormupdate_rcpp.cpp
void varbvsnormupdate_rcpp (const NumericMatrix& X, double sigma, double sa,
			    const NumericVector& logodds,
			    const NumericVector& xy, const NumericVector& d,
			    NumericVector& alpha, NumericVector& mu,
			    NumericVector& Xr, const IntegerVector& i) {

  // Cycle through the coordinate ascent updates.
  for (int iter = 0; iter < i.size(); iter++) {

    // j is the coordinate we update in this iteration.
    int j = i[iter];

    // Compute the variational estimate of the posterior variance.
    double s = sa*sigma/(sa*d[j] + 1);

    // Update the variational estimate of the posterior mean.
    double r = alpha[j] * mu[j];
    mu[j] = s/sigma*(xy[j] + d[j]*r - sum(X.column(j) * Xr));

    // Update the variational estimate of the posterior inclusion probability.
    alpha[j] = sigmoid_rcpp(logodds[j] + (log(s/(sa*sigma)) +
					  mu[j]*mu[j]/s)/2);

    // Update Xr = X*r.
    Xr = Xr + (alpha[j] * mu[j] - r) * X.column(j);
  }
}
// Execute a single coordinate ascent update to maximize the variational 
// lower bound for Bayesian variable selection in linear regression.
//
// [[Rcpp::export]]
Execute a single coordinate ascent update to maximize the variational
lower bound for Bayesian variable selection in linear regression.


Execute a single coordinate ascent update to maximize the variational lower bound for Bayesian variable selection in linear regression .
void varbvsnormupdate_rcpp (const NumericMatrix& X, double sigma, double sa,
			    const NumericVector& logodds,
			    const NumericVector& xy, const NumericVector& d,
			    NumericVector& alpha, NumericVector& mu,
			    NumericVector& Xr, const IntegerVector& i) {
  for (int iter = 0; iter < i.size(); iter++) {
    int j = i[iter];
    double s = sa*sigma/(sa*d[j] + 1);
    double r = alpha[j] * mu[j];
    mu[j] = s/sigma*(xy[j] + d[j]*r - sum(X.column(j) * Xr));
    alpha[j] = sigmoid_rcpp(logodds[j] + (log(s/(sa*sigma)) +
					  mu[j]*mu[j]/s)/2);
    Xr = Xr + (alpha[j] * mu[j] - r) * X.column(j);
  }
}
void varbvsnormupdate_rcpp ( const NumericMatrix & X , double sigma , double sa , const NumericVector & logodds , const NumericVector & xy , const NumericVector & d , NumericVector & alpha , NumericVector & mu , NumericVector & Xr , const IntegerVector & i ) { for ( int iter = 0 ; iter < i . size ( ) ; iter ++ ) { int j = i [ iter ] ; double s = sa * sigma / ( sa * d [ j ] + 1 ) ; double r = alpha [ j ] * mu [ j ] ; mu [ j ] = s / sigma * ( xy [ j ] + d [ j ] * r - sum ( X . column ( j ) * Xr ) ) ; alpha [ j ] = sigmoid_rcpp ( logodds [ j ] + ( log ( s / ( sa * sigma ) ) + mu [ j ] * mu [ j ] / s ) / 2 ) ; Xr = Xr + ( alpha [ j ] * mu [ j ] - r ) * X . column ( j ) ; } }
Execute a single coordinate ascent update to maximize the variational
lower bound for Bayesian variable selection in linear regression.
Execute a single coordinate ascent update to maximize the variational lower bound for Bayesian variable selection in linear regression .
// Cycle through the coordinate ascent updates. // j is the coordinate we update in this iteration. // Compute the variational estimate of the posterior variance. // Update the variational estimate of the posterior mean. // Update the variational estimate of the posterior inclusion probability. // Update Xr = X*r.