Skip to contents

Samples a DAG in accordance with it's posterior probability conditional on it being consistent with a partition.

Usage

PartitiontoDAG(partitions, scorer)

Arguments

partitions

A cia_chain(s) object or data.frame representing the partition.

scorer

A scorer object.

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 1 0 1 0 0
#> B 0 0 1 0 1 1
#> C 0 0 0 1 1 0
#> D 0 0 0 0 0 0
#> E 0 0 0 0 0 1
#> F 0 0 0 0 0 0
#> 
#> $log_score
#> [1] -24071.05
#> 

# Used to convert a chain of partitions to DAGs.
results <- SampleChains(3, partition, PartitionMCMC(), scorer)
PartitiontoDAG(results, scorer)
#> [[1]]
#> $state
#> $state[[1]]
#>   A B C D E F
#> A 0 1 1 1 0 0
#> B 0 0 0 0 1 1
#> C 0 0 0 1 0 0
#> D 0 0 0 0 0 0
#> E 0 0 0 0 0 1
#> F 0 0 0 0 0 0
#> 
#> $state[[2]]
#>   A B C D E F
#> A 0 1 1 1 0 0
#> B 0 0 0 0 1 1
#> C 0 0 0 1 0 0
#> D 0 0 0 0 0 0
#> E 0 0 0 0 0 1
#> F 0 0 0 0 0 0
#> 
#> $state[[3]]
#>   A B C D E F
#> A 0 1 1 1 0 0
#> B 0 0 0 0 1 1
#> C 0 0 0 1 0 0
#> D 0 0 0 0 0 0
#> E 0 0 0 0 0 1
#> F 0 0 0 0 0 0
#> 
#> 
#> $log_score
#> [1] -24029.79 -24029.79 -24029.79
#> 
#> attr(,"class")
#> [1] "cia_chain"
#> 
#> [[2]]
#> $state
#> $state[[1]]
#>   A B C D E F
#> A 0 1 0 1 0 0
#> B 0 0 1 0 1 1
#> C 0 0 0 1 1 0
#> D 0 0 0 0 0 0
#> E 0 0 0 0 0 1
#> F 0 0 0 0 0 0
#> 
#> $state[[2]]
#>   A B C D E F
#> A 0 1 0 1 0 0
#> B 0 0 1 0 1 1
#> C 0 0 0 1 1 0
#> D 0 0 0 0 0 0
#> E 0 0 0 0 0 1
#> F 0 0 0 0 0 0
#> 
#> $state[[3]]
#>   A B C D E F
#> A 0 1 0 1 0 0
#> B 0 0 1 0 1 1
#> C 0 0 0 1 1 0
#> D 0 0 0 0 0 0
#> E 0 0 0 0 0 1
#> F 0 0 0 0 0 0
#> 
#> 
#> $log_score
#> [1] -24071.05 -24071.05 -24071.05
#> 
#> attr(,"class")
#> [1] "cia_chain"
#> 
#> attr(,"class")
#> [1] "cia_chains"