Renamed fromRange -> FromRange and added an overloaded version for 1 parent
parent
540608fed4
commit
2945832086
|
|
@ -61,18 +61,27 @@ public:
|
|||
|
||||
/** Constructor from a frontal variable and a vector of parents */
|
||||
Conditional(Index key, const std::vector<Index>& parents) : nrFrontals_(1) {
|
||||
keys_.resize(1 + parents.size());
|
||||
*(beginFrontals()) = key;
|
||||
std::copy(parents.begin(), parents.end(), beginParents());
|
||||
}
|
||||
keys_.resize(1 + parents.size());
|
||||
*(beginFrontals()) = key;
|
||||
std::copy(parents.begin(), parents.end(), beginParents());
|
||||
}
|
||||
|
||||
/** Constructor from a frontal variable and an iterator range of parents */
|
||||
template<typename Iterator>
|
||||
static Conditional::shared_ptr FromRange(Index key, Iterator firstParent, Iterator lastParent) : nrFrontals_(1) {
|
||||
Conditional::shared_ptr conditional(new Conditional);
|
||||
conditional->keys_.push_back(key);
|
||||
std::copy(firstKey, lastKey, back_inserter(conditional->keys_));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Named constructor from any number of frontal variables and parents */
|
||||
template<typename Iterator>
|
||||
static shared_ptr fromRange(Iterator firstKey, Iterator lastKey, size_t nrFrontals) {
|
||||
shared_ptr conditional(new Conditional);
|
||||
conditional->nrFrontals_ = nrFrontals;
|
||||
std::copy(firstKey, lastKey, back_inserter(conditional->keys_));
|
||||
return conditional;
|
||||
static Conditional::shared_ptr FromRange(Iterator firstKey, Iterator lastKey, size_t nrFrontals) {
|
||||
Conditional::shared_ptr conditional(new Conditional);
|
||||
conditional->nrFrontals_ = nrFrontals;
|
||||
std::copy(firstKey, lastKey, back_inserter(conditional->keys_));
|
||||
return conditional;
|
||||
}
|
||||
|
||||
/** check equality */
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ boost::shared_ptr<BayesNet<Conditional> > Factor::eliminate(size_t nrFrontals) {
|
|||
BayesNet<Conditional>::shared_ptr fragment(new BayesNet<Conditional>());
|
||||
const_iterator nextFrontal = this->begin();
|
||||
for(Index n = 0; n < nrFrontals; ++n, ++nextFrontal)
|
||||
fragment->push_back(Conditional::fromRange(nextFrontal, const_iterator(this->end()), 1));
|
||||
fragment->push_back(Conditional::FromRange(nextFrontal, const_iterator(this->end()), 1));
|
||||
if(nrFrontals > 0)
|
||||
keys_.assign(fragment->back()->beginParents(), fragment->back()->endParents());
|
||||
return fragment;
|
||||
|
|
|
|||
|
|
@ -22,9 +22,9 @@ TEST(SymbolicFactor, eliminate) {
|
|||
BayesNet<Conditional> fragment = *actual.eliminate(3);
|
||||
|
||||
Factor expected(keys.begin()+3, keys.end());
|
||||
Conditional::shared_ptr expected0 = Conditional::fromRange(keys.begin(), keys.end(), 1);
|
||||
Conditional::shared_ptr expected1 = Conditional::fromRange(keys.begin()+1, keys.end(), 1);
|
||||
Conditional::shared_ptr expected2 = Conditional::fromRange(keys.begin()+2, keys.end(), 1);
|
||||
Conditional::shared_ptr expected0 = Conditional::FromRange(keys.begin(), keys.end(), 1);
|
||||
Conditional::shared_ptr expected1 = Conditional::FromRange(keys.begin()+1, keys.end(), 1);
|
||||
Conditional::shared_ptr expected2 = Conditional::FromRange(keys.begin()+2, keys.end(), 1);
|
||||
|
||||
CHECK(assert_equal(fragment.size(), size_t(3)));
|
||||
CHECK(assert_equal(expected, actual));
|
||||
|
|
|
|||
Loading…
Reference in New Issue