add evaluate and getter

release/4.3a0
Varun Agrawal 2024-12-31 00:16:44 -05:00
parent b39b20084a
commit d9faa820de
3 changed files with 34 additions and 0 deletions

View File

@ -488,6 +488,20 @@ void DiscreteConditional::setData(const DiscreteConditional::shared_ptr& dc) {
this->root_ = dc->root_; this->root_ = dc->root_;
} }
/* ************************************************************************* */
DiscreteConditional::shared_ptr DiscreteConditional::max(
const Ordering& keys) const {
auto m = *BaseFactor::max(keys);
return std::make_shared<DiscreteConditional>(m.discreteKeys().size(), m);
}
/* ************************************************************************* */
DiscreteConditional::shared_ptr DiscreteConditional::prune(
size_t maxNrAssignments) const {
return std::make_shared<DiscreteConditional>(
this->nrFrontals(), BaseFactor::prune(maxNrAssignments));
}
/* ************************************************************************* */ /* ************************************************************************* */
double DiscreteConditional::negLogConstant() const { return 0.0; } double DiscreteConditional::negLogConstant() const { return 0.0; }

View File

@ -214,6 +214,15 @@ class GTSAM_EXPORT DiscreteConditional
*/ */
size_t argmax(const DiscreteValues& parentsValues = DiscreteValues()) const; size_t argmax(const DiscreteValues& parentsValues = DiscreteValues()) const;
/**
* @brief Create new conditional by maximizing over all
* values with the same separator.
*
* @param keys The keys to sum over.
* @return DiscreteConditional::shared_ptr
*/
virtual DiscreteConditional::shared_ptr max(const Ordering& keys) const;
/// @} /// @}
/// @name Advanced Interface /// @name Advanced Interface
/// @{ /// @{
@ -273,6 +282,9 @@ class GTSAM_EXPORT DiscreteConditional
/// Set the data from another DiscreteConditional. /// Set the data from another DiscreteConditional.
virtual void setData(const DiscreteConditional::shared_ptr& dc); virtual void setData(const DiscreteConditional::shared_ptr& dc);
/// Prune the conditional
virtual DiscreteConditional::shared_ptr prune(size_t maxNrAssignments) const;
/// @} /// @}
protected: protected:

View File

@ -205,6 +205,14 @@ class GTSAM_EXPORT DiscreteTableConditional : public DiscreteConditional {
return -error(x); return -error(x);
} }
/// Return the underlying TableFactor
TableFactor table() const { return table_; }
/// Evaluate the conditional given the values.
virtual double evaluate(const Assignment<Key>& values) const override {
return table_.evaluate(values);
}
/// @} /// @}
private: private: