Skip to content

Commit

Permalink
make evaluate the overriden method
Browse files Browse the repository at this point in the history
  • Loading branch information
varunagrawal committed Dec 10, 2024
1 parent ab943b5 commit a98ac0f
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gtsam/discrete/DecisionTreeFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace gtsam {
// Construct unordered_map with values
std::vector<std::pair<DiscreteValues, double>> result;
for (const auto& assignment : assignments) {
result.emplace_back(assignment, operator()(assignment));
result.emplace_back(assignment, evaluate(assignment));
}
return result;
}
Expand Down
5 changes: 4 additions & 1 deletion gtsam/discrete/DecisionTreeFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ namespace gtsam {

/// Calculate probability for given values,
/// is just look up in AlgebraicDecisionTree.
double operator()(const Assignment<Key>& values) const override {
virtual double evaluate(const Assignment<Key>& values) const override {
return ADT::operator()(values);
}

/// Disambiguate to use DiscreteFactor version. Mainly for wrapper
using DiscreteFactor::operator();

/// Calculate error for DiscreteValues `x`, is -log(probability).
double error(const DiscreteValues& values) const override;

Expand Down
4 changes: 2 additions & 2 deletions gtsam/discrete/DiscreteConditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ class GTSAM_EXPORT DiscreteConditional
}

/// Evaluate, just look up in AlgebraicDecisionTree
double evaluate(const DiscreteValues& values) const {
virtual double evaluate(const Assignment<Key>& values) const override {
return ADT::operator()(values);
}

using DecisionTreeFactor::error; ///< DiscreteValues version
using DecisionTreeFactor::operator(); ///< DiscreteValues version
using DiscreteFactor::operator(); ///< DiscreteValues version

/**
* @brief restrict to given *parent* values.
Expand Down
8 changes: 4 additions & 4 deletions gtsam/discrete/DiscreteFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ class GTSAM_EXPORT DiscreteFactor : public Factor {
* @param values Discrete assignment.
* @return double
*/
double evaluate(const Assignment<Key>& values) const {
return operator()(values);
}
virtual double evaluate(const Assignment<Key>& values) const = 0;

/// Find value for given assignment of values to variables
virtual double operator()(const Assignment<Key>& values) const = 0;
double operator()(const DiscreteValues& values) const {
return evaluate(values);
}

/// Error is just -log(value)
virtual double error(const DiscreteValues& values) const;
Expand Down
2 changes: 1 addition & 1 deletion gtsam/discrete/TableFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bool TableFactor::equals(const DiscreteFactor& other, double tol) const {
}

/* ************************************************************************ */
double TableFactor::operator()(const Assignment<Key>& values) const {
double TableFactor::evaluate(const Assignment<Key>& values) const {
// a b c d => D * (C * (B * (a) + b) + c) + d
uint64_t idx = 0, card = 1;
for (auto it = sorted_dkeys_.rbegin(); it != sorted_dkeys_.rend(); ++it) {
Expand Down
2 changes: 1 addition & 1 deletion gtsam/discrete/TableFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class GTSAM_EXPORT TableFactor : public DiscreteFactor {
// /// @{

/// Evaluate probability distribution, is just look up in TableFactor.
double operator()(const Assignment<Key>& values) const override;
double evaluate(const Assignment<Key>& values) const override;

/// Calculate error for DiscreteValues `x`, is -log(probability).
double error(const DiscreteValues& values) const override;
Expand Down
2 changes: 1 addition & 1 deletion gtsam_unstable/discrete/AllDiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void AllDiff::print(const std::string& s, const KeyFormatter& formatter) const {
}

/* ************************************************************************* */
double AllDiff::operator()(const Assignment<Key>& values) const {
double AllDiff::evaluate(const Assignment<Key>& values) const {
std::set<size_t> taken; // record values taken by keys
for (Key dkey : keys_) {
size_t value = values.at(dkey); // get the value for that key
Expand Down
2 changes: 1 addition & 1 deletion gtsam_unstable/discrete/AllDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class GTSAM_UNSTABLE_EXPORT AllDiff : public Constraint {
}

/// Calculate value = expensive !
double operator()(const Assignment<Key>& values) const override;
double evaluate(const Assignment<Key>& values) const override;

/// Convert into a decisiontree, can be *very* expensive !
DecisionTreeFactor toDecisionTreeFactor() const override;
Expand Down
2 changes: 1 addition & 1 deletion gtsam_unstable/discrete/BinaryAllDiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BinaryAllDiff : public Constraint {
}

/// Calculate value
double operator()(const Assignment<Key>& values) const override {
double evaluate(const Assignment<Key>& values) const override {
return (double)(values.at(keys_[0]) != values.at(keys_[1]));
}

Expand Down
2 changes: 1 addition & 1 deletion gtsam_unstable/discrete/Domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ string Domain::base1Str() const {
}

/* ************************************************************************* */
double Domain::operator()(const Assignment<Key>& values) const {
double Domain::evaluate(const Assignment<Key>& values) const {
return contains(values.at(key()));
}

Expand Down
2 changes: 1 addition & 1 deletion gtsam_unstable/discrete/Domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class GTSAM_UNSTABLE_EXPORT Domain : public Constraint {
bool contains(size_t value) const { return values_.count(value) > 0; }

/// Calculate value
double operator()(const Assignment<Key>& values) const override;
double evaluate(const Assignment<Key>& values) const override;

/// Convert into a decisiontree
DecisionTreeFactor toDecisionTreeFactor() const override;
Expand Down
2 changes: 1 addition & 1 deletion gtsam_unstable/discrete/SingleValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void SingleValue::print(const string& s, const KeyFormatter& formatter) const {
}

/* ************************************************************************* */
double SingleValue::operator()(const Assignment<Key>& values) const {
double SingleValue::evaluate(const Assignment<Key>& values) const {
return (double)(values.at(keys_[0]) == value_);
}

Expand Down
2 changes: 1 addition & 1 deletion gtsam_unstable/discrete/SingleValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class GTSAM_UNSTABLE_EXPORT SingleValue : public Constraint {
}

/// Calculate value
double operator()(const Assignment<Key>& values) const override;
double evaluate(const Assignment<Key>& values) const override;

/// Convert into a decisiontree
DecisionTreeFactor toDecisionTreeFactor() const override;
Expand Down

0 comments on commit a98ac0f

Please sign in to comment.