aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
multiDimFunctionGraphGenerator.cpp
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 /**
23  * @file
24  * @brief Sources of MultiDimFunctionGraphGenerator.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
28  * GONZALES(@AMU)
29  *
30  */
31 
32 #include <cstdlib>
33 #include <random>
34 
35 #include <agrum/tools/core/priorityQueue.h>
36 #include <agrum/tools/multidim/implementations/multiDimFunctionGraphGenerator.h>
37 
38 namespace gum {
39  // Constructor
41  Idx maxVar,
42  Idx minVar,
43  const Sequence< const DiscreteVariable* >& varSeq) :
44  varSeq__(varSeq) {
46 
48  }
49 
50  // Destructor
53  }
54 
58 
60  = varSeq__.beginSafe();
62  ++varIter) {
64  }
65 
67  Idx nbIter = 0;
68 
69  std::vector< NodeId > filo;
70 
75 
76  while (!filo.empty()) { //&& nbIter < 20 ){
77 
79  filo.pop_back();
83 
85  Idx nbPotentialSons = 0;
86  for (Idx varPos = 0;
88  varPos++) {
89  const DiscreteVariable* var
91 
92  Idx vsp = varSeq__.pos(var);
93  if (vsp > cvp) {
94  const Link< NodeId >* nicleIter
96  while (nicleIter) {
100  }
101  }
102  }
103 
105  modality++) {
106  if (!potentialSons.list()
107  || (double)std::rand() / (double)RAND_MAX
108  > (1.0 / (1.0 + 3.0 / nbPotentialSons))) {
112  modality,
114  (double)std::rand() / (double)RAND_MAX * 100));
115  } else {
116  Idx sonVarPos
121  modality,
126  }
127  } else {
128  Idx sonPos
129  = (Idx)(((double)std::rand() / (double)RAND_MAX) * nbPotentialSons);
132  while (sonPos) {
134  sonPos--;
135  }
137  modality,
138  nicleIter->element());
139  }
140  }
141  ++nbIter;
142  }
143 
146 
147  return generatedFunctionGraph;
148  }
149 
153  return !(currentNodeId == 1
154  || ((double)std::rand() / (double)RAND_MAX
155  < 0.9
156  + 0.01
158  / float(nbTotalVar__))
160  }
161 
163  Idx randOut = 0;
164 
165  if (span != 0) {
166  auto generator = gum::getRandomGenerator();
167  std::weibull_distribution< double > distribution(double(span), 1.0);
168  randOut = (Idx)(distribution(generator) * span / 2);
169  if (randOut > span) randOut = span;
170  }
171 
172  return offset + randOut;
173  }
174 
175 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669