Skip to content

Commit a5c7b01

Browse files
Marco Scutaricran-robot
Marco Scutari
authored andcommitted
version 4.1
1 parent b736d3c commit a5c7b01

File tree

124 files changed

+3552
-1687
lines changed

Some content is hidden

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

124 files changed

+3552
-1687
lines changed

Changelog

+30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
bnlearn (4.1)
2+
3+
* fixed memory corruption in dsep() (thanks Dominik Muller).
4+
* added the marginal uniform prior.
5+
* fixed the optimized score cache for the Castelo & Siebes and for the
6+
marginal uniform priors, which were affected by several subtle bugs.
7+
* bn.cv() now implements a "custom-folds" method that allows to manually
8+
specify which observation belongs to each fold, and folds are not
9+
constrained to have the same size.
10+
* fixed checks in the C code involving R objects' classes; they failed
11+
when additional, optional classes were present (thanks Claudia Vitolo).
12+
* fixed cpdag() handling of illegal arcs that are part of shielded
13+
colliders (thanks Vladimir Manewitsch).
14+
* removed misleading warning about conflicting v-structures from cpdag().
15+
* rsmax2() and mmhc() now return whitelists and blacklists as they are
16+
at the beginning restrict phase (thanks Vladimir Manewitsch).
17+
* bn.fit() can now fit local distributions in parallel, and has been mostly
18+
reimplemented in C for speed (thanks Claudia Vitolo).
19+
* added an impute() function to impute missing values from a bn.fit object.
20+
* fixed loss functions for data in which observations have to be dropped
21+
for various nodes (thanks Manuel Gomez Olmedo).
22+
* added an all.equal() method to compare bn.fit objects.
23+
* added a "by.node" argument to score() for decomposable scores (thanks
24+
Behjati Shahab).
25+
* added warning about partially direct graphs in choose.direction() and
26+
improved its debugging output (thanks Wei Kong).
27+
* added spouses(), ancestors() and descendats().
28+
* fixed a segfault in predict(..., method = "lw") with discrete BNS and
29+
sparse CPTs that included NaNs.
30+
131
bnlearn (4.0)
232

