aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
IBayesNetGenerator_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief Source implementation of IBayesNetGenerator
24  *
25  * @author Christophe GONZALES(@AMU), Pierre-Henri WUILLEMIN(@LIP6), Lionel TORTI
26  *and Ariele-Paolo MAESANO
27  *
28  */
29 
30 #include <agrum/BN/generator/IBayesNetGenerator.h>
31 
32 namespace gum {
33 
34  // Default constructor.
35  // Use the SimpleCPTGenerator for generating the BNs CPT.
36  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
37  INLINE IBayesNetGenerator< GUM_SCALAR, ICPTGenerator >::IBayesNetGenerator(
38  Size nbrNodes,
39  Size maxArcs,
40  Size maxModality) :
41  bayesNet_() {
44 
45  if (maxArcs < nbrNodes - 1 || maxArcs > (nbrNodes * (nbrNodes - 1)) / 2)
46  GUM_ERROR(OperationNotAllowed, " maxArcs value not possible ");
47 
48  if (maxModality < 2)
50  " maxModality must be at least equal to two ");
51 
52  maxArcs_ = maxArcs;
54  }
55 
56  // Destructor.
57  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
60  // delete cptGenerator_;
61  }
62 
63  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
65  for (auto node: bayesNet_.nodes())
67  bayesNet_.cpt(node));
68  }
69 
70  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
71  INLINE Size
73  return maxModality_;
74  }
75 
76  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
78  return nbrNodes_;
79  }
80 
81  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
83  return maxArcs_;
84  }
85 
86  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
88  Size maxModality) {
89  if (maxModality < 2)
91  " maxModality must be at least equal to two ");
92 
94  }
95  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
96  INLINE void
98  if ((maxArcs_ < nbrNodes - 1) || (maxArcs_ > (nbrNodes * (nbrNodes - 1)) / 2))
99  GUM_ERROR(OperationNotAllowed, " nbrNodes value not possible ");
100 
102  }
103 
104  template < typename GUM_SCALAR, template < typename > class ICPTGenerator >
105  INLINE void
107  if (maxArcs < nbrNodes_ - 1 || maxArcs > (nbrNodes_ * (nbrNodes_ - 1)) / 2)
108  GUM_ERROR(OperationNotAllowed, " maxArcs value not possible ");
109 
110  maxArcs_ = maxArcs;
111  }
112 
113  // Generates a Bayesian network using floats.
114  // @param nbrNodes The number of nodes in the generated BN.
115  // @param density The probability of adding an arc between two nodes.
116  // @return A BNs randomly generated.
117 
118 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669