aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
multiDimFunctionGraphGenerator.cpp
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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 
61  ++varIter) {
63  }
64 
66  Idx nbIter = 0;
67 
68  std::vector< NodeId > filo;
69 
74 
75  while (!filo.empty()) { //&& nbIter < 20 ){
76 
78  filo.pop_back();
81 
83  Idx nbPotentialSons = 0;
86 
87  Idx vsp = _varSeq_.pos(var);
88  if (vsp > cvp) {
90  while (nicleIter) {
94  }
95  }
96  }
97 
99  if (!potentialSons.list()
100  || (double)std::rand() / (double)RAND_MAX > (1.0 / (1.0 + 3.0 / nbPotentialSons))) {
104  modality,
106  / (double)RAND_MAX * 100));
107  } else {
112  modality,
116  }
117  } else {
118  Idx sonPos = (Idx)(((double)std::rand() / (double)RAND_MAX) * nbPotentialSons);
121  while (sonPos) {
123  sonPos--;
124  }
126  }
127  }
128  ++nbIter;
129  }
130 
133 
134  return generatedFunctionGraph;
135  }
136 
139  return !(
140  currentNodeId == 1
141  || ((double)std::rand() / (double)RAND_MAX
142  < 0.9
143  + 0.01 * (float(_nbTotalVar_ - node2MinVar[currentNodeId]) / float(_nbTotalVar_))
145  }
146 
148  Idx randOut = 0;
149 
150  if (span != 0) {
151  auto generator = gum::getRandomGenerator();
152  std::weibull_distribution< double > distribution(double(span), 1.0);
153  randOut = (Idx)(distribution(generator) * span / 2);
154  if (randOut > span) randOut = span;
155  }
156 
157  return offset + randOut;
158  }
159 
160 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643