aGrUM  0.13.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 > class ICPTGenerator,
41  template < typename > class ICPTDisturber >
42  INLINE MaxInducedWidthMCBayesNetGenerator<
43  GUM_SCALAR,
44  ICPTGenerator,
45  ICPTDisturber >::MaxInducedWidthMCBayesNetGenerator(Size nbrNodes,
46  Size maxArcs,
47  Size maxModality,
48  Size maxInducedWidth,
49  Idx iteration,
50  Idx p,
51  Idx q) :
52  MCBG(nbrNodes, maxArcs, maxModality, iteration, p, q) {
53  if (maxInducedWidth == 0)
55  "maxInducedWidth must be at least equal "
56  "to 1 to have a connexe graph");
57 
58  _maxlog10InducedWidth = maxInducedWidth;
59  GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
60  }
61 
62  template < typename GUM_SCALAR,
63  template < typename > class ICPTGenerator,
64  template < typename > class ICPTDisturber >
65  INLINE MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR,
66  ICPTGenerator,
67  ICPTDisturber >::
69  Size maxInducedWidth,
70  Idx iteration,
71  Idx p,
72  Idx q) :
73  MCBG(bayesNet, iteration, p, q) {
74  _maxlog10InducedWidth = maxInducedWidth;
75  GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
76  }
77 
78  // Use this constructor if you want to use a different policy for generating
79  // CPT than the default one.
80  // The cptGenerator will be erased when the destructor is called.
81  // @param cptGenerator The policy used to generate CPT.
82  /*template<typename GUM_SCALAR, template<class> class ICPTGenerator,
83  template<class> class ICPDisturber>
84  MaxInducedWidthMCBayesNetGenerator<GUM_SCALAR,ICPTGenerator,ICPTDisturber>::MaxInducedWidthMCBayesNetGenerator(
85  CPTGenerator* cptGenerator,Size nbrNodes, Idx p,Idx q,Idx iteration,float
86  maxDensity , Size max_modality, Size maxInducedWidth):
87  MCBG<GUM_SCALAR,ICPTGenerator,ICPTDisturber>(cptGenerator,
88  nbrNodes,p,q,iteration, maxDensity,max_modality, maxInducedWidth){
89  GUM_CONSTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
90  }*/
91 
92  // Destructor.
93  template < typename GUM_SCALAR,
94  template < typename > class ICPTGenerator,
95  template < typename > class ICPTDisturber >
97  GUM_SCALAR,
98  ICPTGenerator,
100  GUM_DESTRUCTOR(MaxInducedWidthMCBayesNetGenerator);
101  // delete BayesNetGenerator<GUM_SCALAR>::_cptGenerator;
102  }
103 
104  template < typename GUM_SCALAR,
105  template < typename > class ICPTGenerator,
106  template < typename > class ICPTDisturber >
107  bool MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR,
108  ICPTGenerator,
109  ICPTDisturber >::__checkConditions() {
110  NodeProperty< Size > __modalitiesMap;
111 
112  for (auto node : this->_bayesNet.nodes())
113  __modalitiesMap.insert(node, this->_bayesNet.variable(node).domainSize());
114 
115  DefaultTriangulation tri(&(this->_bayesNet.moralGraph()), &__modalitiesMap);
116 
117  if (tri.maxLog10CliqueDomainSize() > _maxlog10InducedWidth) return false;
118 
119  return MCBG::__checkConditions();
120  }
121 
122  template < typename GUM_SCALAR,
123  template < typename > class ICPTGenerator,
124  template < typename > class ICPTDisturber >
125  INLINE Size
127  ICPTGenerator,
128  ICPTDisturber >::maxlog10InducedWidth()
129  const {
130  return _maxlog10InducedWidth;
131  }
132  template < typename GUM_SCALAR,
133  template < typename > class ICPTGenerator,
134  template < typename > class ICPTDisturber >
136  GUM_SCALAR,
137  ICPTGenerator,
139  if (maxlog10InducedWidth == 0)
141  "maxInducedWidth must be at least equal "
142  "to 1 to have a connexe graph");
143 
145  }
146 } /* namespace gum */
Class representing a Bayesian Network.
Definition: BayesNet.h:76
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
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.
Idx p() const
Return a constant reference to the probabilité p imposed on the Markov Chain BayesNetGenerator.
Size iteration() const
Return a constant reference to the number of iteration imposed on the Markov Chain BayesNetGenerator...
Size maxlog10InducedWidth() const
Return a constant reference to the number of maximum parents imposed on the Markov Chain BayesNetGene...
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
unsigned long Idx
Type for indexes.
Definition: types.h:43
Idx q() const
Return a constant reference to the probabilité imposed on the Markov Chain BayesNetGenerator.
maxInducedWidthMCBayesNetGenerator.h <agrum/BN/generator/SimpleMCayesNetGenerator.h>
#define GUM_ERROR(type, msg)
Definition: exceptions.h:66
bool __checkConditions() final
function to holding the the specification wanted for the Bayesian markov.