Skip to content

Commit

Permalink
Translated almost all hh_nlambda_loop() (#17)
Browse files Browse the repository at this point in the history
The only missing part now are bits related to and dependend on the translation of `count_nonzero_a()`.
  • Loading branch information
wleoncio committed Feb 14, 2024
1 parent fdc1bc4 commit 328f1ee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ Suggests:
License: GPL-3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Config/testthat/edition: 3
16 changes: 15 additions & 1 deletion man/MADMMplasso.Rd

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

27 changes: 14 additions & 13 deletions src/hh_nlambda_loop_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Rcpp::List hh_nlambda_loop_cpp(
arma::vec non_zero_theta;
Rcpp::List my_obj;
arma::vec n_main_terms;
Rcpp::List lam_list;
arma::vec lam_list;
arma::mat y_hat = y;
unsigned int hh = 0;
while (hh <= nlambda) {
Expand All @@ -69,27 +69,28 @@ Rcpp::List hh_nlambda_loop_cpp(
beta_hat = Rcpp::as<arma::mat>(my_values_hh["beta_hat"]);
y_hat = Rcpp::as<arma::mat>(my_values_hh["y_hat"]);

// beta1 <- as(beta * (abs(beta) > tol), "sparseMatrix")
// theta1 <- as.sparse3Darray(theta * (abs(theta) > tol))
// beta_hat1 <- as(beta_hat * (abs(beta_hat) > tol), "sparseMatrix")
arma::sp_mat beta1(beta % (abs(beta) > tol));
arma::cube theta1(theta % (abs(theta) > tol)); // should be sparse, but Arma doesn't have sp_cube
arma::sp_mat beta_hat1(beta_hat % (abs(beta_hat) > tol));

// n_interaction_terms <- count_nonzero_a((theta1))
// n_interaction_terms <- count_nonzero_a((theta1)) TODO: translate count_nonzero_a()

// n_main_terms <- (c(n_main_terms, count_nonzero_a((beta1))))

double obj1 = arma::accu(arma::pow(y - y_hat, 2)) / (D * N);
// obj <- c(obj, obj1)
obj.resize(obj.n_elem + 1);
obj(obj.n_elem - 1) = obj1;

// non_zero_theta <- (c(non_zero_theta, n_interaction_terms))
// lam_list <- (c(lam_list, lambda))

// BETA0[[hh]] <- beta0
// THETA0[[hh]] <- theta0
// BETA[[hh]] <- as(beta1, "sparseMatrix")
// BETA_hat[[hh]] <- as(beta_hat1, "sparseMatrix")
arma::join_vert(lam_list, lambda);

// Y_HAT[[hh]] <- y_hat
// THETA[[hh]] <- as.sparse3Darray(theta1)
BETA0[hh] = beta0;
THETA0[hh] = theta0;
BETA[hh] = arma::conv_to<arma::sp_mat>::from(beta1);
BETA_hat[hh] = arma::conv_to<arma::sp_mat>::from(beta_hat1);
Y_HAT[hh] = y_hat;
THETA[hh] = theta1;

if (hh == 0) {
Rcpp::Rcout << hh << n_main_terms(hh) << non_zero_theta(hh) << obj1 << std::endl;
Expand Down

0 comments on commit 328f1ee

Please sign in to comment.