Skip to content

Commit c360638

Browse files
committed
export print.performance; build readme
1 parent 753781f commit c360638

5 files changed

Lines changed: 37 additions & 15 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
S3method(plot,blkmat)
44
S3method(plot,penderiv)
5+
S3method(print,performance)
56
export(compute_derivative)
67
export(compute_penalty)
78
export(gen_prec_sbm)

R/performance.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ performance <- function(hatOmega, Omega) {
163163
}
164164

165165

166+
#' @export
166167
#' @noRd
167168

168169
print.performance <- function(x, ...) {

README.Rmd

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,25 @@ library(grasps)
105105
set.seed(1234)
106106
107107
## block-structured precision matrix based on SBM
108-
sim <- gen_prec_sbm(d = 100, K = 5,
109-
within.prob = 0.5, between.prob = 0.05,
108+
sim <- gen_prec_sbm(d = 30, K = 3,
109+
within.prob = 0.25, between.prob = 0.05,
110110
weight.dists = list("gamma", "unif"),
111-
weight.paras = list(c(shape = 20, scale = 5), c(min = 0, max = 1)),
111+
weight.paras = list(c(shape = 100, rate = 10),
112+
c(min = 0, max = 5)),
112113
cond.target = 100)
113114
114115
## synthetic data
115116
library(MASS)
116-
X <- MASS::mvrnorm(n = 50, mu = rep(0, 100), Sigma = sim$Sigma)
117+
X <- mvrnorm(n = 20, mu = rep(0, 30), Sigma = sim$Sigma)
117118
118119
## solution
119-
res <- grasps(X = X, membership = sim$membership, penalty = "lasso", crit = "BIC")
120+
res <- grasps(X = X, membership = sim$membership, penalty = "adapt", crit = "BIC")
120121
121122
## visualization
122123
plot(res)
124+
125+
## performance
126+
performance(hatOmega = res$hatOmega, Omega = sim$Omega)
123127
```
124128

125129

README.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,51 @@ You can install the development version of **grasps** from
6363

6464
``` r
6565
library(grasps)
66-
#>
67-
#> Attaching package: 'grasps'
68-
#> The following object is masked from 'package:stats':
69-
#>
70-
#> deriv
7166

7267
## reproducibility for everything
7368
set.seed(1234)
7469

7570
## block-structured precision matrix based on SBM
76-
sim <- gen_prec_sbm(d = 100, K = 5,
77-
within.prob = 0.5, between.prob = 0.05,
71+
sim <- gen_prec_sbm(d = 30, K = 3,
72+
within.prob = 0.25, between.prob = 0.05,
7873
weight.dists = list("gamma", "unif"),
79-
weight.paras = list(c(shape = 20, scale = 5), c(min = 0, max = 1)),
74+
weight.paras = list(c(shape = 100, rate = 10),
75+
c(min = 0, max = 5)),
8076
cond.target = 100)
8177

8278
## synthetic data
8379
library(MASS)
84-
X <- MASS::mvrnorm(n = 50, mu = rep(0, 100), Sigma = sim$Sigma)
80+
X <- mvrnorm(n = 20, mu = rep(0, 30), Sigma = sim$Sigma)
8581

8682
## solution
87-
res <- grasps(X = X, membership = sim$membership, penalty = "lasso", crit = "BIC")
83+
res <- grasps(X = X, membership = sim$membership, penalty = "adapt", crit = "BIC")
8884

8985
## visualization
9086
plot(res)
9187
```
9288

9389
<img src="man/figures/README-unnamed-chunk-2-1.png" width="100%" />
9490

91+
``` r
92+
93+
## performance
94+
performance(hatOmega = res$hatOmega, Omega = sim$Omega)
95+
#> measure value
96+
#> 1 sparsity 0.8414
97+
#> 2 Frobenius 86.8888
98+
#> 3 KL 10.1162
99+
#> 4 quadratic 139.5146
100+
#> 5 spectral 39.1448
101+
#> 6 TP 24.0000
102+
#> 7 TN 342.0000
103+
#> 8 FP 45.0000
104+
#> 9 FN 24.0000
105+
#> 10 TPR 0.5000
106+
#> 11 FPR 0.1163
107+
#> 12 F1 0.4103
108+
#> 13 MCC 0.3291
109+
```
110+
95111
## Reference
96112

97113
<div id="refs" class="references csl-bib-body hanging-indent">
-9.31 KB
Loading

0 commit comments

Comments
 (0)