Skip to contents

Get the maximum a posteriori state

Usage

GetMAP(x)

Arguments

x

A collection of unique objects or chains object.

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

scorer <- CreateScorer(
  scorer = BNLearnScorer, 
  data = data
  )
init_state <- InitPartition(colnames(data), scorer)

results <- SampleChains(10, init_state, 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    B
#> 3         3    C
#> 4         4    D
#> 5         5    F
#> 6         6    E
#> 
#> 
#> [[1]]$log_p
#> [1] 1
#> 
#> [[1]]$log_state_score
#> [1] -24028.65
#> 
#> [[1]]$log_norm_state_score
#> [1] 0
#> 
#> 
#> [[2]]
#> [[2]]$state
#> [[2]]$state[[1]]
#>   partition node
#> 1         1    A
#> 2         2    B
#> 3         3    C
#> 4         3    E
#> 5         4    F
#> 6         5    D
#> 
#> [[2]]$state[[2]]
#>   partition node
#> 1         1    C
#> 2         2    B
#> 3         3    A
#> 4         3    E
#> 5         4    F
#> 6         5    D
#> 
#> 
#> [[2]]$log_p
#> [1] 0.5
#> 
#> [[2]]$log_state_score
#> [1] -24096.56 -24096.56
#> 
#> [[2]]$log_norm_state_score
#> [1] -0.6931472 -0.6931472
#> 
#> 

# Get MAP across all chains.
results |>
  FlattenChains() |>
  GetMAP()
#> $state
#> $state[[1]]
#>   partition node
#> 1         1    A
#> 2         2    B
#> 3         3    C
#> 4         4    D
#> 5         5    F
#> 6         6    E
#> 
#> 
#> $log_p
#> [1] 1
#> 
#> $log_state_score
#> [1] -24028.65
#> 
#> $log_norm_state_score
#> [1] 0
#>