← Documentation
ADS-IDAC Engine 5.0.0
bncore::Factor Class Reference

A potential over an ordered scope of variables. More...

#include <factor.hpp>

Collaboration diagram for bncore::Factor:
[legend]

Public Member Functions

 Factor (const std::vector< NodeId > &scope, const std::vector< std::size_t > &state_sizes)
 Creates a factor that owns zero-initialized storage. More...
 
 Factor (const std::vector< NodeId > &scope, const std::vector< std::size_t > &state_sizes, double *preallocated_ptr)
 Creates a factor over caller memory. The buffer is not initialized. More...
 
const std::vector< NodeId > & scope () const
 Variables of the factor, in tensor dimension order. More...
 
Factor multiply (const Factor &other, class BumpAllocator *allocator=nullptr) const
 Product of two factors. More...
 
Factor marginalize (const std::vector< NodeId > &marg_vars, class BumpAllocator *allocator=nullptr) const
 Sums variables out of the factor. More...
 
DenseTensor & tensor ()
 The value table. More...
 
const DenseTensor & tensor () const
 The value table, read only. More...
 
void bind_data (double *ptr)
 Redirects the value table to a caller buffer. See DenseTensor::bind_data(). More...
 

Private Attributes

std::vector< NodeId > scope_
 
DenseTensor tensor_
 

Detailed Description

A potential over an ordered scope of variables.

Dimension i of the tensor belongs to scope()[i] and has one entry per state of that variable. If the tensor has one more dimension than the scope, the last dimension is the batch dimension. It varies fastest, so the value for state configuration c and batch row b is at c * B + b.

Definition at line 22 of file factor.hpp.

Constructor & Destructor Documentation

◆ Factor() [1/2]

bncore::Factor::Factor ( const std::vector< NodeId > &  scope,
const std::vector< std::size_t > &  state_sizes 
)

Creates a factor that owns zero-initialized storage.

Parameters
scopeVariables of the factor, in dimension order.
state_sizesState count of each scope variable, optionally followed by the batch size.
Exceptions
std::invalid_argumentif state_sizes is empty, or its length is neither scope.size() nor scope.size() + 1.

Definition at line 6 of file factor.cpp.

References scope().

Referenced by marginalize(), and multiply().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Factor() [2/2]

bncore::Factor::Factor ( const std::vector< NodeId > &  scope,
const std::vector< std::size_t > &  state_sizes,
double *  preallocated_ptr 
)

Creates a factor over caller memory. The buffer is not initialized.

Parameters
scopeVariables of the factor, in dimension order.
state_sizesState count of each scope variable, optionally followed by the batch size.
preallocated_ptrBuffer holding at least the product of state_sizes doubles. It must outlive the factor's use.
Exceptions
std::invalid_argumentif state_sizes is empty or has the wrong length, or the pointer is null.

Definition at line 15 of file factor.cpp.

References scope().

Here is the call graph for this function:

Member Function Documentation

◆ bind_data()

void bncore::Factor::bind_data ( double *  ptr)

Redirects the value table to a caller buffer. See DenseTensor::bind_data().

Parameters
ptrBuffer holding at least tensor().size() doubles.

Definition at line 25 of file factor.cpp.

References bncore::DenseTensor::bind_data(), and tensor_.

Here is the call graph for this function:

◆ marginalize()

Factor bncore::Factor::marginalize ( const std::vector< NodeId > &  marg_vars,
class BumpAllocator *  allocator = nullptr 
) const

Sums variables out of the factor.

The result keeps the remaining scope variables in their order and keeps the batch dimension if there is one.

Parameters
marg_varsVariables to sum out. Entries that are not in the scope are ignored.
allocatorIf non-null, the result's storage comes from this allocator and is valid until its reset(). If null, the result owns its storage.
Returns
The marginal factor.
Exceptions
std::bad_allocif allocator has too little space left.

Definition at line 151 of file factor.cpp.

References bncore::BumpAllocator::allocate(), bncore::DenseTensor::data(), Factor(), bncore::DenseTensor::fill(), scope_, bncore::DenseTensor::shape(), bncore::DenseTensor::size(), tensor(), and tensor_.

Here is the call graph for this function:

◆ multiply()

Factor bncore::Factor::multiply ( const Factor &  other,
class BumpAllocator *  allocator = nullptr 
) const

Product of two factors.

The result scope is this factor's scope followed by the variables of other that are not in it, in the order other lists them. The result is batched if either operand is. An unbatched operand is used for every batch row. The batch size is taken from this factor if it is batched, otherwise from other; two batched operands must have the same batch size, which is not checked.

Each call builds index maps over the result's state space, so the cost is proportional to the result size and the call allocates temporaries.

Parameters
otherRight operand. Shared variables must have the same state count in both factors.
allocatorIf non-null, the result's storage comes from this allocator and is valid until its reset(). If null, the result owns its storage.
Returns
The product factor.
Exceptions
std::bad_allocif allocator has too little space left.

Definition at line 27 of file factor.cpp.

References bncore::BumpAllocator::allocate(), bncore::DenseTensor::data(), Factor(), scope_, bncore::DenseTensor::shape(), tensor(), and tensor_.

Referenced by bncore::BatchWorkspace::rebuild_clique_potentials().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scope()

const std::vector< NodeId > & bncore::Factor::scope ( ) const
inline

Variables of the factor, in tensor dimension order.

Definition at line 45 of file factor.hpp.

References scope_.

Referenced by bncore::BatchWorkspace::apply_soft_evidence_to_clique(), Factor(), and bncore::BatchWorkspace::rebuild_clique_potentials().

Here is the caller graph for this function:

◆ tensor() [1/2]

DenseTensor & bncore::Factor::tensor ( )
inline

The value table.

Definition at line 83 of file factor.hpp.

References tensor_.

Referenced by bncore::BatchWorkspace::apply_soft_evidence_to_clique(), marginalize(), multiply(), bncore::BatchWorkspace::rebuild_clique_potentials(), and bncore::BatchWorkspace::snapshot_base_potentials().

Here is the caller graph for this function:

◆ tensor() [2/2]

const DenseTensor & bncore::Factor::tensor ( ) const
inline

The value table, read only.

Definition at line 85 of file factor.hpp.

References tensor_.

Member Data Documentation

◆ scope_

std::vector<NodeId> bncore::Factor::scope_
private

Definition at line 95 of file factor.hpp.

Referenced by marginalize(), multiply(), and scope().

◆ tensor_

DenseTensor bncore::Factor::tensor_
private

Definition at line 96 of file factor.hpp.

Referenced by bind_data(), marginalize(), multiply(), and tensor().


The documentation for this class was generated from the following files: