80#ifndef GUM_KTBN_DATABASE_GENERATOR_H
81#define GUM_KTBN_DATABASE_GENERATOR_H
91#include <unordered_set>
107 template < GUM_Numeric GUM_SCALAR >
114 enum class VarOrderMode :
char { RANDOM, TOPOLOGICAL, ANTI_TOPOLOGICAL };
159 std::string_view dirPath,
160 std::string_view csvBaseName,
162 bool useLabels =
true,
163 std::string csvSeparator =
",");
178 std::vector< double >
drawSamples(
const std::vector< Size >& nbTimeSlices,
179 std::string_view dirPath,
180 std::string_view csvBaseName,
182 bool useLabels =
true,
183 std::string csvSeparator =
",");
211 const Tensor< GUM_SCALAR >*
cpt;
231 std::vector< const DiscreteVariable* >
_vars_;
252 static std::pair< std::string, int >
253 _decode_(
const std::string& name,
const std::unordered_set< std::string >& temporalSet);
259 void _build_(
const KTBN< GUM_SCALAR >& kdbn);
266 const Tensor< GUM_SCALAR >& cpt,
267 double& log2likelihood);
279 const std::vector< Idx >& traj,
282 const std::string& csvSeparator,
283 const std::vector< Idx >& colOrder)
const;
302 const std::vector< Size >* perTraj,
303 std::string_view dirPath,
304 std::string_view csvBaseName,
307 const std::string& csvSeparator);
317#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
Implementation of the KTBNDatabaseGenerator class.
Class representing k-order dynamic Bayesian networks (k-DBN).
Base class for discrete random variable.
Class for assigning/browsing values to tuples of discrete variables.
Notification for progress using listener.
Generates a database of trajectories from a k-DBN (one CSV per trajectory).
Idx _drawVar_(const DiscreteVariable &var, const Tensor< GUM_SCALAR > &cpt, double &log2likelihood)
inverse-CDF draw of var given the parents already set in inst; accumulates log2(P(drawn value)) into ...
Size _k_
the order of the k-DBN
Size _nbVars_
number of base variable columns
std::vector< const DiscreteVariable * > _vars_
one representative variable per base column (same order as baseCols), pointing into template so it ou...
KTBNDatabaseGenerator(const KTBNDatabaseGenerator &)=delete
void setVarOrderAntiTopological(std::vector< Idx > &colOrder) const
builds the reverse of setVarOrderTopological()
void setVarOrderTopological(std::vector< Idx > &colOrder) const
builds a topological column order (transition-kernel projection)
void setDiscretizedLabelModeInterval()
set discretized-label rendering to the interval label "[min,max["
std::vector< std::string > _baseCols_
col index -> base name (canonical column numbering)
static std::pair< std::string, int > _decode_(const std::string &name, const std::unordered_set< std::string > &temporalSet)
decodes a template node name into (base, slice): "B[t]" with B a known temporal process -> (B,...
void _writeTrajectory_(std::string_view csvFileURL, const std::vector< Idx > &traj, Size nbTimeSlices, bool useLabels, const std::string &csvSeparator, const std::vector< Idx > &colOrder) const
writes one trajectory CSV (header + T rows) to csvFileURL. traj is the flat row-major buffer (T x nbV...
KTBNDatabaseGenerator & operator=(KTBNDatabaseGenerator &&)=delete
void setDiscretizedLabelModeRandom()
set discretized-label rendering to a uniform random draw in the interval (this is the default; each l...
KTBNDatabaseGenerator & operator=(const KTBNDatabaseGenerator &)=delete
std::vector< Idx > _kernel_
indices, in nodes, of the slice-(k-1) nodes (the transition kernel, drives Phase 2); already in topol...
std::vector< NodeRef > _nodes_
all template nodes in topological order (drives Phase 1, the bootstrap)
void setDiscretizedLabelModeMedian()
set discretized-label rendering to the (deterministic) interval median
std::vector< double > _drawSamples_(Size nbSamples, Size fixedLen, const std::vector< Size > *perTraj, std::string_view dirPath, std::string_view csvBaseName, VarOrderMode mode, bool useLabels, const std::string &csvSeparator)
the single worker behind both drawSamples() overloads. Trajectory i's horizon is read from perTraj (w...
KTBNDatabaseGenerator(KTBNDatabaseGenerator &&)=delete
DiscretizedLabelMode
rendering of discretized variables when labels are requested
void _build_(const KTBN< GUM_SCALAR > &kdbn)
one-shot initialisation called by the constructor: fills the column index (baseCols,...
Instantiation _inst_
a shared instantiation over all template variables, so we don't have to rebuild it for every draw
KTBNDatabaseGenerator(const KTBN< GUM_SCALAR > &kdbn)
Constructor.
std::string _label_(Idx col, Idx idx) const
renders the label of modality idx of base column col (taking the discretized-label mode into account)
BayesNet< GUM_SCALAR > _template_
the -slice template (a small copy, independent of the horizon)
VarOrderMode
column order used for the exported CSV
void setVarOrderRandomized(std::vector< Idx > &colOrder) const
builds a uniformly random column order
Size nbVars() const
returns the number of base variable columns
DiscretizedLabelMode _discretizedLabelMode_
rendering of discretized variables when labels are requested
std::vector< double > drawSamples(Size nbSamples, Size nbTimeSlices, std::string_view dirPath, std::string_view csvBaseName, VarOrderMode mode=VarOrderMode::RANDOM, bool useLabels=true, std::string csvSeparator=",")
Generates nbSamples independent trajectories, writing one CSV file per trajectory into dirPath.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
include the inlined functions if necessary
template class GUM_PUBLIC_KTBN KTBNDatabaseGenerator< double >
gum is the global namespace for all aGrUM entities
priority queues (in which an element cannot appear more than once)
a template node, precompiled for fast sampling
Idx col
its base column index in baseCols
int slice
its template slice (ATEMPORAL if static)
const DiscreteVariable * var
the node variable (in template)
std::vector< ParentRef > parents
its parents (drives sampling and topology)
const Tensor< GUM_SCALAR > * cpt
its CPT (in template)
a parent of a template node, precompiled for fast sampling
bool isAtemporal
whether the parent is atemporal
const DiscreteVariable * var
the parent variable (in template)
Idx col
its base column index in baseCols
int lag
time steps back: parentTime = nodeTime - lag