Skip to content

Commit 2c03cca

Browse files
Marco Scutarigaborcsardi
Marco Scutari
authored andcommitted
version 3.7
1 parent e2f1917 commit 2c03cca

File tree

114 files changed

+5338
-3429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+5338
-3429
lines changed

Changelog

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
bnlearn (3.7)
2+
3+
* fixed the default setting for the number of particles in cpquery()
4+
(thanks Nishanth Upadhyaya).
5+
* reimplemented common test patterns in monolithic C functions to speed
6+
up constraint-based algorithms.
7+
* added support for conditional linear Gaussian (CLG) networks.
8+
* fixed several recursion bugs in choose.direction().
9+
* make read.{bif,dsc,net}() consistent with the `$<-` method for bn.fit
10+
objects (thanks Felix Rios).
11+
* support empty networks in read.{bif,dsc,net}().
12+
* fixed bug in hc(), triggered when using both random restarts and the
13+
maxp argument (thanks Irene Kaplow).
14+
* correctly initialize the Castelo & Siebes prior (thanks Irene Kaplow).
15+
* change the prior distribution for the training variable in classifiers
16+
from the uniform prior to the fitted distribution in the
17+
bn.fit.{naive,tan} object, for consistency with gRain and e1071 (thanks
18+
Bojan Mihaljevic).
19+
* note AIC and BIC scaling in the documentation (thanks Thomas Lefevre).
20+
* note limitations of {white,black}lists in tree.bayes() (thanks Bojan
21+
Mihaljevic).
22+
* better input sanitization in custom.fit() and bn.fit<-().
23+
* fixed .Call stack imbalance in random restarts (thanks James Jensen).
24+
* note limitations of predict()ing from bn objects (thanks Florian Sieck).
25+
126
bnlearn (3.6)
227

328
* support rectangular nodes in {graphviz,strength}.plot().
@@ -18,12 +43,12 @@ bnlearn (3.6)
1843
* attach the weights to the return value of cpdist(..., method = "lw").
1944
* changed the default number of simulations in cp{query, dist}().
2045
* support interval and multiple-valued evidence for likelihood weighting
21-
in cp{query,dist}().
46+
in cp{query,dist}().
2247
* implemented dedup() to pre-process continuous data.
2348
* fixed a scalability bug in blacklist sanitization (thanks Dong Yeon Cho).
2449
* fixed permutation test support in relevant().
2550
* reimplemented the conditional.test() backend completely in C for
26-
speed, it is now called indep.test().
51+
speed, it is now called indep.test().
2752

2853
bnlearn (3.5)
2954

