add scale() method in DiscreteFactor
parent
d57994d279
commit
c8bafab430
|
@ -71,4 +71,12 @@ AlgebraicDecisionTree<Key> DiscreteFactor::errorTree() const {
|
||||||
return AlgebraicDecisionTree<Key>(dkeys, errors);
|
return AlgebraicDecisionTree<Key>(dkeys, errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ************************************************************************ */
|
||||||
|
DiscreteFactor::shared_ptr DiscreteFactor::scale() const {
|
||||||
|
// Max over all the potentials by pretending all keys are frontal:
|
||||||
|
shared_ptr denominator = this->max(this->size());
|
||||||
|
// Normalize the product factor to prevent underflow.
|
||||||
|
return this->operator/(denominator);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace gtsam
|
} // namespace gtsam
|
||||||
|
|
|
@ -158,6 +158,14 @@ class GTSAM_EXPORT DiscreteFactor : public Factor {
|
||||||
/// Create new factor by maximizing over all values with the same separator.
|
/// Create new factor by maximizing over all values with the same separator.
|
||||||
virtual DiscreteFactor::shared_ptr max(const Ordering& keys) const = 0;
|
virtual DiscreteFactor::shared_ptr max(const Ordering& keys) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Scale the factor values by the maximum
|
||||||
|
* to prevent underflow/overflow.
|
||||||
|
*
|
||||||
|
* @return DiscreteFactor::shared_ptr
|
||||||
|
*/
|
||||||
|
DiscreteFactor::shared_ptr scale() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of non-zero values contained in this factor.
|
* Get the number of non-zero values contained in this factor.
|
||||||
* It could be much smaller than `prod_{key}(cardinality(key))`.
|
* It could be much smaller than `prod_{key}(cardinality(key))`.
|
||||||
|
|
Loading…
Reference in New Issue