-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRunLogistic.cpp
83 lines (77 loc) · 2.03 KB
/
RunLogistic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
#include"LogitCD.h"
#include"RunLogistic.h"
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
arma::vec RunLogit(arma::mat const &x, arma::vec const &y, double lamb1, double lamb2, arma::vec b, double r, arma::mat const &a, arma::vec const &triRowAbsSums, int p, double alpha, char method)
{
int count = 0, n = x.n_rows;
arma::vec bnew, u;
if(method == 'n') u = 0.25 + lamb2 * triRowAbsSums;
while(count < 20){
if(method == 'n'){
bnew = Network(x, y, lamb1, lamb2, b, r, a, u, n, p);
}else if(method == 'm'){
bnew = MCP(x, y, lamb1, b, r, n, p);
}else{
bnew = Elastic(x, y, lamb1, b, alpha, n, p);
}
double dif = arma::accu(arma::abs(b - bnew))/(arma::accu(b != 0)+0.1);
if(dif < 0.001) break;
else{
b = bnew;
count++;
}
}
return(bnew);
}
// [[Rcpp::export]]
arma::vec RunNet(arma::mat& x, arma::vec& y, double lamb1, double lamb2, arma::vec b, double r, arma::mat& a, int p)
{
int count = 0, n = x.n_rows;
arma::vec bnew;
while(count < 20){
bnew = Network(x, y, lamb1, lamb2, b, r, a, n, p);
double dif = arma::accu(arma::abs(b - bnew))/p;
if(dif < 0.001) break;
else{
b = bnew;
count++;
}
}
return(bnew);
}
// [[Rcpp::export]]
arma::vec RunMCP(arma::mat& x, arma::vec& y, double lambda, arma::vec b, double r, int p)
{
int count = 0, n = x.n_rows;
arma::vec bnew;
while(count < 20){
bnew = MCP(x, y, lambda, b, r, n, p);
double dif = arma::accu(arma::abs(b - bnew))/p;
if(dif < 0.001) break;
else{
b = bnew;
count++;
}
}
return(bnew);
}
// [[Rcpp::export]]
arma::vec RunElastic(arma::mat& x, arma::vec& y, double lambda, arma::vec b, double alpha, int p)
{
int count = 0, n = x.n_rows;
arma::vec bnew;
while(count < 20){
bnew = Elastic(x, y, lambda, b, alpha, n, p);
double dif = arma::accu(arma::abs(b - bnew))/p;
if(dif < 0.001) break;
else{
b = bnew;
count++;
}
}
return(bnew);
}