DESCRIPTION

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Package: bnlearn
22
Type: Package
3-
Title: Bayesian network structure learning, parameter learning and
4-
inference
5-
Version: 3.6
6-
Date: 2014-06-17
3+
Title: Bayesian Network Structure Learning, Parameter Learning and
4+
Inference
5+
Version: 3.7
6+
Date: 2015-01-13
77
Depends: R (>= 2.14.0)
88
Imports: methods
99
Suggests: parallel, graph, Rgraphviz, lattice, gRain
@@ -14,8 +14,8 @@ Description: Bayesian network structure learning, parameter learning and
1414
This package implements constraint-based (GS, IAMB, Inter-IAMB, Fast-IAMB,
1515
MMPC, Hiton-PC), pairwise (ARACNE and Chow-Liu), score-based (Hill-Climbing
1616
and Tabu Search) and hybrid (MMHC and RSMAX2) structure learning algorithms
17-
for both discrete and Gaussian networks, along with many score functions
18-
and conditional independence tests.
17+
for discrete, Gaussian and conditional Gaussian networks, along with many
18+
score functions and conditional independence tests.
1919
The Naive Bayes and the Tree-Augmented Naive Bayes (TAN) classifiers are
2020
also implemented.
2121
Some utility functions (model comparison and manipulation, random data
@@ -27,7 +27,7 @@ Description: Bayesian network structure learning, parameter learning and
2727
URL: http://www.bnlearn.com/
2828
License: GPL (>= 2)
2929
LazyData: yes
30-
Packaged: 2014-06-17 17:15:42 UTC; fizban
30+
Packaged: 2015-01-13 23:45:31 UTC; fizban
3131
NeedsCompilation: yes
3232
Repository: CRAN
33-
Date/Publication: 2014-06-17 21:16:12
33+
Date/Publication: 2015-01-14 01:52:50

MD5

+113-100
Large diffs are not rendered by default.

NAMESPACE

+5-6
Original file line numberDiff line numberDiff line change
@@ -142,28 +142,26 @@ S3method(as.graphNEL, bn.fit)
142142
S3method(as.graphAM, bn)
143143
S3method(as.bn, graphAM)
144144
S3method(as.graphAM, bn.fit)
145-
S3method(ci.test, character)
146-
S3method(ci.test, data.frame)
147-
S3method(ci.test, matrix)
148-
S3method(ci.test, numeric)
149-
S3method(ci.test, factor)
150-
S3method(ci.test, default)
151145
S3method(print, "bn.fit")
152146
S3method(print, "bn.fit.dnode")
153147
S3method(print, "bn.fit.onode")
154148
S3method(print, "bn.fit.gnode")
149+
S3method(print, "bn.fit.cgnode")
155150
S3method(residuals, "bn.fit")
156151
S3method(residuals, "bn.fit.dnode")
157152
S3method(residuals, "bn.fit.onode")
158153
S3method(residuals, "bn.fit.gnode")
154+
S3method(residuals, "bn.fit.cgnode")
159155
S3method(fitted, "bn.fit")
160156
S3method(fitted, "bn.fit.dnode")
161157
S3method(fitted, "bn.fit.onode")
162158
S3method(fitted, "bn.fit.gnode")
159+
S3method(fitted, "bn.fit.cgnode")
163160
S3method(coef, "bn.fit")
164161
S3method(coef, "bn.fit.dnode")
165162
S3method(coef, "bn.fit.onode")
166163
S3method(coef, "bn.fit.gnode")
164+
S3method(coef, "bn.fit.cgnode")
167165
S3method(print, "mvber.moments")
168166
S3method(print, "bn.kcv")
169167
S3method(plot, "bn.strength")
@@ -172,6 +170,7 @@ S3method(predict, "bn.fit")
172170
S3method(predict, "bn.fit.dnode")
173171
S3method(predict, "bn.fit.onode")
174172
S3method(predict, "bn.fit.gnode")
173+
S3method(predict, "bn.fit.cgnode")
175174
S3method(predict, "bn.naive")
176175
S3method(predict, "bn.tan")
177176
S3method("$<-", "bn.fit")

R/arc.operations.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ arc.operations = function(x, from, to, op = NULL, check.cycles, update = TRUE,
88
# check x's class.
99
check.bn(x)
1010
# check the op code.
11-
if (!(op %in% available.ops))
11+
if (op %!in% available.ops)
1212
stop("valid op codes are 'set', 'drop' and 'reverse'.")
1313
# a valid node is needed.
1414
check.nodes(nodes = from, graph = x, max.nodes = 1)

R/arc.strength.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ arc.strength.boot = function(data, cluster = NULL, R, m, algorithm,
205205
# get the number of slaves.
206206
s = nSlaves(cluster)
207207

208-
res = parLapply(cluster, rep(ceiling(R / s), s), bootstrap.batch,
208+
res = parallel::parLapply(cluster, rep(ceiling(R / s), s), bootstrap.batch,
209209
data = data, m = m, arcs = arcs, algorithm = algorithm,
210210
algorithm.args = algorithm.args, cpdag = cpdag, debug = debug)
211211

R/backend-indep.R

+35-76
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ neighbour = function(x, mb, data, alpha, B = NULL, whitelist, blacklist,
7878
# whitelisted nodes are included (arc orientation is irrelevant),
7979
# and blacklisted nodes are removed if both directed arcs are banned
8080
# and both are not in the whitelist.
81-
nbrhood = nbrhood[!(nbrhood %in% blacklisted)]
81+
nbrhood = nbrhood[nbrhood %!in% blacklisted]
8282
nbrhood = unique(c(nbrhood, whitelisted))
8383

8484
# use backtracking for a further screening of the nodes to be checked.
@@ -92,7 +92,7 @@ neighbour = function(x, mb, data, alpha, B = NULL, whitelist, blacklist,
9292

9393
# known.bad nodes are not to be checked for inclusion and/or used in
9494
# the subsets.
95-
nbrhood = nbrhood[!(nbrhood %in% known.bad)]
95+
nbrhood = nbrhood[nbrhood %!in% known.bad]
9696

9797
}#THEN
9898

@@ -133,7 +133,7 @@ neighbour = function(x, mb, data, alpha, B = NULL, whitelist, blacklist,
133133
cat(" > dsep.set = '", dsep.set, "'\n")
134134

135135
a = allsubs.test(x = x, y = y, sx = dsep.set, min = ifelse(empty.dsep, 0, 1),
136-
data = data, test = test, alpha = alpha, B = B, debug = debug)
136+
data = data, test = test, alpha = alpha, B = B, debug = debug)[1]
137137

138138
if (a > alpha) {
139139

@@ -156,7 +156,7 @@ neighbour = function(x, mb, data, alpha, B = NULL, whitelist, blacklist,
156156

157157
# do not even try to remove whitelisted nodes; on the other hand, known.good
158158
# nodes from backtracking should be checked to remove false positives.
159-
sapply(nbrhood[!(nbrhood %in% whitelisted)], nbr, x = x, mb = mb, test = test)
159+
sapply(nbrhood[nbrhood %!in% whitelisted], nbr, x = x, mb = mb, test = test)
160160

161161
return(list(mb = mb[[x]], nbr = nbrhood))
162162

@@ -177,11 +177,12 @@ vstruct.detect = function(nodes, arcs, mb, data, alpha, B = NULL, test,
177177

178178
tos = parents.backend(arcs, x, TRUE)
179179

180-
if (length(tos) < 2) return(NULL)
180+
if (length(tos) < 2)
181+
return(NULL)
181182

182183
# build a list of possibile parents for the node x, i.e. all the subsets
183184
# of size 2 of the nodes connected to x by incoming arcs.
184-
tos.combs = subsets(length(tos), 2, tos)
185+
tos.combs = subsets(tos, 2)
185186
vs = NULL
186187

187188
for (j in 1:nrow(tos.combs)) {
@@ -193,70 +194,28 @@ vstruct.detect = function(nodes, arcs, mb, data, alpha, B = NULL, test,
193194
cat(" * checking", y, "->", x, "<-", z, "\n")
194195

195196
# check there's no arc from y to z and vice versa.
196-
if(!is.listed(arcs, c(y, z)) &&
197-
!is.listed(arcs, c(z, y))) {
198-
199-
mby = mb[[y]][['mb']]
200-
mbz = mb[[z]][['mb']]
201-
202-
# compute mb(y) - {x,z} and mb(z) - {x,y}
203-
mby = mby[!(mby %in% c(x, z))]
204-
mbz = mbz[!(mbz %in% c(x, y))]
205-
206-
# choose the smallest one to cut down the number of subsets to test.
207-
dsep.set = smaller(mby, mbz)
208-
209-
if (debug)
210-
cat(" > chosen d-separating set: '", dsep.set, "'\n")
211-
212-
k = 0
213-
max_a = a = 0
214-
215-
repeat {
216-
217-
dsep.subsets = subsets(length(dsep.set), k, dsep.set)
218-
219-
for (s in 1:nrow(dsep.subsets)) {
197+
if (is.listed(arcs, c(y, z), either = TRUE))
198+
next
220199

221-
a = indep.test(y, z, c(dsep.subsets[s,], x), data = data,
222-
test = test, B = B, alpha = alpha)
223-
if (debug)
224-
cat(" > testing", y, "vs", z, "given", c(dsep.subsets[s,], x), "(", a, ")\n")
225-
max_a = max(a, max_a)
226-
if (a > alpha) {
200+
# choose the smallest of mb(y) - {x,z} and mb(z) - {x,y} to cut down
201+
# the number of subsets to test.
202+
dsep.set = smaller(setdiff(mb[[y]][['mb']], c(x, z)),
203+
setdiff(mb[[z]][['mb']], c(x, y)))
227204

228-
if (debug)
229-
cat(" >", y, "and", z, "are independent given '", c(dsep.subsets[s,], x), "' (", a, ")\n")
230-
break
231-
232-
}#THEN
233-
234-
}#FOR
235-
236-
if (a <= alpha) {
237-
238-
if (k < length(dsep.set)) {
239-
240-
k = k + 1
241-
242-
}#THEN
243-
else {
244-
245-
if (debug)
246-
cat(" @ detected v-structure", y, "->", x, "<-", z, "\n")
247-
vs = rbind(vs, data.frame(max_a, y, x, z, stringsAsFactors = FALSE))
248-
break
249-
250-
}#ELSE
205+
if (debug)
206+
cat(" > chosen d-separating set: '", dsep.set, "'\n")
251207

252-
}#THEN
253-
else {
208+
assoc = allsubs.test(x = y, y = z, fixed = x, sx = dsep.set, data = data,
209+
test = test, B = B, alpha = alpha, debug = debug)
210+
a = assoc[1]
211+
max_a = assoc[3]
254212

255-
break
213+
if (a <= alpha) {
256214

257-
}#ELSE
215+
if (debug)
216+
cat(" @ detected v-structure", y, "->", x, "<-", z, "\n")
258217

259-
}#REPEAT
218+
vs = rbind(vs, data.frame(max_a, y, x, z, stringsAsFactors = FALSE))
260219

261220
}#THEN
262221

@@ -288,13 +247,13 @@ vstruct.apply = function(arcs, vs, nodes, strict, debug = FALSE) {
288247
}#THEN
289248

290249
if (strict)
291-
stop(paste("vstructure", v["y"], "->", v["x"], "<-", v["z"],
292-
"is not applicable, because one or both arcs are oriented",
293-
"in the opposite direction."))
250+
stop("vstructure ", v["y"], " -> ", v["x"], " <- ", v["z"],
251+
" is not applicable, because one or both arcs are oriented",
252+
" in the opposite direction.")
294253
else
295-
warning(paste("vstructure", v["y"], "->", v["x"], "<-", v["z"],
296-
"is not applicable, because one or both arcs are oriented",
297-
"in the opposite direction."))
254+
warning("vstructure ", v["y"], " -> ", v["x"], " <- ", v["z"],
255+
" is not applicable, because one or both arcs are oriented",
256+
" in the opposite direction.")
298257

299258
return(NULL)
300259

@@ -314,13 +273,13 @@ vstruct.apply = function(arcs, vs, nodes, strict, debug = FALSE) {
314273
}#THEN
315274

316275
if (strict)
317-
stop(paste("vstructure", v["y"], "->", v["x"], "<-", v["z"],
318-
"is not applicable, because one or both arcs introduce cycles",
319-
"in the graph."))
276+
stop("vstructure ", v["y"], " -> ", v["x"], " <- ", v["z"],
277+
" is not applicable, because one or both arcs introduce cycles",
278+
" in the graph.")
320279
else
321-
warning(paste("vstructure", v["y"], "->", v["x"], "<-", v["z"],
322-
"is not applicable, because one or both arcs introduce cycles",
323-
"in the graph."))
280+
warning("vstructure ", v["y"], " -> ", v["x"], " <- ", v["z"],
281+
" is not applicable, because one or both arcs introduce cycles",
282+
" in the graph.")
324283

325284
return(NULL)
326285

R/backend-s4.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
if (!is.null(x$learning$blacklist))
4444
x$learning$blacklist[] = value[match(x$learning$blacklist, nodes)]
4545
# ... Castelo & Siebes prior specification...
46-
if (("prior" %in% names(x$learning$args)) &&
46+
if (("prior" %in% names(x$learning$args)) &&
4747
(x$learning$args$prior == "cs")) {
4848

49-
x$learning$args$beta[, c("from", "to")] =
49+
x$learning$args$beta[, c("from", "to")] =
5050
value[match(x$learning$args$beta[, c("from", "to")], nodes)]
5151
attr(x$learning$args$beta, "nodes") = value
5252

@@ -99,7 +99,7 @@
9999
}#FOR
100100

101101
# relabel the nodes.
102-
names(x) = value
102+
names(x) = value
103103

104104
# update the training node of classifiers.
105105
if (is(x, c("bn.naive", "bn.tan")))

R/backend-score.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ arcs.to.be.reversed = function(arcs, blacklist, nparents, maxp = Inf) {
5050
arcs = arcs[!which.listed(arcs[, c(2, 1), drop = FALSE], blacklist), , drop = FALSE]
5151

5252
if (!missing(nparents))
53-
arcs = arcs[nparents[arcs[, 1]] < maxp, ]
53+
arcs = arcs[nparents[arcs[, 1]] < maxp, , drop = FALSE]
5454

5555
return(arcs)
5656

0 commit comments

Comments
 (0)