aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::prm::gspan::TreeWidthSearch< GUM_SCALAR > Class Template Reference

A growth is accepted if and only if the new growth has a tree width less large or equal than its father. More...

#include <agrum/PRM/gspan/DFSTree.h>

Inheritance diagram for gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >:
Collaboration diagram for gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >:

Public Member Functions

Constructor and destructor.
 TreeWidthSearch ()
 Default constructor.
 TreeWidthSearch (const TreeWidthSearch &from)
 Copy constructor.
 ~TreeWidthSearch () override
 Destructor.
TreeWidthSearchoperator= (const TreeWidthSearch &from)
 Copy operator.
Search methods.
double cost (const Pattern &p)
bool accept_root (const Pattern *r) override
bool accept_growth (const Pattern *parent, const Pattern *child, const EdgeGrowth< GUM_SCALAR > &growth) override
bool operator() (LabelData *i, LabelData *j) override
bool operator() (Pattern *i, Pattern *j) override
Search methods.
void setTree (DFSTree< GUM_SCALAR > *tree)

Protected Member Functions

double computeCost_ (const Pattern &p)

Protected Attributes

DFSTree< GUM_SCALAR > * tree_

Private Attributes

HashTable< const Pattern *, double_map_

Detailed Description

template<GUM_Numeric GUM_SCALAR>
class gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >

A growth is accepted if and only if the new growth has a tree width less large or equal than its father.

Definition at line 270 of file searchStrategy.h.

Constructor & Destructor Documentation

◆ TreeWidthSearch() [1/2]

template<GUM_Numeric GUM_SCALAR>
gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::TreeWidthSearch ( )

Default constructor.

Definition at line 393 of file searchStrategy_tpl.h.

395 }
A growth is accepted if and only if the new growth has a tree width less large or equal than its fath...

References gum::prm::gspan::SearchStrategy< GUM_SCALAR >::SearchStrategy(), and TreeWidthSearch().

Referenced by TreeWidthSearch(), TreeWidthSearch(), ~TreeWidthSearch(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TreeWidthSearch() [2/2]

template<GUM_Numeric GUM_SCALAR>
gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::TreeWidthSearch ( const TreeWidthSearch< GUM_SCALAR > & from)

Copy constructor.

Definition at line 398 of file searchStrategy_tpl.h.

References gum::prm::gspan::SearchStrategy< GUM_SCALAR >::SearchStrategy(), and TreeWidthSearch().

Here is the call graph for this function:

◆ ~TreeWidthSearch()

template<GUM_Numeric GUM_SCALAR>
gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::~TreeWidthSearch ( )
override

Destructor.

Definition at line 404 of file searchStrategy_tpl.h.

404 {
406 }

References TreeWidthSearch().

Here is the call graph for this function:

Member Function Documentation

◆ accept_growth()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_growth ( const Pattern * parent,
const Pattern * child,
const EdgeGrowth< GUM_SCALAR > & growth )
overridevirtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 435 of file searchStrategy_tpl.h.

437 {
438 return cost(*parent) >= cost(*child);
439 }

References cost().

Here is the call graph for this function:

◆ accept_root()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_root ( const Pattern * r)
overridevirtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 425 of file searchStrategy_tpl.h.

425 {
426 Size tree_width = 0;
427
428 for (const auto n: r->nodes())
429 tree_width += r->label(n).tree_width;
430
431 return tree_width >= cost(*r);
432 }

References cost(), gum::prm::gspan::Pattern::label(), gum::prm::gspan::Pattern::nodes(), and gum::prm::gspan::LabelData::tree_width.

Here is the call graph for this function:

◆ computeCost_()

template<GUM_Numeric GUM_SCALAR>
double gum::prm::gspan::SearchStrategy< GUM_SCALAR >::computeCost_ ( const Pattern & p)
protectedinherited

Definition at line 57 of file searchStrategy_tpl.h.

57 {
58 double cost = 0;
60 = *(this->tree_->data(p).iso_map.begin().val());
62
63 for (const auto inst: seq) {
64 for (const auto input: inst->type().slotChains())
65 for (const auto inst2: inst->getInstances(input->id()))
66 if ((!seq.exists(inst2))
67 && (!input_set.exists(&(inst2->get(input->lastElt().safeName()))))) {
68 cost += std::log(input->type().variable().domainSize());
69 input_set.insert(&(inst2->get(input->lastElt().safeName())));
70 }
71
72 for (auto vec = inst->beginInvRef(); vec != inst->endInvRef(); ++vec)
73 for (const auto& inverse: *vec.val())
74 if (!seq.exists(inverse.first)) {
75 cost += std::log(inst->get(vec.key()).type().variable().domainSize());
76 break;
77 }
78 }
79
80 return cost;
81 }
This is an abstract class used to tune search strategies in the gspan algorithm.
DFSTree< GUM_SCALAR > * tree_

References gum::SequenceImplementation< Key, Gen >::exists(), gum::SequenceImplementation< Key, Gen >::insert(), and tree_.

Referenced by gum::prm::gspan::StrictSearch< GUM_SCALAR >::_compute_costs_(), and gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cost()

template<GUM_Numeric GUM_SCALAR>
double gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost ( const Pattern & p)

Definition at line 415 of file searchStrategy_tpl.h.

415 {
416 auto pm = _map_.tryGet(&p);
417 if (!pm) {
418 _map_.insert(&p, this->computeCost_(p));
419 pm = _map_.tryGet(&p);
420 }
421 return *pm;
422 }
double computeCost_(const Pattern &p)
HashTable< const Pattern *, double > _map_

References _map_, and gum::prm::gspan::SearchStrategy< GUM_SCALAR >::computeCost_().

Referenced by accept_growth(), accept_root(), and operator()().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator()() [1/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator() ( LabelData * i,
LabelData * j )
overridevirtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 447 of file searchStrategy_tpl.h.

447 {
448 return i->tree_width < j->tree_width;
449 }

References gum::prm::gspan::LabelData::tree_width.

◆ operator()() [2/2]

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator() ( gspan::Pattern * i,
gspan::Pattern * j )
overridevirtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 442 of file searchStrategy_tpl.h.

442 {
443 return cost(*i) < cost(*j);
444 }

References cost().

Here is the call graph for this function:

◆ operator=()

template<GUM_Numeric GUM_SCALAR>
TreeWidthSearch< GUM_SCALAR > & gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator= ( const TreeWidthSearch< GUM_SCALAR > & from)

Copy operator.

Definition at line 410 of file searchStrategy_tpl.h.

410 {
411 return *this;
412 }

References TreeWidthSearch().

Here is the call graph for this function:

◆ setTree()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::gspan::SearchStrategy< GUM_SCALAR >::setTree ( DFSTree< GUM_SCALAR > * tree)
inherited

Definition at line 236 of file searchStrategy_tpl.h.

236 {
237 this->tree_ = tree;
238 }

References tree_.

Member Data Documentation

◆ _map_

template<GUM_Numeric GUM_SCALAR>
HashTable< const Pattern*, double > gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::_map_
private

Definition at line 308 of file searchStrategy.h.

Referenced by cost().

◆ tree_


The documentation for this class was generated from the following files: