13#include <unordered_map>
143 void reset(std::size_t new_batch_size, std::size_t cpt_batch_offset = 0);
189 std::size_t n_states);
204 std::size_t n_states);
259 void query_map(
int *out_states, std::size_t n_vars)
const;
289 const std::size_t *offsets,
Message passing state for one junction tree and one batch size.
std::vector< std::size_t > down_msg_size_
std::unordered_map< NodeId, std::vector< double > > soft_evidence_matrix_
void build_message_schedule()
Fills collect_ops_, distribute_ops_, assemble_ops_ and clique_marg_info_.
std::vector< std::size_t > collect_order_
std::vector< std::size_t > sepset_size_
std::vector< std::vector< uint32_t > > map_traceback_
std::vector< std::size_t > cal_pot_size_
std::vector< uint8_t > cal_changed_
std::unordered_map< NodeId, std::vector< double > > soft_evidence_scalar_
const int * evidence_matrix_
void clear_soft_evidence()
Removes all soft evidence, scalar and matrix.
std::vector< std::vector< double > > map_cal_pot_buf_
void set_soft_evidence_matrix(NodeId var, const double *likelihoods_matrix, std::size_t n_states)
Sets a separate likelihood vector per batch row for a variable.
DenseTensor query_marginal(NodeId node) const
Marginal of one variable from the last calibrate().
void calibrate()
Runs sum-product message passing with the current evidence.
std::unordered_map< NodeId, std::size_t > node_to_clique_
std::vector< std::vector< double > > base_up_buf_
std::vector< std::vector< double > > ev_scratch_
std::vector< uint8_t > query_visited_scratch_
std::vector< Factor > clique_potentials_
bool apply_soft_evidence_to_clique(std::size_t ci)
void clear_evidence()
Forgets the hard evidence matrix. Soft evidence is not affected.
std::vector< std::vector< double > > map_up_msg_buf_
std::vector< std::vector< double > > up_msg_buf_
std::size_t base_batch_size_
std::vector< bool > ev_scratch_active_
std::vector< std::vector< double > > base_cal_buf_
std::vector< std::vector< double > > cal_pot_buf_
std::vector< CollectOp > collect_ops_
std::unordered_map< NodeId, std::vector< std::size_t > > node_in_cliques_
BatchWorkspace(const JunctionTree &jt, std::size_t batch_size=1)
Builds the workspace and calibrates it without evidence.
std::vector< std::vector< double > > base_down_buf_
void resize_runtime_buffers(std::size_t target_batch_size)
Sizes message, belief and scratch buffers for a batch size.
std::vector< std::size_t > distribute_order_
void build_node_to_clique_map()
std::size_t evidence_num_vars_
std::vector< AssembleOp > assemble_ops_
std::vector< std::vector< std::size_t > > children_of_
void max_calibrate()
Runs max-product propagation with the current evidence, for query_map().
void set_soft_evidence(NodeId var, const double *likelihoods, std::size_t n_states)
Sets one likelihood vector for a variable, shared by all batch rows.
std::vector< std::size_t > clique_states_
bool base_depends_on_offset_
std::vector< DistributeOp > distribute_ops_
bool is_first_calibration_
void snapshot_base_potentials()
Copies clique_potentials_ into owning base_clique_potentials_.
std::vector< uint8_t > up_changed_
std::size_t base_batch_offset_
void set_evidence_matrix(const int *evidence_matrix, std::size_t num_vars)
Sets the hard evidence for the next calibration.
std::vector< double > scratch_buf_
void query_marginals_multi(const NodeId *query_vars, std::size_t num_queries, const std::size_t *offsets, double *out) const
Marginals of several variables from the last calibrate(), with one scan of each clique involved.
std::vector< std::vector< double > > down_msg_buf_
std::vector< CliqueMargInfo > clique_marg_info_
std::size_t max_product_states_
std::vector< std::size_t > up_msg_size_
std::vector< std::size_t > parent_of_
std::vector< uint8_t > ev_clique_
void reset(std::size_t new_batch_size, std::size_t cpt_batch_offset=0)
Prepares the workspace for a new evidence case.
std::size_t cpt_batch_offset_
std::vector< Factor > base_clique_potentials_
std::vector< uint8_t > down_changed_
void rebuild_clique_potentials(std::size_t target_batch_size)
void query_map(int *out_states, std::size_t n_vars) const
Decodes a state for each variable from the max-product beliefs.
Dense row-major array of doubles with a fixed shape.
Cliques and separators compiled from one Graph.
bncore::Factor, a table of doubles over a list of variables, with the product and sum-out operations ...
Junction tree data structure of BNCore: Clique, Separator and the JunctionTree container.
std::uint32_t NodeId
Handle of a variable within one Graph.
Index tables that assemble the calibrated belief of one clique from its potential,...
std::vector< uint32_t > down_map
[clique_idx] to index in the clique's down message; empty unless has_down
std::size_t product_states
number of states of the clique
std::vector< std::vector< uint32_t > > child_maps
[child_i][clique_idx] to index in that child's up message
std::vector< std::size_t > child_cliques
clique indices of the children, parallel to child_maps
bool has_down
true when the clique has a parent
Per-clique lookup from a flat clique index to the state of each scope variable.
std::vector< std::vector< uint8_t > > state_of_dim
std::size_t n_states_total
number of joint states of the clique
Index tables for the upward (collect) message of one non-root clique u to its parent.
std::vector< std::vector< uint32_t > > child_maps
[child_i][prod_idx] to index in that child's up message
std::vector< uint32_t > pot_map
[prod_idx] to flat index in clique u's potential
std::size_t product_states
number of states of the product space
std::vector< uint32_t > marg_map
[prod_idx] to index in u's up message (its separator states)
std::vector< std::size_t > child_cliques
clique indices of the children, parallel to child_maps
Index tables for the downward (distribute) message from a parent clique p to one child clique u.
std::size_t product_states
number of states of the product space
std::vector< uint32_t > marg_map
[prod_idx] to index in u's down message
std::size_t parent_clique
clique index of p
bool has_parent_down
true when p has a parent of its own
std::vector< std::size_t > sibling_cliques
other children of p, parallel to sibling_maps
std::vector< uint32_t > down_map
[prod_idx] to index in p's down message; empty unless has_parent_down
std::vector< std::vector< uint32_t > > sibling_maps
[sibling_i][prod_idx] to index in that sibling's up message
std::vector< uint32_t > pot_map
[prod_idx] to flat index in parent clique p's potential