aGrUM  0.14.2
maxInducedWidthMCBayesNetGenerator_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN & Ariele-Paolo MAESANO *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
28 
29 namespace gum {
30 #ifdef _MSC_VER
31 # define MCBG MCBayesNetGenerator
32 # define IBNG IBayesNetGenerator
33 #else
34 # define MCBG MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >
35 # define IBNG IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >
36 #endif
37  // Default constructor.
38  // Use the SimpleCPTGenerator for generating the BNs CPT.
39  template < typename GUM_SCALAR,
40  template < typename >
41  class ICPTGenerator,
42  template < typename >
43  class ICPTDisturber >
44  INLINE MaxInducedWidthMCBayesNetGenerator<
45  GUM_SCALAR,
46  ICPTGenerator,
47  ICPTDisturber >::MaxInducedWidthMCBayesNetGenerator(Size nbrNodes,
48  Size maxArcs,
49  Size maxModality,
50  Size maxInducedWidth,
51  Idx iteration,
52  Idx p,
53  Idx q) :
54  MCBG(nbrNodes, maxArcs, maxModality, iteration, p, q) {
55  if (maxInducedWidth == 0)
57  "maxInducedWidth must be at least equal "
58  "to 1 to have a connexe graph");
59 
60  _maxlog10InducedWidth = maxInducedWidth;
61  GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
62  }
63 
64  template < typename GUM_SCALAR,
65  template < typename >
66  class ICPTGenerator,
67  template < typename >
68  class ICPTDisturber >
69  INLINE MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR,
70  ICPTGenerator,
71  ICPTDisturber >::
73  Size maxInducedWidth,
74  Idx iteration,
75  Idx p,
76  Idx q) :
77  MCBG(bayesNet, iteration, p, q) {
78  _maxlog10InducedWidth = maxInducedWidth;
79  GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
80  }
81 
82  // Use this constructor if you want to use a different policy for generating
83  // CPT than the default one.
84  // The cptGenerator will be erased when the destructor is called.
85  // @param cptGenerator The policy used to generate CPT.
86  /*template<typename GUM_SCALAR, template<class> class ICPTGenerator,
87  template<class> class ICPDisturber>
88  MaxInducedWidthMCBayesNetGenerator<GUM_SCALAR,ICPTGenerator,ICPTDisturber>::MaxInducedWidthMCBayesNetGenerator(
89  CPTGenerator* cptGenerator,Size nbrNodes, Idx p,Idx q,Idx iteration,float
90  maxDensity , Size max_modality, Size maxInducedWidth):
91  MCBG<GUM_SCALAR,ICPTGenerator,ICPTDisturber>(cptGenerator,
92  nbrNodes,p,q,iteration, maxDensity,max_modality, maxInducedWidth){
93  GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
94  }*/
95 
96  // Destructor.
97  template < typename GUM_SCALAR,
98  template < typename >
99  class ICPTGenerator,
100  template < typename >
101  class ICPTDisturber >
103  GUM_SCALAR,
104  ICPTGenerator,
106  GUM_DESTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
107  // delete BayesNetGenerator<GUM_SCALAR>::_cptGenerator;
108  }
109 
110  template < typename GUM_SCALAR,
111  template < typename >
112  class ICPTGenerator,
113  template < typename >
114  class ICPTDisturber >
115  bool MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR,
116  ICPTGenerator,
117  ICPTDisturber >::__checkConditions() {
118  NodeProperty< Size > __modalitiesMap;
119 
120  for (auto node : this->_bayesNet.nodes())
121  __modalitiesMap.insert(node, this->_bayesNet.variable(node).domainSize());
122 
123  DefaultTriangulation tri(&(this->_bayesNet.moralGraph()), &__modalitiesMap);
124 
125  if (tri.maxLog10CliqueDomainSize() > _maxlog10InducedWidth) return false;
126 
127  return MCBG::__checkConditions();
128  }
129 
130  template < typename GUM_SCALAR,
131  template < typename >
132  class ICPTGenerator,
133  template < typename >
134  class ICPTDisturber >
135  INLINE Size
137  ICPTGenerator,
138  ICPTDisturber >::maxlog10InducedWidth()
139  const {
140  return _maxlog10InducedWidth;
141  }
142  template < typename GUM_SCALAR,
143  template < typename >
144  class ICPTGenerator,
145  template < typename >
146  class ICPTDisturber >
148  GUM_SCALAR,
149  ICPTGenerator,
151  if (maxlog10InducedWidth == 0)
153  "maxInducedWidth must be at least equal "
154  "to 1 to have a connexe graph");
155 
157  }
158 } /* namespace gum */
Class representing a Bayesian Network.
Definition: BayesNet.h:76
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.
Class for generating bayesian networks using MC algorithm cf.
MaxInducedWidthMCBayesNetGenerator(Size nbrNodes, Size maxArcs, Size maxModality=2, Size maxInducedWidth=3, Idx iteration=5000, Idx p=30, Idx q=40)
Constructor.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
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:50
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:45
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:52
bool __checkConditions() final
function to holding the the specification wanted for the Bayesian markov.