Skip to content

Commit

Permalink
update QRWMR
Browse files Browse the repository at this point in the history
  • Loading branch information
Jie Ren committed Feb 8, 2025
1 parent 82b6d6a commit 0fa1cec
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 22 deletions.
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.0.0
Date: 2022-08-17 21:15:59 UTC
SHA: 9e26b77dc5aeb764214c63eb665d892685bba329
Version: 1.0.1
Date: 2024-02-22 02:19:13 UTC
SHA: 82b6d6aecea6a19861c56747df859ca61158c0bf
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: regnet
Type: Package
Title: Network-Based Regularization for Generalized Linear Models
Version: 1.0.1
Version: 1.0.2
Author: Jie Ren, Luann C. Jung, Yinhao Du, Cen Wu, Yu Jiang, Junhao Liu
Maintainer: Jie Ren <[email protected]>
Description: Network-based regularization has achieved success in variable selection for
Expand All @@ -18,7 +18,7 @@ LazyData: true
Imports: glmnet, stats, Rcpp, igraph, utils
URL: https://github.com/jrhub/regnet
BugReports: https://github.com/jrhub/regnet/issues
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
LinkingTo: Rcpp, RcppArmadillo
Suggests:
testthat,
Expand Down
6 changes: 3 additions & 3 deletions R/plot.regnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#' @return an object of class "igraph" is returned in default.
#' When \emph{subnetworks=TRUE}, a list of "igraph" objects (sub-networks) is returned.
#'
#' @usage \method{plot}{regnet}(x, subnetworks=FALSE, vsize=10, labelDist=2, minVertices=2, theta=5, \dots)
#' @seealso \code{\link{regnet}}
#'
#' @examples
Expand All @@ -36,14 +35,15 @@ plot.regnet=function(x, subnetworks=FALSE, vsize=10, labelDist=2, minVertices=2,

adjacency = x$Adj
if(nrow(adjacency)==0) return(NULL)
net0 <- igraph::graph.adjacency(adjacency, mode="undirected", weighted=TRUE, diag=FALSE)
# net0 <- igraph::graph.adjacency(adjacency, mode="undirected", weighted=TRUE, diag=FALSE)
net0 <- igraph::graph_from_adjacency_matrix(adjacency, mode="undirected", weighted=TRUE, diag=FALSE)
igraph::V(net0)$color = "skyblue"

if(!subnetworks){
plot(net0, vertex.size=vsize, edge.color="gray40", vertex.label=NA)
net0
}else{
nets = igraph::decompose.graph(net0, mode="weak", min.vertices = minVertices)
nets = igraph::decompose(net0, mode="weak", min.vertices = minVertices)
largest = 0
if(length(nets)==0) return(NULL)
for(i in 1: length(nets)){
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ available for continuous and survival responses.
<!-- -->

install.packages("devtools")
devtools::install_github("jrhub/regnet")
devtools::install_github("jrhub/regnet") #v1.0.2

- Released versions of regnet are available on CRAN
[(link)](https://cran.r-project.org/package=regnet), and can be
Expand Down
10 changes: 9 additions & 1 deletion man/plot.regnet.Rd

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

1 change: 1 addition & 0 deletions regnet.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 641f086e-8023-4b4b-b547-3b0a0d51ef10

RestoreWorkspace: Default
SaveWorkspace: Default
Expand Down
24 changes: 19 additions & 5 deletions src/QR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ using namespace Rcpp;
using namespace arma;


arma::vec QRWMR(arma::mat const &x, arma::vec const &y, arma::vec b)
arma::vec QRWMR(arma::mat const &x, arma::vec const &y, arma::vec b, bool debugging)
{
int p = x.n_cols, n = x.n_rows;
arma::vec t = y - x * b;
arma::vec u(n, fill::none), w(n, fill::none);
arma::uvec index;

for(int m = 0; m < p; m++){
t += x.col(m) * b(m);
u = t/x.col(m);
w = arma::abs(x.col(m))/n;


u.replace(datum::nan, 0);

if (debugging) {
Rcpp::Rcout << "Values of u before NaN replacement for column " << m << ":\n";
u.print(Rcpp::Rcout);
}

index = arma::sort_index(u);
// arma::vec _w = w(index), _u = u(index);

Expand All @@ -35,17 +42,24 @@ arma::vec QRWMR(arma::mat const &x, arma::vec const &y, arma::vec b)
return(b);
}

void QRWMR(arma::mat const &x, arma::vec const &y, arma::vec &b, arma::mat const &w, arma::vec const &totalWeights)
void QRWMR(arma::mat const &x, arma::vec const &y, arma::vec &b, arma::mat const &w, arma::vec const &totalWeights, bool debugging)
{
int p = x.n_cols, n = x.n_rows;
arma::vec t = y - x * b;
arma::vec u(n, fill::none);
arma::uvec index;

for(int m = 0; m < p; m++){
t += x.col(m) * b(m);
u = t/x.col(m);

if (debugging) {
Rcpp::Rcout << "Values of u before NaN replacement for column " << m << ":\n";
u.print(Rcpp::Rcout);
}

u.replace(datum::nan, 0);

index = arma::sort_index(u);

double SUM = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/QR.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include<RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]

arma::vec QRWMR(arma::mat const &x, arma::vec const &y, arma::vec b);
void QRWMR(arma::mat const &x, arma::vec const &y, arma::vec &b, arma::mat const &w, arma::vec const &totalWeights);
arma::vec QRWMR(arma::mat const &x, arma::vec const &y, arma::vec b, bool debugging);
void QRWMR(arma::mat const &x, arma::vec const &y, arma::vec &b, arma::mat const &w, arma::vec const &totalWeights, bool debugging);

#endif
#endif
4 changes: 2 additions & 2 deletions src/RunCont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ arma::vec RunCont_robust(arma::mat const &xc, arma::mat const &xg, arma::vec con
arma::vec bold(p, fill::none), yc, yg; // bc = bc0, bg = bg0;
arma::mat const wc = arma::abs(xc)/n;
arma::vec const totalWeights = arma::sum(wc, 0).t();

while(count < 20){
yc = y - xg * bg;
// bc = QRWMR(xc, yc, bc);
QRWMR(xc, yc, bc, wc, totalWeights);
QRWMR(xc, yc, bc, wc, totalWeights, debugging);
yg = y - xc * bc;
bold = bg;
if(method == 'n'){
Expand Down
4 changes: 2 additions & 2 deletions src/RunSurv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ arma::vec RunSurv_robust(arma::mat const &xc, arma::mat const &xg, arma::vec con
while(count < 20){
yc = y - xg * bg;
// bc = QRWMR(xc, yc, bc);
QRWMR(xc, yc, bc, wc, totalWeights);
QRWMR(xc, yc, bc, wc, totalWeights, debugging);
yg = y - xc * bc;
bold = bg;
if(method == 'n'){
Expand Down Expand Up @@ -62,7 +62,7 @@ void RunSurv_robust_warm(arma::mat const &xc, arma::mat const &xg, arma::vec con
while(count < 20){
yc = y - xg * bg;
// bc = QRWMR(xc, yc, bc);
QRWMR(xc, yc, bc, wc, totalWeights);
QRWMR(xc, yc, bc, wc, totalWeights, false);
yg = y - xc * bc;
bold = bg;
if(method == 'n'){
Expand Down

0 comments on commit 0fa1cec

Please sign in to comment.