Get the maximum a posteriori state
Value
A list with the adjacency matrix for the map and it's posterior probability. It is possible for it to return multiple DAGs. The list has elements;
state: List of MAP DAGs.
log_p: Numeric vector with the log posterior probability for each state.
log_state_score: Numeric vector representing the log score for each state.
log_norm_state_score: Numeric vector representing the log of the normalised score for each state.
Examples
data <- bnlearn::learning.test
dag <- UniformlySampleDAG(colnames(data))
partitioned_nodes <- DAGtoPartition(dag)
scorer <- CreateScorer(
scorer = BNLearnScorer,
data = data
)
results <- SampleChains(10, partitioned_nodes, PartitionMCMC(), scorer)
# Get the MAP per chain. Can be helpful to compare chains.
GetMAP(results)
#> [[1]]
#> [[1]]$state
#> [[1]]$state[[1]]
#> partition node
#> 1 1 A
#> 2 2 C
#> 3 2 E
#> 4 3 D
#> 5 3 F
#> 6 4 B
#>
#>
#> [[1]]$log_p
#> [1] 1
#>
#> [[1]]$log_state_score
#> [1] -24147.61
#>
#> [[1]]$log_norm_state_score
#> [1] 0
#>
#>
#> [[2]]
#> [[2]]$state
#> [[2]]$state[[1]]
#> partition node
#> 1 1 A
#> 2 1 F
#> 3 2 B
#> 4 3 C
#> 5 4 D
#> 6 5 E
#>
#>
#> [[2]]$log_p
#> [1] 0.9987463
#>
#> [[2]]$log_state_score
#> [1] -24111.97
#>
#> [[2]]$log_norm_state_score
#> [1] -0.001254526
#>
#>
# Get MAP across all chains.
results |>
FlattenChains() |>
GetMAP()
#> $state
#> $state[[1]]
#> partition node
#> 1 1 A
#> 2 1 F
#> 3 2 B
#> 4 3 C
#> 5 4 D
#> 6 5 E
#>
#>
#> $log_p
#> [1] 0.9987463
#>
#> $log_state_score
#> [1] -24111.97
#>
#> $log_norm_state_score
#> [1] -0.001254526
#>