|
a |
|
b/A_Simple_Example.R |
|
|
1 |
library(pROC) |
|
|
2 |
library(MASS) |
|
|
3 |
library(glmnet) |
|
|
4 |
# ------------------------------------------ |
|
|
5 |
# Please first set the path |
|
|
6 |
# working_dir = "C:/Users/dell/Desktop/NSLR" |
|
|
7 |
# setwd(working_dir) |
|
|
8 |
|
|
|
9 |
source('Fun_Auxiliary.R') |
|
|
10 |
source('Fun_NSLR.R') |
|
|
11 |
|
|
|
12 |
# ------------------------------------------ |
|
|
13 |
# Generate a simple simulation data |
|
|
14 |
snrlam0 = 3 |
|
|
15 |
f.num0 = 100 |
|
|
16 |
sim.data = GET.SIM.DATA2(smaple.num = 700, feature.num=f.num0, random.seed = 10, snrlam=snrlam0) |
|
|
17 |
adj = get_sim_prior_Net(f.num0, 40, 0.3,0.05) |
|
|
18 |
|
|
|
19 |
Train.id = 1:300 |
|
|
20 |
Valid.id = 301:500 |
|
|
21 |
w.true = sim.data$w |
|
|
22 |
|
|
|
23 |
# Training data |
|
|
24 |
X1 = sim.data$X[Train.id,]; y1 =sim.data$y[Train.id]; |
|
|
25 |
# Testing data |
|
|
26 |
X2 = sim.data$X[Valid.id,]; y2 =sim.data$y[Valid.id]; |
|
|
27 |
|
|
|
28 |
# Non Normalized Laplacian Matrix" |
|
|
29 |
PM = get.penalityMatrix(adj,X1, y1) |
|
|
30 |
|
|
|
31 |
# ---------------------------------------- |
|
|
32 |
# ---------------------------------------- |
|
|
33 |
# Two regularization parameters |
|
|
34 |
lambda = 0.2 |
|
|
35 |
alpha = 0.3 |
|
|
36 |
|
|
|
37 |
# ---------------------------------------- |
|
|
38 |
# A typical logistic regression model and four regularized logistic regession models |
|
|
39 |
# ---------------------------------------- |
|
|
40 |
|
|
|
41 |
# Typical Logistic Regression Model |
|
|
42 |
out1 = SGNLR(X1, y1, PM$M.c, lambda=0, alpha=0, niter=20) |
|
|
43 |
|
|
|
44 |
# L1 (Lasso) Regularized Logistic Regression Model |
|
|
45 |
out2 = SGNLR(X1, y1, PM$M.lasso, lambda, alpha, niter=20) |
|
|
46 |
|
|
|
47 |
# Elastic Net Regularized Logistic Regression Model |
|
|
48 |
out3 = SGNLR(X1, y1, PM$M.elastic, lambda, alpha, niter=20) |
|
|
49 |
|
|
|
50 |
# Classical Network-regularized Logistic Regression Model |
|
|
51 |
out4 = SGNLR(X1, y1, PM$M.network, lambda, alpha, niter=20) |
|
|
52 |
|
|
|
53 |
# Adaptive Network-regularized Logistic Regression Model |
|
|
54 |
out5 = SGNLR(X1, y1, PM$M.AdaptNet, lambda, alpha, niter=20) |
|
|
55 |
|
|
|
56 |
# Absolute Network-regularized Logistic Regression Model |
|
|
57 |
out6 = abs.SNLR(X1, y1, PM$M.network, lambda, alpha, niter=20) |
|
|
58 |
|
|
|
59 |
# Testing |
|
|
60 |
res1 = predict.SGNLR(X2,y2,out1$w) |
|
|
61 |
res2 = predict.SGNLR(X2,y2,out2$w) |
|
|
62 |
res3 = predict.SGNLR(X2,y2,out3$w) |
|
|
63 |
res4 = predict.SGNLR(X2,y2,out4$w) |
|
|
64 |
res5 = predict.SGNLR(X2,y2,out5$w) |
|
|
65 |
res6 = predict.SGNLR(X2,y2,out6$w) |
|
|
66 |
|
|
|
67 |
multi.method.AUC = c(res1$AUC,res2$AUC,res3$AUC,res4$AUC,res5$AUC,res6$AUC) |
|
|
68 |
names(multi.method.AUC) = c("LR","Lasso.LR","Elastic.LR","Network.LR","AdaNet.LR","AbsNet.LR") |
|
|
69 |
|
|
|
70 |
# Result in term of AUC |
|
|
71 |
print(multi.method.AUC) |
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|