59 template < GUM_Numeric GUM_SCALAR >
60 template <
typename T >
62 for (std::size_t i = v.size(); i > 1; --i)
70 template < GUM_Numeric GUM_SCALAR >
83 template < GUM_Numeric GUM_SCALAR >
92 template < GUM_Numeric GUM_SCALAR >
94 if (density < 0.0 || density > 1.0)
100 template < GUM_Numeric GUM_SCALAR >
104 if (maxModality < minModality)
111 template < GUM_Numeric GUM_SCALAR >
117 template < GUM_Numeric GUM_SCALAR >
123 template < GUM_Numeric GUM_SCALAR >
129 template < GUM_Numeric GUM_SCALAR >
132 const std::string& atemporal) {
133 if (temporal.empty() || atemporal.empty())
135 if (temporal == atemporal)
146 template < GUM_Numeric GUM_SCALAR >
151 template < GUM_Numeric GUM_SCALAR >
155 const Size atemporalPairs = (m >= 2) ? m * (m - 1) / 2 : 0;
156 const Size atemporalToAll = m * n *
k;
157 const Size slicePairs = (
k >= 2) ?
k * (
k - 1) / 2 : 0;
158 const Size crossSlice = n * n * slicePairs;
159 const Size intraSlice = ((n >= 2) ? n * (n - 1) / 2 : 0) *
k;
160 return atemporalPairs + atemporalToAll + crossSlice + intraSlice;
167 template < GUM_Numeric GUM_SCALAR >
168 std::vector< typename KTBNGenerator< GUM_SCALAR >::_Arc_ >
170 const std::vector< std::string >& atemporal,
171 const std::vector< Size >& tRank,
172 const std::vector< Size >& aRank)
const {
173 const int k =
static_cast< int >(
_k_);
175 std::vector< _Arc_ > out;
179 for (std::size_t i = 0; i < atemporal.size(); ++i)
180 for (std::size_t j = 0; j < atemporal.size(); ++j)
181 if (aRank[i] < aRank[j]) out.push_back({atemporal[i], AT, atemporal[j], AT});
185 for (
const auto& a: atemporal)
186 for (
const auto& b: temporal)
187 for (
int s = 0; s <
k; ++s)
188 out.push_back({a, AT, b, s});
191 for (
int s1 = 0; s1 <
k; ++s1)
192 for (
int s2 = s1 + 1; s2 <
k; ++s2)
193 for (
const auto& b1: temporal)
194 for (
const auto& b2: temporal)
195 out.push_back({b1, s1, b2, s2});
198 for (
int s = 0; s <
k; ++s)
199 for (std::size_t i = 0; i < temporal.size(); ++i)
200 for (std::size_t j = 0; j < temporal.size(); ++j)
201 if (tRank[i] < tRank[j]) out.push_back({temporal[i], s, temporal[j], s});
206 template < GUM_Numeric GUM_SCALAR >
208 out = KTBN< GUM_SCALAR >(
_k_);
212 std::vector< std::string > temporal, atemporal;
219 temporal.push_back(name);
224 atemporal.push_back(name);
246 :
static_cast< Size >(std::llround(
_density_ *
double(legalCount)));
247 if (target > legalCount) target = legalCount;
258 out.addArc(tail, 0, head,
static_cast< int >(
_k_) - 1);
263 auto legal =
_legalArcs_(temporal, atemporal, tRank, aRank);
265 for (
const auto& a: legal) {
266 if (added >= target)
break;
267 if (out.existsArc(a.tailBase, a.tailSlice, a.headBase, a.headSlice))
continue;
269 &&
static_cast< Size >(out.parents(a.headBase, a.headSlice).size()) >=
_maxParents_)
271 out.addArc(a.tailBase, a.tailSlice, a.headBase, a.headSlice);
278 template < GUM_Numeric GUM_SCALAR >
280 KTBN< GUM_SCALAR > out(
_k_);
Random k-order dynamic Bayesian network generator.
Exception: at least one argument passed to a function is not what was expected.
Draws a random k-DBN template (structure and, optionally, CPTs).
KTBNGenerator< GUM_SCALAR > & setMaxParents(Size maxParents)
Caps the number of parents of any node, which bounds CPT size. 0 (default) means unlimited — a dense ...
KTBN< GUM_SCALAR > generate()
Same, returning the model by value.
KTBNGenerator(Size k, Size nbTemporal, Size nbAtemporal=0, Size maxArcs=0, Size maxModality=2)
Constructor.
std::string _atemporalPrefix_
KTBNGenerator< GUM_SCALAR > & setGenerateCPTs(bool on)
Whether to fill the CPTs with random values (default true). When false only the structure is drawn an...
void generateKTBN(KTBN< GUM_SCALAR > &out)
Fills out with a freshly drawn model (its previous content is discarded). Seed it with gum::initRando...
static void _shuffle_(std::vector< T > &v)
Fisher-Yates through gum::randomValue, so gum::initRandom() alone makes a whole generation reproducib...
KTBNGenerator< GUM_SCALAR > & setDensity(double density)
Fraction of the legal arc set to draw, in . Ignored when a non-zero maxArcs was given to the construc...
KTBNGenerator< GUM_SCALAR > & setDomainRange(Size minModality, Size maxModality)
Domain sizes are drawn uniformly in .
std::string _temporalPrefix_
std::vector< _Arc_ > _legalArcs_(const std::vector< std::string > &temporal, const std::vector< std::string > &atemporal, const std::vector< Size > &tRank, const std::vector< Size > &aRank) const
Every arc the k-DBN's rules allow, with the two cycle-prone families (lag 0, atemporal→atemporal) alr...
~KTBNGenerator()
Destructor.
KTBNGenerator< GUM_SCALAR > & setNamePrefixes(const std::string &temporal, const std::string &atemporal)
Name prefixes; variables are prefix0, prefix1, … Defaults are "X" (temporal) and "A" (atemporal).
KTBNGenerator< GUM_SCALAR > & setGuaranteeOrder(bool on)
Force one arc of lag into the kernel slice, so the model's effective order equals (see the class do...
static constexpr int ATEMPORAL
Conventional time-slice value denoting an atemporal (static) variable.
LabelizedVariable()
(protected) Default constructor
Exception : out of bound.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
GUM_SHARED_PUBLIC Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
Base class for labelized discrete random variables.
gum is the global namespace for all aGrUM entities