333
* fixed memory usage in aracne(), chow.liu() and tree.bayes() (thanks

DESCRIPTION

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Package: bnlearn
22
Type: Package
33
Title: Bayesian Network Structure Learning, Parameter Learning and
44
Inference
5-
Version: 4.0
6-
Date: 2016-05-12
5+
Version: 4.1
6+
Date: 2017-02-09
77
Depends: R (>= 2.14.0), methods
88
Suggests: parallel, graph, Rgraphviz, lattice, gRain
99
Author: Marco Scutari
@@ -22,11 +22,11 @@ Description: Bayesian network structure learning, parameter learning and
2222
included, as well as support for parameter estimation (maximum likelihood
2323
and Bayesian) and inference, conditional probability queries and
2424
cross-validation. Development snapshots with the latest bugfixes are
25-
available from www.bnlearn.com.
25+
available from <http://www.bnlearn.com>.
2626
URL: http://www.bnlearn.com/
2727
License: GPL (>= 2)
2828
LazyData: yes
2929
NeedsCompilation: yes
30-
Packaged: 2016-05-15 21:32:16 UTC; fizban
30+
Packaged: 2017-02-09 16:21:05 UTC; fizban
3131
Repository: CRAN
32-
Date/Publication: 2016-05-16 14:47:13
32+
Date/Publication: 2017-02-09 18:20:13

MD5

+123-117
Large diffs are not rendered by default.

NAMESPACE

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export(
3434
"parents<-",
3535
"children",
3636
"children<-",
37+
"spouses",
38+
"ancestors",
39+
"descendants",
3740
"root.nodes",
3841
"leaf.nodes",
3942
"nnodes",
@@ -101,6 +104,7 @@ export(
101104
"dsep",
102105
"discretize",
103106
"dedup",
107+
"impute",
104108
"configs",
105109
"relevant",
106110
"read.bif",
@@ -128,6 +132,7 @@ importFrom("graphics", "abline", "arrows", "lines", "plot", "points",
128132
S3method(as.bn, fit)
129133

130134
S3method(all.equal, bn)
135+
S3method(all.equal, bn.fit)
131136
S3method(print, bn)
132137
S3method(plot, bn)
133138
S3method(AIC, bn)

R/arc.strength.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ arc.strength.score = function(network, data, score, extra, debug = FALSE) {
8888
reference.score = per.node.score(network = network, score = score,
8989
targets = nodes, extra.args = extra, data = data)
9090
# check whether the score is decomposable.
91-
decomp = is.score.decomposable(score, nodes, extra)
91+
decomp = is.score.decomposable(score, extra)
9292

9393
if (debug) {
9494

R/backend-indep.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ vstruct.apply = function(arcs, vs, nodes, strict, debug = FALSE) {
274274
temp = set.arc.direction(v["y"], v["x"], arcs)
275275
temp = set.arc.direction(v["z"], v["x"], temp)
276276

277-
if(!is.acyclic(temp, nodes, directed = TRUE)) {
277+
if (!is.acyclic(temp, nodes, directed = TRUE)) {
278278

279279
if (debug) {
280280

R/choose.direction.R

+9-2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ choose.direction.test = function(x, arc, data, test, alpha, B, debug = FALSE) {
160160
# because if they, too, are parents of the node to be tested
161161
# they _do_ belong there; if they are not, the node distribution
162162
# does not depend on them so they are largely irrelevant.
163+
if (any(arc %in% undirected.arcs(x)))
164+
warning("the graph is not completely directed around ", arc[1], " and ",
165+
arc[2], ", treating nodes connected by undirected arcs as parents.")
166+
163167
choose.direction.test.pvalue = function(arc) {
164168

165169
if (!is.legal.arc(arc, test, data)) {
@@ -208,6 +212,9 @@ choose.direction.score = function(x, data, arc, score, extra.args, debug = FALSE
208212
# because if they, too, are parents of the node to be tested
209213
# they _do_ belong there; if they are not, the node distribution
210214
# does not depend on them so they are largely irrelevant.
215+
if (any(arc %in% undirected.arcs(x)))
216+
warning("the graph is not completely directed around ", arc[1], " and ",
217+
arc[2], ", treating nodes connected by undirected arcs as parents.")
211218

212219
x$nodes[[arc[1]]]$parents = parents.backend(x$arcs, arc[1], undirected = TRUE)
213220
x$nodes[[arc[2]]]$parents = parents.backend(x$arcs, arc[2], undirected = TRUE)
@@ -218,7 +225,7 @@ choose.direction.score = function(x, data, arc, score, extra.args, debug = FALSE
218225
reference.score = per.node.score(network = x, score = score,
219226
targets = arc, extra.args = extra.args, data = data)
220227
# check whether the score is decomposable.
221-
decomp = is.score.decomposable(score, names(x$nodes), extra.args)
228+
decomp = is.score.decomposable(score, extra.args)
222229

223230
# compare the scores of the two networks.
224231
choose.direction.score.delta = function(arc) {
@@ -230,7 +237,7 @@ choose.direction.score = function(x, data, arc, score, extra.args, debug = FALSE
230237

231238
if (debug) {
232239

233-
cat(" > initial score for node", arc[1], "is", reference.score[arc[1]], ".\n")
240+
cat(" > initial score for node", arc[2], "is", reference.score[arc[2]], ".\n")
234241
if (is.legal.arc(arc, score, data))
235242
cat(" > score delta for arc", arc[1], "->", arc[2], "is", better$delta, ".\n")
236243
else

R/custom.fit.R

+6-5
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ custom.fit.backend = function(x, dist, discrete, ordinal) {
4444
# sanity check the distribution by comparing it to the network structure.
4545
if (is(dist[[node]]$coef, "matrix")) {
4646

47-
check.cgnode.vs.spec(dist[[node]], old = fitted[[node]]$parents,
48-
node = node)
47+
dist[[node]] =
48+
check.cgnode.vs.spec(dist[[node]], old = fitted[[node]]$parents,
49+
node = node, discrete = discrete[fitted[[node]]$parents])
4950
# set the correct class for method dispatch.
5051
class(fitted[[node]]) = "bn.fit.cgnode"
5152

@@ -131,9 +132,6 @@ custom.fit.backend = function(x, dist, discrete, ordinal) {
131132
# identify discrete and continuous parents and configurations.
132133
parents = fitted[[node]]$parents
133134
configs = as.character(seq(from = 0, to = ncol(dist[[node]]$coef) - 1))
134-
# store the new coefficients and standard deviations.
135-
fitted[[node]]$coefficients = noattr(dist[[node]]$coef)
136-
fitted[[node]]$sd = structure(noattr(dist[[node]]$sd), names = configs)
137135
# identify discrete and continuous parents.
138136
dparents = as.integer(which(discrete[parents]))
139137
gparents = as.integer(which(!discrete[parents]))
@@ -143,6 +141,9 @@ custom.fit.backend = function(x, dist, discrete, ordinal) {
143141
dlevels = sapply(parents[dparents],
144142
function(x) dimnames(dist[[x]])[[1]], simplify = FALSE)
145143
fitted[[node]]$dlevels = dlevels
144+
# store the new coefficients and standard deviations.
145+
fitted[[node]]$coefficients = noattr(dist[[node]]$coef)
146+
fitted[[node]]$sd = structure(noattr(dist[[node]]$sd), names = configs)
146147
# reset columns names for the coefficients and names for sd.
147148
colnames(fitted[[node]]$coefficients) =
148149
names(fitted[[node]]$sd) = configs

R/cv.R

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
crossvalidation = function(data, bn, loss = NULL, k = 10,
3-
m = ceiling(nrow(data)/10), algorithm.args, loss.args, fit, fit.args,
4-
method, cluster = NULL, debug = FALSE) {
3+
m = ceiling(nrow(data)/10), folds, algorithm.args, loss.args, fit,
4+
fit.args, method, cluster = NULL, debug = FALSE) {
55

66
n = nrow(data)
77

@@ -27,6 +27,14 @@ crossvalidation = function(data, bn, loss = NULL, k = 10,
2727
# all test sets have the same length, a dummy works just fine.
2828
kcv.length = rep(m, k)
2929

30+
}#THEN
31+
else if (method == "custom-folds") {
32+
33+
# the folds are the custom folds specified by the user.
34+
kcv = folds
35+
# store the length of each test set.
36+
kcv.length = sapply(kcv, length)
37+
3038
}#THEN
3139

3240
if (is.character(bn)) {

R/fast-iamb.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fast.incremental.association = function(x, cluster = NULL, whitelist,
4747
nodes = names(x)
4848

4949
# 1. [Compute Markov Blankets]
50-
mb = smartLapply(cluster, as.list(nodes), fast.ia.markov.blanket,
50+
mb = smartSapply(cluster, as.list(nodes), fast.ia.markov.blanket,
5151
data = x, nodes = nodes, alpha = alpha, B = B, whitelist = whitelist,
5252
blacklist = blacklist, test = test, debug = debug)
5353
names(mb) = nodes
@@ -56,7 +56,7 @@ fast.incremental.association = function(x, cluster = NULL, whitelist,
5656
mb = bn.recovery(mb, nodes = nodes, strict = strict, mb = TRUE, debug = debug)
5757

5858
# 2. [Compute Graph Structure]
59-
mb = smartLapply(cluster, as.list(nodes), neighbour, mb = mb, data = x,
59+
mb = smartSapply(cluster, as.list(nodes), neighbour, mb = mb, data = x,
6060
alpha = alpha, B = B, whitelist = whitelist, blacklist = blacklist,
6161
test = test, debug = debug)
6262
names(mb) = nodes

R/fast.lm.R

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
fast.lm = function(data, node, parents, keep.fitted = FALSE) {
2+
3+
y = minimal.data.frame.column(data, node)
4+
5+
.Call("fast_lm",
6+
data = data,
7+
node = node,
8+
parents = parents,
9+
keep = keep.fitted)
10+
11+
}#FAST.LM
12+
13+
fast.cglm = function(data, node, parents, configs, keep.fitted = FALSE) {
14+
15+
.Call("fast_cglm",
16+
data = data,
17+
node = node,
18+
parents = parents,
19+
configs = configs,
20+
keep = keep.fitted)
21+
22+
}#FAST.CGLM

0 commit comments

Comments
 (0)