aGrUM  0.16.0
maxInducedWidthMCBayesNetGenerator_tpl.h
Go to the documentation of this file.
1 
31 
32 namespace gum {
33 #ifdef _MSC_VER
34 # define MCBG MCBayesNetGenerator
35 # define IBNG IBayesNetGenerator
36 #else
37 # define MCBG MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >
38 # define IBNG IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >
39 #endif
40  // Default constructor.
41  // Use the SimpleCPTGenerator for generating the BNs CPT.
42  template < typename GUM_SCALAR,
43  template < typename >
44  class ICPTGenerator,
45  template < typename >
46  class ICPTDisturber >
47  INLINE MaxInducedWidthMCBayesNetGenerator<
48  GUM_SCALAR,
49  ICPTGenerator,
50  ICPTDisturber >::MaxInducedWidthMCBayesNetGenerator(Size nbrNodes,
51  Size maxArcs,
52  Size maxModality,
53  Size maxInducedWidth,
54  Idx iteration,
55  Idx p,
56  Idx q) :
57  MCBG(nbrNodes, maxArcs, maxModality, iteration, p, q) {
58  if (maxInducedWidth == 0)
60  "maxInducedWidth must be at least equal "
61  "to 1 to have a connexe graph");
62 
63  _maxlog10InducedWidth = maxInducedWidth;
64  GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
65  }
66 
67  template < typename GUM_SCALAR,
68  template < typename >
69  class ICPTGenerator,
70  template < typename >
71  class ICPTDisturber >
72  INLINE MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR,
73  ICPTGenerator,
74  ICPTDisturber >::
76  Size maxInducedWidth,
77  Idx iteration,
78  Idx p,
79  Idx q) :
80  MCBG(bayesNet, iteration, p, q) {
81  _maxlog10InducedWidth = maxInducedWidth;
82  GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
83  }
84 
85  // Use this constructor if you want to use a different policy for generating
86  // CPT than the default one.
87  // The cptGenerator will be erased when the destructor is called.
88  // @param cptGenerator The policy used to generate CPT.
89  /*template<typename GUM_SCALAR, template<class> class ICPTGenerator,
90  template<class> class ICPDisturber>
91  MaxInducedWidthMCBayesNetGenerator<GUM_SCALAR,ICPTGenerator,ICPTDisturber>::MaxInducedWidthMCBayesNetGenerator(
92  CPTGenerator* cptGenerator,Size nbrNodes, Idx p,Idx q,Idx iteration,float
93  maxDensity , Size max_modality, Size maxInducedWidth):
94  MCBG<GUM_SCALAR,ICPTGenerator,ICPTDisturber>(cptGenerator,
95  nbrNodes,p,q,iteration, maxDensity,max_modality, maxInducedWidth){
96  GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
97  }*/
98 
99  // Destructor.
100  template < typename GUM_SCALAR,
101  template < typename >
102  class ICPTGenerator,
103  template < typename >
104  class ICPTDisturber >
106  GUM_SCALAR,
107  ICPTGenerator,
109  GUM_DESTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
110  // delete BayesNetGenerator<GUM_SCALAR>::_cptGenerator;
111  }
112 
113  template < typename GUM_SCALAR,
114  template < typename >
115  class ICPTGenerator,
116  template < typename >
117  class ICPTDisturber >
118  bool MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR,
119  ICPTGenerator,
120  ICPTDisturber >::__checkConditions() {
121  NodeProperty< Size > __modalitiesMap;
122 
123  for (auto node : this->_bayesNet.nodes())
124  __modalitiesMap.insert(node, this->_bayesNet.variable(node).domainSize());
125 
126  DefaultTriangulation tri(&(this->_bayesNet.moralGraph()), &__modalitiesMap);
127 
128  if (tri.maxLog10CliqueDomainSize() > _maxlog10InducedWidth) return false;
129 
130  return MCBG::__checkConditions();
131  }
132 
133  template < typename GUM_SCALAR,
134  template < typename >
135  class ICPTGenerator,
136  template < typename >
137  class ICPTDisturber >
138  INLINE Size
140  ICPTGenerator,
141  ICPTDisturber >::maxlog10InducedWidth()
142  const {
143  return _maxlog10InducedWidth;
144  }
145  template < typename GUM_SCALAR,
146  template < typename >
147  class ICPTGenerator,
148  template < typename >
149  class ICPTDisturber >
151  GUM_SCALAR,
152  ICPTGenerator,
154  if (maxlog10InducedWidth == 0)
156  "maxInducedWidth must be at least equal "
157  "to 1 to have a connexe graph");
158 
160  }
161 } /* namespace gum */
Class representing a Bayesian Network.
Definition: BayesNet.h:78
Idx q() const
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator.
double maxLog10CliqueDomainSize()
returns the max of log10DomainSize of the cliques in the junction tree.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
MaxInducedWidthMCBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality=2, Size maxInducedWidth=3, Idx iteration=5000, Idx p=30, Idx q=40)
Constructor.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
BayesNet< GUM_SCALAR > _bayesNet
void setMaxlog10InducedWidth(Size maxlog10InducedWidth)
Modifies the value of the number of maximum parents imposed on the BayesNetGenerator.
The default triangulation algorithm used by aGrUM.
Size maxlog10InducedWidth() const
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGene...
Size Idx
Type for indexes.
Definition: types.h:53
Size iteration() const
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Idx p() const
Return a constant reference to the probabilité p imposed on the Markov Chain BayesNetGenerator.
maxInducedWidthMCBayesNetGenerator.h <agrum/BN/generator/SimpleMCayesNetGenerator.h>
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
bool __checkConditions() final
function to holding the the specification wanted for the Bayesian markov.