Jean
Jean

Reputation: 1490

bnlearn setting and dropping arcs inplace

Looking at http://www.bnlearn.com/documentation/man/arcops.html, the way to drop arcs is to use the drop.arcs function.

It doesn't seem to be dropping it though

library(bnlearn)
data(learning.test)
res = gs(learning.test)

arcs(res)
     from to 
[1,] "A"  "B"
[2,] "A"  "D"
[3,] "B"  "A"
[4,] "B"  "E"
[5,] "C"  "D"
[6,] "F"  "E"

drop.arc(res, "A", "B")
arcs(res)
     from to 
[1,] "A"  "B"
[2,] "A"  "D"
[3,] "B"  "A"
[4,] "B"  "E"
[5,] "C"  "D"
[6,] "F"  "E"

But in the debug logs it seems like it worked.

drop.arc(res, "A","B",debug=T)
* dropping any arc between  A and B .
  > dropping any arc between A and B .
* (re)building cached information about node A.
* node A.
  > found child D.
  > found node C in markov blanket.
  > node A has 0 parent(s), 1 child(ren), 1 neighbour(s) and 2 nodes in the markov blanket.
...

Is this a problem with R3.4.3 ? How to use arc operations while checking for cycles? I could always replace the res$arcs table, but I want to be able to check for cycles.

> version
               _                           
platform       x86_64-apple-darwin15.6.0   
arch           x86_64                      
os             darwin15.6.0                
system         x86_64, darwin15.6.0        
status                                     
major          3                           
minor          4.3                         
year           2017                        
month          11                          
day            30                          
svn rev        73796                       
language       R                           
version.string R version 3.4.3 (2017-11-30)
nickname       Kite-Eating Tree     
> packageVersion('bnlearn')
[1] '4.3'

Upvotes: 2

Views: 442

Answers (1)

Zelimir Kurtanjek
Zelimir Kurtanjek

Reputation: 11

The help page for ?drop.arcs says

"All functions return invisibly an updated copy of x."

You have to assign the the results of the function call to an object. So try

res2 = drop.arc(res, "A", "B") 
arcs(res2)

Upvotes: 0

Related Questions