← Documentation
ADS-IDAC Engine 5.0.0
junction_tree.hpp
Go to the documentation of this file.
1#pragma once
13#include <vector>
14
15namespace bncore {
16
18struct Clique {
19 std::size_t id;
22 std::vector<NodeId> scope;
26 std::vector<NodeId> assigned_cpts;
31 Factor base_potential; // Uncalibrated potential
32 std::vector<std::size_t> neighbor_cliques;
33};
34
36struct Separator {
37 std::size_t clique1;
38 std::size_t clique2;
39 std::vector<NodeId> scope;
40};
41
50public:
52 explicit JunctionTree(const Graph *graph);
53
59 void add_clique(const std::vector<NodeId> &scope,
60 const std::vector<std::size_t> &state_sizes);
66 void add_separator(std::size_t c1, std::size_t c2,
67 const std::vector<NodeId> &scope);
68
70 [[nodiscard]] const Graph *graph() const { return graph_; }
72 [[nodiscard]] const std::vector<Clique> &cliques() const { return cliques_; }
74 [[nodiscard]] const std::vector<Separator> &separators() const {
75 return separators_;
76 }
77
80 std::vector<Clique> &get_mutable_cliques() { return cliques_; }
81
82private:
83 const Graph *graph_;
84 std::vector<Clique> cliques_;
85 std::vector<Separator> separators_;
86};
87
88} // namespace bncore
A potential over an ordered scope of variables.
Definition: factor.hpp:22
Directed graphical model over discrete variables.
Definition: graph.hpp:28
Cliques and separators compiled from one Graph.
const Graph * graph_
not owned
const std::vector< Separator > & separators() const
All separators, in the order they were added.
JunctionTree(const Graph *graph)
void add_clique(const std::vector< NodeId > &scope, const std::vector< std::size_t > &state_sizes)
Appends a clique. Its id is the number of cliques before the call.
const std::vector< Clique > & cliques() const
All cliques, indexed by Clique::id.
void add_separator(std::size_t c1, std::size_t c2, const std::vector< NodeId > &scope)
Appends a separator and records each clique as a neighbor of the other.
std::vector< Clique > cliques_
const Graph * graph() const
The graph given at construction.
std::vector< Clique > & get_mutable_cliques()
Writable access to the cliques, used by the compiler to fill potentials and CPT assignments.
std::vector< Separator > separators_
bncore::Factor, a table of doubles over a list of variables, with the product and sum-out operations ...
bncore::Graph, the discrete Bayesian network model: variables, their states, directed edges and condi...
One clique of a junction tree.
std::size_t id
std::vector< std::size_t > neighbor_cliques
indices of adjacent cliques
std::vector< NodeId > assigned_cpts
std::vector< NodeId > scope
One edge of a junction tree, with the variables its cliques share.
std::size_t clique2
index of the other end
std::vector< NodeId > scope
variables common to both cliques
std::size_t clique1
index of one end