Samples a DAG in accordance with it's posterior probability conditional on it being consistent with a partition.
Value
A cia_chain(s) object or adjacency matrix. For a cia_chain(s) object each state will be an adjacency matrix.
Examples
data <- bnlearn::learning.test
dag <- UniformlySampleDAG(colnames(data))
partition <- DAGtoPartition(dag)
scorer <- CreateScorer(
scorer = BNLearnScorer,
data = data
)
# Used to sample from a single partition.
PartitiontoDAG(partition, scorer)
#> $state
#> A B C D E F
#> A 0 0 1 0 0 0
#> B 1 0 0 0 1 1
#> C 0 0 0 0 0 0
#> D 1 1 1 0 0 0
#> E 0 0 0 0 0 1
#> F 1 0 0 0 0 0
#>
#> $log_score
#> [1] -24139.22
#>
# Used to convert a chain of partitions to DAGs.
init_state <- InitPartition(colnames(data), scorer)
results <- SampleChains(3, init_state, PartitionMCMC(), scorer)
PartitiontoDAG(results, scorer)
#> [[1]]
#> $state
#> $state[[1]]
#> A B C D E F
#> A 0 1 0 1 1 0
#> B 0 0 0 0 0 0
#> C 1 0 0 1 0 1
#> D 0 0 0 0 0 0
#> E 0 0 0 0 0 0
#> F 0 0 0 0 1 0
#>
#> $state[[2]]
#> A B C D E F
#> A 0 1 0 1 1 0
#> B 0 0 0 0 0 0
#> C 1 0 0 1 0 1
#> D 0 0 0 0 0 0
#> E 0 1 0 0 0 0
#> F 0 1 0 0 1 0
#>
#> $state[[3]]
#> A B C D E F
#> A 0 1 0 1 1 0
#> B 0 0 0 0 0 0
#> C 1 0 0 1 0 1
#> D 0 0 0 0 0 0
#> E 0 1 0 0 0 0
#> F 0 1 0 0 1 0
#>
#>
#> $log_score
#> [1] -24521.02 -24147.27 -24147.27
#>
#> attr(,"class")
#> [1] "cia_chain"
#>
#> [[2]]
#> $state
#> $state[[1]]
#> A B C D E F
#> A 0 0 0 0 0 0
#> B 1 0 1 0 1 0
#> C 1 0 0 0 1 0
#> D 1 1 1 0 0 1
#> E 1 0 0 0 0 0
#> F 0 0 0 0 1 0
#>
#> $state[[2]]
#> A B C D E F
#> A 0 0 0 0 0 0
#> B 1 0 1 0 1 0
#> C 1 0 0 0 1 0
#> D 1 1 1 0 0 1
#> E 1 0 0 0 0 0
#> F 0 0 0 0 1 0
#>
#> $state[[3]]
#> A B C D E F
#> A 0 0 0 0 0 0
#> B 1 0 1 0 1 0
#> C 1 0 0 0 0 0
#> D 1 1 1 0 0 1
#> E 0 0 0 0 0 0
#> F 0 0 0 0 1 0
#>
#>
#> $log_score
#> [1] -24709.1 -24709.1 -24214.7
#>
#> attr(,"class")
#> [1] "cia_chain"
#>
#> attr(,"class")
#> [1] "cia_chains"