aGrUM  0.20.3
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 260 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 383 of file searchStrategy_tpl.h.

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

383  : SearchStrategy< GUM_SCALAR >() {
384  GUM_CONSTRUCTOR(TreeWidthSearch);
385  }
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 389 of file searchStrategy_tpl.h.

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

389  :
390  SearchStrategy< GUM_SCALAR >(from) {
391  GUM_CONS_CPY(TreeWidthSearch);
392  }
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 395 of file searchStrategy_tpl.h.

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

395  {
396  GUM_DESTRUCTOR(TreeWidthSearch);
397  }
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 427 of file searchStrategy_tpl.h.

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

429  {
430  return cost(*parent) >= cost(*child);
431  }
+ 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 416 of file searchStrategy_tpl.h.

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

416  {
417  Size tree_width = 0;
418 
419  for (const auto n: r->nodes())
420  tree_width += r->label(n).tree_width;
421 
422  return tree_width >= cost(*r);
423  }
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(&(inst2->get(input->lastElt().safeName()))))) {
46  cost += std::log(input->type().variable().domainSize());
47  input_set.insert(&(inst2->get(input->lastElt().safeName())));
48  }
49 
50  for (auto vec = inst->beginInvRef(); vec != inst->endInvRef(); ++vec)
51  for (const auto inverse: *vec.val())
52  if (!seq.exists(inverse.first)) {
53  cost += std::log(inst->get(vec.key()).type().variable().domainSize());
54  break;
55  }
56  }
57 
58  return cost;
59  }
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 406 of file searchStrategy_tpl.h.

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

406  {
407  try {
408  return _map_[&p];
409  } catch (NotFound&) {
410  _map_.insert(&p, this->computeCost_(p));
411  return _map_[&p];
412  }
413  }
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 439 of file searchStrategy_tpl.h.

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

439  {
440  return i->tree_width < j->tree_width;
441  }
+ 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 434 of file searchStrategy_tpl.h.

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

434  {
435  return cost(*i) < cost(*j);
436  }
+ 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 401 of file searchStrategy_tpl.h.

401  {
402  return *this;
403  }

◆ setTree()

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

Definition at line 219 of file searchStrategy_tpl.h.

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

219  {
220  this->tree_ = tree;
221  }
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 298 of file searchStrategy.h.

◆ tree_

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

Definition at line 111 of file searchStrategy.h.


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