Skip to contents

Converts a Knowledge object to a list of two data frames, namely whitelist and blacklist, which can be used as arguments for bnlearn algorithms. The whitelist contains all required edges, and the blacklist contains all forbidden edges. Tiers will be made into forbidden edges before running the conversion.

Usage

as_bnlearn_knowledge(kn)

Arguments

kn

A knowledge object. Must have no tier information.

Value

A list with two elements, whitelist and blacklist, each a data frame containing the edges in a from, to format.

Examples

# produce whitelist/blacklist data frame for bnlearn
data(tpc_example)

kn <- knowledge(
  tpc_example,
  tier(
    child ~ starts_with("child"),
    youth ~ starts_with("youth"),
    oldage ~ starts_with("old")
  ),
  child_x1 %-->% youth_x3
)

bnlearn_kn <- as_bnlearn_knowledge(kn)
print(bnlearn_kn)
#> $whitelist
#>       from       to
#> 1 child_x1 youth_x3
#> 
#> $blacklist
#>         from       to
#> 1  oldage_x5 child_x1
#> 2  oldage_x5 child_x2
#> 3  oldage_x5 youth_x3
#> 4  oldage_x5 youth_x4
#> 5  oldage_x6 child_x1
#> 6  oldage_x6 child_x2
#> 7  oldage_x6 youth_x3
#> 8  oldage_x6 youth_x4
#> 9   youth_x3 child_x1
#> 10  youth_x3 child_x2
#> 11  youth_x4 child_x1
#> 12  youth_x4 child_x2
#>