![]() |
aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
|
Draws a random k-DBN template (structure and, optionally, CPTs). More...
#include <agrum/KTBN/generator/KTBNGenerator.h>
Classes | |
| struct | _Arc_ |
| A (tail, head) endpoint pair, each as (base, slice). More... | |
Public Member Functions | |
Constructors / Destructor | |
| KTBNGenerator (Size k, Size nbTemporal, Size nbAtemporal=0, Size maxArcs=0, Size maxModality=2) | |
| Constructor. | |
| ~KTBNGenerator () | |
| Destructor. | |
Generation | |
| void | generateKTBN (KTBN< GUM_SCALAR > &out) |
Fills out with a freshly drawn model (its previous content is discarded). Seed it with gum::initRandom() for reproducibility. | |
| KTBN< GUM_SCALAR > | generate () |
| Same, returning the model by value. | |
Configuration (fluent) | |
| KTBNGenerator< GUM_SCALAR > & | setDensity (double density) |
Fraction of the legal arc set to draw, in \([0,1]\). Ignored when a non-zero maxArcs was given to the constructor. Default 0.1. | |
| KTBNGenerator< GUM_SCALAR > & | setDomainRange (Size minModality, Size maxModality) |
| Domain sizes are drawn uniformly in \([min, max]\). | |
| KTBNGenerator< GUM_SCALAR > & | setMaxParents (Size maxParents) |
| Caps the number of parents of any node, which bounds CPT size. 0 (default) means unlimited — a dense draw can then produce very large CPTs, so set it when generating dense or high-k models. | |
| KTBNGenerator< GUM_SCALAR > & | setGuaranteeOrder (bool on) |
Force one arc of lag \(k-1\) into the kernel slice, so the model's effective order equals \(k\) (see the class doc). Default true. No-op when \(k = 1\) or there is no temporal process. | |
| KTBNGenerator< GUM_SCALAR > & | setGenerateCPTs (bool on) |
Whether to fill the CPTs with random values (default true). When false only the structure is drawn and the CPTs stay at their default content. | |
| 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). | |
Accessors | |
| Size | k () const |
| Size | nbLegalArcs () const |
Private Member Functions | |
| 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) already restricted to the ranks given by tRank / aRank, so the result is acyclic by construction. | |
Static Private Member Functions | |
| template<typename T> | |
| static void | _shuffle_ (std::vector< T > &v) |
| Fisher-Yates through gum::randomValue, so gum::initRandom() alone makes a whole generation reproducible. | |
Private Attributes | |
| Size | _k_ |
| Size | _nbTemporal_ |
| Size | _nbAtemporal_ |
| Size | _maxArcs_ |
| Size | _minModality_ {2} |
| Size | _maxModality_ |
| Size | _maxParents_ {0} |
| double | _density_ {0.1} |
| bool | _guaranteeOrder_ {true} |
| bool | _generateCPTs_ {true} |
| std::string | _temporalPrefix_ {"X"} |
| std::string | _atemporalPrefix_ {"A"} |
Draws a random k-DBN template (structure and, optionally, CPTs).
Definition at line 114 of file KTBNGenerator.h.
|
explicit |
Constructor.
| k | Order of the generated k-DBN (number of template slices). Must be \(\geq 1\). |
| nbTemporal | Number of temporal processes. |
| nbAtemporal | Number of atemporal variables. |
| maxArcs | Hard cap on the number of arcs. 0 (default) means "derive it from the density" — see setDensity(). |
| maxModality | Largest domain size; domains are drawn uniformly in \([2, maxModality]\). Must be \(\geq 2\). |
| InvalidArgument | if k is 0 or maxModality is below 2. |
Definition at line 71 of file KTBNGenerator_tpl.h.
References KTBNGenerator(), _k_, _maxArcs_, _maxModality_, _nbAtemporal_, _nbTemporal_, GUM_ERROR, and k().
Referenced by KTBNGenerator(), ~KTBNGenerator(), setDensity(), setDomainRange(), setGenerateCPTs(), setGuaranteeOrder(), and setMaxParents().
| gum::KTBNGenerator< GUM_SCALAR >::~KTBNGenerator | ( | ) |
Destructor.
Definition at line 84 of file KTBNGenerator_tpl.h.
References KTBNGenerator().
|
private |
Every arc the k-DBN's rules allow, with the two cycle-prone families (lag 0, atemporal→atemporal) already restricted to the ranks given by tRank / aRank, so the result is acyclic by construction.
Definition at line 169 of file KTBNGenerator_tpl.h.
References _k_, gum::KTBN< GUM_SCALAR >::ATEMPORAL, k(), and nbLegalArcs().
Referenced by generateKTBN().
|
staticprivate |
Fisher-Yates through gum::randomValue, so gum::initRandom() alone makes a whole generation reproducible.
Definition at line 61 of file KTBNGenerator_tpl.h.
References gum::randomValue().
Referenced by generateKTBN().
| KTBN< GUM_SCALAR > gum::KTBNGenerator< GUM_SCALAR >::generate | ( | ) |
Same, returning the model by value.
Definition at line 279 of file KTBNGenerator_tpl.h.
References _k_, and generateKTBN().
| void gum::KTBNGenerator< GUM_SCALAR >::generateKTBN | ( | KTBN< GUM_SCALAR > & | out | ) |
Fills out with a freshly drawn model (its previous content is discarded). Seed it with gum::initRandom() for reproducibility.
Definition at line 207 of file KTBNGenerator_tpl.h.
References gum::LabelizedVariable::LabelizedVariable(), _atemporalPrefix_, _density_, _generateCPTs_, _guaranteeOrder_, _k_, _legalArcs_(), _maxArcs_, _maxModality_, _maxParents_, _minModality_, _nbAtemporal_, _nbTemporal_, _shuffle_(), _temporalPrefix_, nbLegalArcs(), and gum::randomValue().
Referenced by generate().
| Size gum::KTBNGenerator< GUM_SCALAR >::k | ( | ) | const |
Definition at line 147 of file KTBNGenerator_tpl.h.
References _k_.
Referenced by KTBNGenerator(), _legalArcs_(), and nbLegalArcs().
| Size gum::KTBNGenerator< GUM_SCALAR >::nbLegalArcs | ( | ) | const |
maxArcs is silently clamped to. Definition at line 152 of file KTBNGenerator_tpl.h.
References _k_, _nbAtemporal_, _nbTemporal_, and k().
Referenced by _legalArcs_(), and generateKTBN().
| KTBNGenerator< GUM_SCALAR > & gum::KTBNGenerator< GUM_SCALAR >::setDensity | ( | double | density | ) |
Fraction of the legal arc set to draw, in \([0,1]\). Ignored when a non-zero maxArcs was given to the constructor. Default 0.1.
| OutOfBounds | if density is outside \([0,1]\). |
Definition at line 93 of file KTBNGenerator_tpl.h.
References KTBNGenerator(), _density_, and GUM_ERROR.
| KTBNGenerator< GUM_SCALAR > & gum::KTBNGenerator< GUM_SCALAR >::setDomainRange | ( | Size | minModality, |
| Size | maxModality ) |
Domain sizes are drawn uniformly in \([min, max]\).
| InvalidArgument | if minModality < 2 or maxModality < minModality. |
Definition at line 101 of file KTBNGenerator_tpl.h.
References KTBNGenerator(), _maxModality_, _minModality_, and GUM_ERROR.
| KTBNGenerator< GUM_SCALAR > & gum::KTBNGenerator< GUM_SCALAR >::setGenerateCPTs | ( | bool | on | ) |
Whether to fill the CPTs with random values (default true). When false only the structure is drawn and the CPTs stay at their default content.
Definition at line 124 of file KTBNGenerator_tpl.h.
References KTBNGenerator(), and _generateCPTs_.
| KTBNGenerator< GUM_SCALAR > & gum::KTBNGenerator< GUM_SCALAR >::setGuaranteeOrder | ( | bool | on | ) |
Force one arc of lag \(k-1\) into the kernel slice, so the model's effective order equals \(k\) (see the class doc). Default true. No-op when \(k = 1\) or there is no temporal process.
Definition at line 118 of file KTBNGenerator_tpl.h.
References KTBNGenerator(), and _guaranteeOrder_.
| KTBNGenerator< GUM_SCALAR > & gum::KTBNGenerator< GUM_SCALAR >::setMaxParents | ( | Size | maxParents | ) |
Caps the number of parents of any node, which bounds CPT size. 0 (default) means unlimited — a dense draw can then produce very large CPTs, so set it when generating dense or high-k models.
Definition at line 112 of file KTBNGenerator_tpl.h.
References KTBNGenerator(), and _maxParents_.
| KTBNGenerator< GUM_SCALAR > & gum::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).
| InvalidArgument | if a prefix is empty or the two are equal. |
Definition at line 131 of file KTBNGenerator_tpl.h.
References _atemporalPrefix_, _temporalPrefix_, and GUM_ERROR.
|
private |
Definition at line 228 of file KTBNGenerator.h.
Referenced by generateKTBN(), and setNamePrefixes().
|
private |
Definition at line 223 of file KTBNGenerator.h.
Referenced by generateKTBN(), and setDensity().
|
private |
Definition at line 225 of file KTBNGenerator.h.
Referenced by generateKTBN(), and setGenerateCPTs().
|
private |
Definition at line 224 of file KTBNGenerator.h.
Referenced by generateKTBN(), and setGuaranteeOrder().
|
private |
Definition at line 216 of file KTBNGenerator.h.
Referenced by KTBNGenerator(), _legalArcs_(), generate(), generateKTBN(), k(), and nbLegalArcs().
|
private |
Definition at line 219 of file KTBNGenerator.h.
Referenced by KTBNGenerator(), and generateKTBN().
|
private |
Definition at line 221 of file KTBNGenerator.h.
Referenced by KTBNGenerator(), generateKTBN(), and setDomainRange().
|
private |
Definition at line 222 of file KTBNGenerator.h.
Referenced by generateKTBN(), and setMaxParents().
|
private |
Definition at line 220 of file KTBNGenerator.h.
Referenced by generateKTBN(), and setDomainRange().
|
private |
Definition at line 218 of file KTBNGenerator.h.
Referenced by KTBNGenerator(), generateKTBN(), and nbLegalArcs().
|
private |
Definition at line 217 of file KTBNGenerator.h.
Referenced by KTBNGenerator(), generateKTBN(), and nbLegalArcs().
|
private |
Definition at line 227 of file KTBNGenerator.h.
Referenced by generateKTBN(), and setNamePrefixes().