aGrUM 2.3.2
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.
virtual ~TreeWidthSearch ()
 Destructor.
TreeWidthSearchoperator= (const TreeWidthSearch &from)
 Copy operator.
Search methods.
double cost (const Pattern &p)
virtual bool accept_root (const Pattern *r)
virtual bool accept_growth (const Pattern *parent, const Pattern *child, const EdgeGrowth< GUM_SCALAR > &growth)
virtual bool operator() (LabelData *i, LabelData *j)
virtual bool operator() (Pattern *i, Pattern *j)
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<typename 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 271 of file searchStrategy.h.

Constructor & Destructor Documentation

◆ TreeWidthSearch() [1/2]

template<typename GUM_SCALAR>
INLINE gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::TreeWidthSearch ( )

Default constructor.

Definition at line 401 of file searchStrategy_tpl.h.

403 }
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<typename GUM_SCALAR>
INLINE gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::TreeWidthSearch ( const TreeWidthSearch< GUM_SCALAR > & from)

Copy constructor.

Definition at line 406 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<typename GUM_SCALAR>
INLINE gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::~TreeWidthSearch ( )
virtual

Destructor.

Definition at line 412 of file searchStrategy_tpl.h.

412 {
414 }

References TreeWidthSearch().

Here is the call graph for this function:

Member Function Documentation

◆ accept_growth()

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

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

Definition at line 444 of file searchStrategy_tpl.h.

446 {
447 return cost(*parent) >= cost(*child);
448 }

References cost().

Here is the call graph for this function:

◆ accept_root()

template<typename GUM_SCALAR>
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_root ( const Pattern * r)
virtual

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

Definition at line 433 of file searchStrategy_tpl.h.

433 {
434 Size tree_width = 0;
435
436 for (const auto n: r->nodes())
437 tree_width += r->label(n).tree_width;
438
439 return tree_width >= cost(*r);
440 }

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<typename GUM_SCALAR>
double gum::prm::gspan::SearchStrategy< GUM_SCALAR >::computeCost_ ( const Pattern & p)
protectedinherited

Definition at line 56 of file searchStrategy_tpl.h.

56 {
57 double cost = 0;
59 = *(this->tree_->data(p).iso_map.begin().val());
61
62 for (const auto inst: seq) {
63 for (const auto input: inst->type().slotChains())
64 for (const auto inst2: inst->getInstances(input->id()))
65 if ((!seq.exists(inst2))
66 && (!input_set.exists(&(inst2->get(input->lastElt().safeName()))))) {
67 cost += std::log(input->type().variable().domainSize());
68 input_set.insert(&(inst2->get(input->lastElt().safeName())));
69 }
70
71 for (auto vec = inst->beginInvRef(); vec != inst->endInvRef(); ++vec)
72 for (const auto& inverse: *vec.val())
73 if (!seq.exists(inverse.first)) {
74 cost += std::log(inst->get(vec.key()).type().variable().domainSize());
75 break;
76 }
77 }
78
79 return cost;
80 }
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<typename GUM_SCALAR>
INLINE double gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost ( const Pattern & p)

Definition at line 423 of file searchStrategy_tpl.h.

423 {
424 try {
425 return _map_[&p];
426 } catch (NotFound const&) {
427 _map_.insert(&p, this->computeCost_(p));
428 return _map_[&p];
429 }
430 }
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<typename GUM_SCALAR>
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator() ( LabelData * i,
LabelData * j )
virtual

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

Definition at line 456 of file searchStrategy_tpl.h.

456 {
457 return i->tree_width < j->tree_width;
458 }

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

◆ operator()() [2/2]

template<typename GUM_SCALAR>
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator() ( gspan::Pattern * i,
gspan::Pattern * j )
virtual

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

Definition at line 451 of file searchStrategy_tpl.h.

451 {
452 return cost(*i) < cost(*j);
453 }

References cost().

Here is the call graph for this function:

◆ operator=()

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

Copy operator.

Definition at line 418 of file searchStrategy_tpl.h.

418 {
419 return *this;
420 }

References TreeWidthSearch().

Here is the call graph for this function:

◆ setTree()

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

Definition at line 238 of file searchStrategy_tpl.h.

238 {
239 this->tree_ = tree;
240 }

References tree_.

Member Data Documentation

◆ _map_

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

Definition at line 309 of file searchStrategy.h.

Referenced by cost().

◆ tree_


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