|
ADS-IDAC Engine 5.0.0
|
A potential over an ordered scope of variables. More...
#include <factor.hpp>
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_ |
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.
| bncore::Factor::Factor | ( | const std::vector< NodeId > & | scope, |
| const std::vector< std::size_t > & | state_sizes | ||
| ) |
Creates a factor that owns zero-initialized storage.
| scope | Variables of the factor, in dimension order. |
| state_sizes | State count of each scope variable, optionally followed by the batch size. |
| std::invalid_argument | if 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().
| 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.
| scope | Variables of the factor, in dimension order. |
| state_sizes | State count of each scope variable, optionally followed by the batch size. |
| preallocated_ptr | Buffer holding at least the product of state_sizes doubles. It must outlive the factor's use. |
| std::invalid_argument | if state_sizes is empty or has the wrong length, or the pointer is null. |
Definition at line 15 of file factor.cpp.
References scope().
| void bncore::Factor::bind_data | ( | double * | ptr | ) |
Redirects the value table to a caller buffer. See DenseTensor::bind_data().
Definition at line 25 of file factor.cpp.
References bncore::DenseTensor::bind_data(), and tensor_.
| 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.
| marg_vars | Variables to sum out. Entries that are not in the scope are ignored. |
| allocator | If non-null, the result's storage comes from this allocator and is valid until its reset(). If null, the result owns its storage. |
| std::bad_alloc | if 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_.
| 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.
| other | Right operand. Shared variables must have the same state count in both factors. |
| allocator | If non-null, the result's storage comes from this allocator and is valid until its reset(). If null, the result owns its storage. |
| std::bad_alloc | if 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().
|
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().
|
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().
|
inline |
|
private |
Definition at line 95 of file factor.hpp.
Referenced by marginalize(), multiply(), and scope().
|
private |
Definition at line 96 of file factor.hpp.
Referenced by bind_data(), marginalize(), multiply(), and tensor().