Skip to content

Commit 042318c

Browse files
styler::style_pkg
1 parent 813364b commit 042318c

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

vignettes/performance.Rmd

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,20 @@ while keeping the user experience smooth.
4343

4444
### Comparison
4545
```{r dagitty-conversion-fn-def, collapse=TRUE}
46-
as_dagitty_bn <- function( x, ... ){
47-
nodes <- names( x$nodes )
48-
ee <- c()
49-
if( nrow(x$arcs) > 0 ){
50-
ee <- apply(x$arcs, 1, function(a) {paste(a[1],"->",a[2])})
51-
}
52-
dagitty::dagitty(paste("pdag{ " ,
53-
paste(nodes, collapse="\n"),
54-
paste(ee, collapse="\n"),
55-
" }"))
46+
as_dagitty_bn <- function(x, ...) {
47+
nodes <- names(x$nodes)
48+
ee <- c()
49+
if (nrow(x$arcs) > 0) {
50+
ee <- apply(x$arcs, 1, function(a) {
51+
paste(a[1], "->", a[2])
52+
})
53+
}
54+
dagitty::dagitty(paste(
55+
"pdag{ ",
56+
paste(nodes, collapse = "\n"),
57+
paste(ee, collapse = "\n"),
58+
" }"
59+
))
5660
}
5761
```
5862

@@ -73,8 +77,10 @@ cg <- caugi::as_caugi(ig, class = "DAG")
7377
forms <- lapply(igraph::V(ig)$name, function(v) {
7478
pa <- names(igraph::neighbors(ig, v, mode = "in"))
7579
if (length(pa) == 0) {
76-
as.formula(paste0(v, " ~ 1"))} else {
77-
as.formula(paste(v, "~", paste(pa, collapse = "+")))}
80+
as.formula(paste0(v, " ~ 1"))
81+
} else {
82+
as.formula(paste(v, "~", paste(pa, collapse = "+")))
83+
}
7884
})
7985
ggmg <- do.call(ggm::DAG, forms)
8086
bng <- bnlearn::as.bn(ig)
@@ -118,12 +124,14 @@ bench::mark(
118124
```{r benchmark-d-sep}
119125
bench::mark(
120126
caugi = caugi::d_separated(cg, "V50", "V18", c("V8", "V20", "V43")),
121-
caugi_index = caugi::d_separated(cg, X_index = 50L, Y_index = 18L,
122-
Z_index = c(8L, 20L, 43L)),
127+
caugi_index = caugi::d_separated(cg,
128+
X_index = 50L, Y_index = 18L,
129+
Z_index = c(8L, 20L, 43L)
130+
),
123131
caugi_rust = caugi:::d_separated_ptr(cg@ptr, 49L, 17L, c(7L, 19L, 42L)),
124132
bnlearn = bnlearn::dsep(bng, "V50", "V18", c("V8", "V20", "V43")),
125-
ggm = ggm::dSep(ggmg, "V50", "V18", c("V8", "V20", "V43")),
126-
dagitty = dagitty::dseparated(dg, "V50", "V18", c("V8", "V20", "V43")),
133+
ggm = ggm::dSep(ggmg, "V50", "V18", c("V8", "V20", "V43")),
134+
dagitty = dagitty::dseparated(dg, "V50", "V18", c("V8", "V20", "V43")),
127135
check = FALSE # ggm returns FALSE, so check fails
128136
) |> dplyr::arrange(median)
129137
```

0 commit comments

Comments
 (0)