aGrUM  0.20.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. More...
 
 TreeWidthSearch (const TreeWidthSearch &from)
 Copy constructor. More...
 
virtual ~TreeWidthSearch ()
 Destructor. More...
 
TreeWidthSearchoperator= (const TreeWidthSearch &from)
 Copy operator. More...
 
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 Attributes

DFSTree< GUM_SCALAR > * tree_
 

Protected Member Functions

double computeCost_ (const Pattern &p)
 

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 263 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 409 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

409  :
410  SearchStrategy< GUM_SCALAR >() {
411  GUM_CONSTRUCTOR(TreeWidthSearch);
412  }
TreeWidthSearch()
Default constructor.
+ Here is the call 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 415 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

416  :
417  SearchStrategy< GUM_SCALAR >(from) {
418  GUM_CONS_CPY(TreeWidthSearch);
419  }
TreeWidthSearch()
Default constructor.
+ 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 422 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

422  {
423  GUM_DESTRUCTOR(TreeWidthSearch);
424  }
TreeWidthSearch()
Default constructor.
+ 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 454 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

457  {
458  return cost(*parent) >= cost(*child);
459  }
+ 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 444 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

444  {
445  Size tree_width = 0;
446 
447  for (const auto n: r->nodes())
448  tree_width += r->label(n).tree_width;
449 
450  return tree_width >= cost(*r);
451  }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ 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 35 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

35  {
36  double cost = 0;
37  const Sequence< PRMInstance< GUM_SCALAR >* >& seq
38  = *(this->tree_->data(p).iso_map.begin().val());
39  Sequence< PRMClassElement< GUM_SCALAR >* > input_set;
40 
41  for (const auto inst: seq) {
42  for (const auto input: inst->type().slotChains())
43  for (const auto inst2: inst->getInstances(input->id()))
44  if ((!seq.exists(inst2))
45  && (!input_set.exists(
46  &(inst2->get(input->lastElt().safeName()))))) {
47  cost += std::log(input->type().variable().domainSize());
48  input_set.insert(&(inst2->get(input->lastElt().safeName())));
49  }
50 
51  for (auto vec = inst->beginInvRef(); vec != inst->endInvRef(); ++vec)
52  for (const auto inverse: *vec.val())
53  if (!seq.exists(inverse.first)) {
54  cost += std::log(
55  inst->get(vec.key()).type().variable().domainSize());
56  break;
57  }
58  }
59 
60  return cost;
61  }
DFSTree< GUM_SCALAR > * tree_
+ Here is the call graph for this function:

◆ cost()

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

Definition at line 434 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

434  {
435  try {
436  return map__[&p];
437  } catch (NotFound&) {
438  map__.insert(&p, this->computeCost_(p));
439  return map__[&p];
440  }
441  }
HashTable< const Pattern *, double > map__
double computeCost_(const Pattern &p)
+ Here is the call 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 468 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

469  {
470  return i->tree_width < j->tree_width;
471  }
+ Here is the call graph for this function:

◆ 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 462 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

463  {
464  return cost(*i) < cost(*j);
465  }
+ 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 428 of file searchStrategy_tpl.h.

429  {
430  return *this;
431  }

◆ setTree()

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

Definition at line 235 of file searchStrategy_tpl.h.

References gum::prm::gspan::operator<<().

235  {
236  this->tree_ = tree;
237  }
DFSTree< GUM_SCALAR > * tree_
+ Here is the call graph for this function:

Member Data Documentation

◆ map__

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

Definition at line 301 of file searchStrategy.h.

◆ tree_

template<typename GUM_SCALAR >
DFSTree< GUM_SCALAR >* gum::prm::gspan::SearchStrategy< GUM_SCALAR >::tree_
protectedinherited

Definition at line 112 of file searchStrategy.h.


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