Skip to content

Commit

Permalink
Added empty UpdateGamma_cpp() (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
wleoncio committed Aug 15, 2024
1 parent f5e3ba4 commit a46dad6
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 3 deletions.
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

UpdateGamma_cpp <- function(sobj, hyperpar, ini, S, method, MRF_G, MRF_2b) {
.Call(`_BayesSurvive_UpdateGamma_cpp`, sobj, hyperpar, ini, S, method, MRF_G, MRF_2b)
}

func_MCMC_graph_cpp <- function(sobj, hyperpar, ini, S, method, MRF_2b) {
.Call(`_BayesSurvive_func_MCMC_graph_cpp`, sobj, hyperpar, ini, S, method, MRF_2b)
}
Expand Down
7 changes: 5 additions & 2 deletions R/updatePara.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
#' is provided in the argument \code{hyperpar}, and \code{MRF_G = FALSE} is to
#' use graphical model for leanring the MRF graph
#' @param MRF_2b two different b in MRF prior for subgraphs G_ss and G_rs
#' @inheritParams func_MCMC
#'
#' @return A list object with two components for the latent variable selection
#' indicators gamma with either independent Bernoulli prior
# (standard approaches) or with MRF prior
#'
#' @export
UpdateGamma <- function(sobj, hyperpar, ini, S, method, MRF_G, MRF_2b) {
UpdateGamma <- function(sobj, hyperpar, ini, S, method, MRF_G, MRF_2b, cpp = FALSE) {
# Update latent variable selection indicators gamma with either independent Bernoulli prior
# (standard approaches) or with MRF prior.

if (cpp) {
return(UpdateGamma_cpp(sobj, hyperpar, ini, S, method, MRF_G, MRF_2b))
}
p <- sobj$p
tau <- hyperpar$tau
cb <- hyperpar$cb
Expand Down
4 changes: 3 additions & 1 deletion man/UpdateGamma.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// UpdateGamma_cpp
Rcpp::List UpdateGamma_cpp(const Rcpp::List sobj, const Rcpp::List hyperpar, const Rcpp::List ini, const uint S, const std::string method, const bool MRF_G, const bool MRF_2b);
RcppExport SEXP _BayesSurvive_UpdateGamma_cpp(SEXP sobjSEXP, SEXP hyperparSEXP, SEXP iniSEXP, SEXP SSEXP, SEXP methodSEXP, SEXP MRF_GSEXP, SEXP MRF_2bSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Rcpp::List >::type sobj(sobjSEXP);
Rcpp::traits::input_parameter< const Rcpp::List >::type hyperpar(hyperparSEXP);
Rcpp::traits::input_parameter< const Rcpp::List >::type ini(iniSEXP);
Rcpp::traits::input_parameter< const uint >::type S(SSEXP);
Rcpp::traits::input_parameter< const std::string >::type method(methodSEXP);
Rcpp::traits::input_parameter< const bool >::type MRF_G(MRF_GSEXP);
Rcpp::traits::input_parameter< const bool >::type MRF_2b(MRF_2bSEXP);
rcpp_result_gen = Rcpp::wrap(UpdateGamma_cpp(sobj, hyperpar, ini, S, method, MRF_G, MRF_2b));
return rcpp_result_gen;
END_RCPP
}
// func_MCMC_graph_cpp
Rcpp::List func_MCMC_graph_cpp(const Rcpp::List sobj, const Rcpp::List hyperpar, const Rcpp::List ini, const uint S, const std::string method, const bool MRF_2b);
RcppExport SEXP _BayesSurvive_func_MCMC_graph_cpp(SEXP sobjSEXP, SEXP hyperparSEXP, SEXP iniSEXP, SEXP SSEXP, SEXP methodSEXP, SEXP MRF_2bSEXP) {
Expand Down
139 changes: 139 additions & 0 deletions src/UpdateGamma_cpp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
Rcpp::List UpdateGamma_cpp(
const Rcpp::List sobj,
const Rcpp::List hyperpar,
const Rcpp::List ini,
const uint S,
const std::string method,
const bool MRF_G,
const bool MRF_2b
){
//UpdateGamma <- function(sobj, hyperpar, ini, S, method, MRF_G, MRF_2b) {
// # Update latent variable selection indicators gamma with either independent Bernoulli prior
// # (standard approaches) or with MRF prior.

// p <- sobj$p
// tau <- hyperpar$tau
// cb <- hyperpar$cb
// pi <- hyperpar$pi.ga
// a <- hyperpar$a
// b <- hyperpar$b

// beta.ini <- ini$beta.ini
// gamma.ini <- ini$gamma.ini

// if (method %in% c("Pooled") && MRF_G) {
// G.ini <- hyperpar$G
// }

// # if (method %in% c("CoxBVSSL", "Sub-struct") ||
// # (method == "Pooled" && !MRF_G)) {
// if (!MRF_G) {
// G.ini <- ini$G.ini
// }

// # two different b in MRF prior for subgraphs G_ss and G_rs
// if (MRF_2b && !MRF_G) {
// for (g in 1:S) { # b1*G_ss
// G.ini[(g - 1) * p + (1:p), (g - 1) * p + (1:p)] <-
// b[1] * G.ini[(g - 1) * p + (1:p), (g - 1) * p + (1:p)]
// }
// for (g in 1:(S - 1)) { # b2*G_rs
// for (r in g:(S - 1)) {
// G.ini[(g - 1) * p + (1:p), r * p + (1:p)] <-
// G.ini[r * p + (1:p), (g - 1) * p + (1:p)] <-
// b[2] * G.ini[r * p + (1:p), (g - 1) * p + (1:p)]
// }
// }
// } else {
// # if (method %in% c("CoxBVSSL", "Sub-struct") ||
// # (method == "Pooled" && !MRF_G)) {
// if (!MRF_G) {
// G.ini <- G.ini * b
// }
// }

// if (method == "Pooled" && MRF_G) {
// post.gamma <- rep(0, p)

// for (j in 1:p) {
// # wa = dnorm(beta.ini[j], mean = 0, sd = cb*tau) * pi
// # wb = dnorm(beta.ini[j], mean = 0, sd = tau) * (1 - pi)
// # pgam = wa/(wa + wb)
// # u = runif(1)
// # gamma.ini[j] = ifelse(u < pgam, 1, 0)
// # post.gamma[j] = pgam



// beta <- beta.ini[j]

// ga.prop1 <- ga.prop0 <- gamma.ini # gamma with gamma_g,j=1 or 0
// ga.prop1[j] <- 1
// ga.prop0[j] <- 0
// ga.prop1 <- unlist(ga.prop1)
// ga.prop0 <- unlist(ga.prop0)

// wa <- (a * sum(ga.prop1) + t(ga.prop1) %*% G.ini %*% ga.prop1) +
// dnorm(beta, mean = 0, sd = tau * cb, log = TRUE)
// wb <- (a * sum(ga.prop0) + t(ga.prop0) %*% G.ini %*% ga.prop0) +
// dnorm(beta, mean = 0, sd = tau, log = TRUE)

// w_max <- max(wa, wb)
// pg <- exp(wa - w_max) / (exp(wa - w_max) + exp(wb - w_max))

// gamma.ini[j] <- as.numeric(runif(1) < pg)
// post.gamma[j] <- pg
// }
// } else {
// post.gamma <- rep(list(rep(0, p)), S)

// ## ? "Subgroup" might be not needed
// # if (method == "Subgroup") {
// if (MRF_G) {
// for (g in 1:S) { # loop through subgroups
// for (j in 1:p) {
// wa <- dnorm((beta.ini[[g]])[j], mean = 0, sd = cb * tau) * pi
// wb <- dnorm((beta.ini[[g]])[j], mean = 0, sd = tau) * (1 - pi)
// pgam <- wa / (wa + wb)
// u <- runif(1)
// gamma.ini[[g]][j] <- ifelse(u < pgam, 1, 0)
// post.gamma[[g]][j] <- pgam
// }
// }
// } else { # CoxBVS-SL or Sub-struct model

// for (g in 1:S) { # loop through subgroups
// for (j in 1:p) {
// beta <- (beta.ini[[g]])[j]

// ga.prop1 <- ga.prop0 <- gamma.ini # gamma with gamma_g,j=1 or 0
// ga.prop1[[g]][j] <- 1
// ga.prop0[[g]][j] <- 0
// ga.prop1 <- unlist(ga.prop1)
// ga.prop0 <- unlist(ga.prop0)

// wa <- (a * sum(ga.prop1) + t(ga.prop1) %*% G.ini %*% ga.prop1) +
// dnorm(beta, mean = 0, sd = tau * cb, log = TRUE)
// wb <- (a * sum(ga.prop0) + t(ga.prop0) %*% G.ini %*% ga.prop0) +
// dnorm(beta, mean = 0, sd = tau, log = TRUE)

// w_max <- max(wa, wb)
// pg <- exp(wa - w_max) / (exp(wa - w_max) + exp(wb - w_max))

// gamma.ini[[g]][j] <- as.numeric(runif(1) < pg)
// post.gamma[[g]][j] <- pg
// }
// }
// }
// }

// return(list(gamma.ini = gamma.ini, post.gamma = post.gamma))
Rcpp::List out = Rcpp::List::create(
Rcpp::Named("gamma_ini") = Rcpp::List::create(),
Rcpp::Named("post_gamma") = Rcpp::List::create()
);
return out;
}
2 changes: 2 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern SEXP _BayesSurvive_updateBH_cpp(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP)
extern SEXP _BayesSurvive_updateBH_list_cpp(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _BayesSurvive_updateRP_genomic_cpp(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _BayesSurvive_func_MCMC_graph_cpp(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _BayesSurvive_UpdateGamma_cpp(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);

static const R_CallMethodDef CallEntries[] = {
{"_BayesSurvive_calJpost_helper_cpp", (DL_FUNC) &_BayesSurvive_calJpost_helper_cpp, 9},
Expand All @@ -26,6 +27,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_BayesSurvive_updateBH_list_cpp", (DL_FUNC) &_BayesSurvive_updateBH_list_cpp, 7},
{"_BayesSurvive_updateRP_genomic_cpp", (DL_FUNC) &_BayesSurvive_updateRP_genomic_cpp, 12},
{"_BayesSurvive_func_MCMC_graph_cpp", (DL_FUNC) &_BayesSurvive_func_MCMC_graph_cpp, 6},
{"_BayesSurvive_UpdateGamma_cpp", (DL_FUNC) &_BayesSurvive_UpdateGamma_cpp, 7},
{NULL, NULL, 0}
};

Expand Down

0 comments on commit a46dad6

Please sign in to comment.