remove constructors that need parents
parent
bc449c1a45
commit
bd30bef1a3
|
@ -38,16 +38,15 @@ using std::vector;
|
|||
namespace gtsam {
|
||||
|
||||
/* ************************************************************************** */
|
||||
TableDistribution::TableDistribution(const size_t nrFrontals,
|
||||
const TableFactor& f)
|
||||
: BaseConditional(nrFrontals, DecisionTreeFactor(f.discreteKeys(), ADT())),
|
||||
table_(f / (*f.sum(nrFrontals))) {}
|
||||
TableDistribution::TableDistribution(const TableFactor& f)
|
||||
: BaseConditional(f.keys().size(),
|
||||
DecisionTreeFactor(f.discreteKeys(), ADT())),
|
||||
table_(f / (*f.sum(f.keys().size()))) {}
|
||||
|
||||
/* ************************************************************************** */
|
||||
TableDistribution::TableDistribution(
|
||||
size_t nrFrontals, const DiscreteKeys& keys,
|
||||
const Eigen::SparseVector<double>& potentials)
|
||||
: BaseConditional(nrFrontals, keys, DecisionTreeFactor(keys, ADT())),
|
||||
const DiscreteKeys& keys, const Eigen::SparseVector<double>& potentials)
|
||||
: BaseConditional(keys.size(), keys, DecisionTreeFactor(keys, ADT())),
|
||||
table_(TableFactor(keys, potentials)) {}
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
@ -66,11 +65,6 @@ TableDistribution::TableDistribution(const TableFactor& joint,
|
|||
keys_.insert(keys_.end(), orderedKeys.begin(), orderedKeys.end());
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
TableDistribution::TableDistribution(const Signature& signature)
|
||||
: BaseConditional(1, DecisionTreeFactor(DiscreteKeys{{1, 1}}, ADT(1))),
|
||||
table_(TableFactor(signature.discreteKeys(), signature.cpt())) {}
|
||||
|
||||
/* ************************************************************************** */
|
||||
void TableDistribution::print(const string& s,
|
||||
const KeyFormatter& formatter) const {
|
||||
|
@ -107,7 +101,7 @@ DiscreteConditional::shared_ptr TableDistribution::max(
|
|||
const Ordering& keys) const {
|
||||
auto m = *table_.max(keys);
|
||||
|
||||
return std::make_shared<TableDistribution>(m.discreteKeys().size(), m);
|
||||
return std::make_shared<TableDistribution>(m);
|
||||
}
|
||||
|
||||
/* ****************************************************************************/
|
||||
|
@ -124,8 +118,8 @@ DiscreteConditional::shared_ptr TableDistribution::prune(
|
|||
size_t maxNrAssignments) const {
|
||||
TableFactor pruned = table_.prune(maxNrAssignments);
|
||||
|
||||
return std::make_shared<TableDistribution>(
|
||||
this->nrFrontals(), this->discreteKeys(), pruned.sparseTable());
|
||||
return std::make_shared<TableDistribution>(this->discreteKeys(),
|
||||
pruned.sparseTable());
|
||||
}
|
||||
|
||||
} // namespace gtsam
|
||||
|
|
|
@ -58,58 +58,16 @@ class GTSAM_EXPORT TableDistribution : public DiscreteConditional {
|
|||
/// Default constructor needed for serialization.
|
||||
TableDistribution() {}
|
||||
|
||||
/// Construct from factor, taking the first `nFrontals` keys as frontals.
|
||||
TableDistribution(size_t nFrontals, const TableFactor& f);
|
||||
/// Construct from TableFactor.
|
||||
TableDistribution(const TableFactor& f);
|
||||
|
||||
/**
|
||||
* Construct from DiscreteKeys and SparseVector, taking the first
|
||||
* `nFrontals` keys as frontals, in the order given.
|
||||
*/
|
||||
TableDistribution(size_t nFrontals, const DiscreteKeys& keys,
|
||||
TableDistribution(const DiscreteKeys& keys,
|
||||
const Eigen::SparseVector<double>& potentials);
|
||||
|
||||
/** Construct from signature */
|
||||
explicit TableDistribution(const Signature& signature);
|
||||
|
||||
/**
|
||||
* Construct from key, parents, and a Signature::Table specifying the
|
||||
* conditional probability table (CPT) in 00 01 10 11 order. For
|
||||
* three-valued, it would be 00 01 02 10 11 12 20 21 22, etc....
|
||||
*
|
||||
* Example: TableDistribution P(D, {B,E}, table);
|
||||
*/
|
||||
TableDistribution(const DiscreteKey& key, const DiscreteKeys& parents,
|
||||
const Signature::Table& table)
|
||||
: TableDistribution(Signature(key, parents, table)) {}
|
||||
|
||||
/**
|
||||
* Construct from key, parents, and a vector<double> specifying the
|
||||
* conditional probability table (CPT) in 00 01 10 11 order. For
|
||||
* three-valued, it would be 00 01 02 10 11 12 20 21 22, etc....
|
||||
*
|
||||
* Example: TableDistribution P(D, {B,E}, table);
|
||||
*/
|
||||
TableDistribution(const DiscreteKey& key, const DiscreteKeys& parents,
|
||||
const std::vector<double>& table)
|
||||
: TableDistribution(1, TableFactor(DiscreteKeys{key} & parents, table)) {}
|
||||
|
||||
/**
|
||||
* Construct from key, parents, and a string specifying the conditional
|
||||
* probability table (CPT) in 00 01 10 11 order. For three-valued, it would
|
||||
* be 00 01 02 10 11 12 20 21 22, etc....
|
||||
*
|
||||
* The string is parsed into a Signature::Table.
|
||||
*
|
||||
* Example: TableDistribution P(D, {B,E}, "9/1 2/8 3/7 1/9");
|
||||
*/
|
||||
TableDistribution(const DiscreteKey& key, const DiscreteKeys& parents,
|
||||
const std::string& spec)
|
||||
: TableDistribution(Signature(key, parents, spec)) {}
|
||||
|
||||
/// No-parent specialization; can also use DiscreteDistribution.
|
||||
TableDistribution(const DiscreteKey& key, const std::string& spec)
|
||||
: TableDistribution(Signature(key, {}, spec)) {}
|
||||
|
||||
/**
|
||||
* @brief construct P(X|Y) = f(X,Y)/f(Y) from f(X,Y) and f(Y)
|
||||
* Assumes but *does not check* that f(Y)=sum_X f(X,Y).
|
||||
|
|
Loading…
Reference in New Issue