![]() |
aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
|
Learns a k-TBN (order k + structure + parameters) from trajectory CSVs. More...
#include <agrum/KTBN/learning/KTBNAdaptiveLearner.h>
Public Member Functions | |
Constructors / Destructors | |
| KTBNAdaptiveLearner (std::string_view dirPath, std::string_view csvBaseName, Size nbSamples, Size kMax, const std::unordered_set< std::string > &atemporalVars, const std::vector< std::string > &missingSymbols={"?"}, bool induceTypes=true) | |
| Constructor — the candidate orders are kMin..kMax. | |
| KTBNAdaptiveLearner (std::string_view dirPath, std::string_view csvBaseName, Size nbSamples, Size kMax, const std::vector< std::string > &missingSymbols={"?"}, bool induceTypes=true) | |
| Structure-learning constructor — atemporal variables inferred from the CSVs. | |
| KTBNAdaptiveLearner (std::string_view dirPath, std::string_view csvBaseName, Size nbSamples, Size kMax, const BayesNet< GUM_SCALAR > &bn, const std::unordered_set< std::string > &atemporalVars={}, const std::vector< std::string > &missingSymbols={"?"}) | |
| Variable-schema constructor — types and domains supplied via a BN. | |
| ~KTBNAdaptiveLearner () | |
| Constructor — the candidate orders are kMin..kMax. | |
Main learning methods | |
| KTBN< GUM_SCALAR > | learnKTBN () override |
| Learns the best k in [kMin, kMax] together with the structure and the CPTs: one KTBNLearner is built and run per candidate k, the recorded configuration is replayed on each, and the k-TBN with the best model-selection score is returned. kMin starts at 2 and is raised by the structural-constraint setters (see class doc). | |
| Size | bestK () const |
| Order k selected by the last learnKTBN() call. | |
| const std::vector< std::pair< Size, double > > & | scorePerCandidateK () const |
| Per-candidate cross-k scores from the last learnKTBN() call, as (k, score) pairs for k = kMin..kMax in ascending k order — the values the order selection compared to choose bestK() (higher is better; the argmax is bestK()). Under the default useOrderScoreBIC() each score is \(\log_2 L - \tfrac{1}{2}\,d\,\log_2 N\) of the k-TBN learned for that k. | |
| const std::vector< std::pair< std::string, std::string > > & | latentVariables () const |
| Engine-name (tail, head) pairs of arcs the selected model's MIIC run flagged as hiding a latent variable. Empty when the recorded algorithm is not MIIC (only MIIC produces latent-variable annotations) or when none were found. | |
Missing values | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | ignoreMissingSymbols (bool ignore=true) |
| Learn and score on the fully observed data only, dropping every row and every scoring instance that carries a missing symbol. | |
| bool | isIgnoringMissingSymbols () const |
| Whether incomplete rows and instances are dropped. False by default. | |
Diagnostics | |
| Size | kMax () const |
| Largest order explored (the kMax argument of the constructor). | |
| std::string | checkScorePriorCompatibility () const |
| Warning string if the recorded score and prior are incompatible, empty otherwise. Data-free: it evaluates the recorded (score, prior) pair exactly as KTBNLearner/BNLearner would, so an incompatible combination can be caught before learnKTBN() reads any trajectory. | |
| std::string | toString () const |
| Human-readable summary of the recorded configuration (candidate order range, algorithm / score / correction / prior, structural constraints) plus the selected k once learnKTBN() has run. | |
| std::vector< std::tuple< std::string, std::string, std::string > > | state () const |
| The recorded configuration as (key, value, comment) tuples (mirrors KTBNLearner::state()); toString() is a formatted view of it. | |
Score selection (recorded, replayed on each candidate k) | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useScoreAIC () override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useScoreBD () override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useScoreBDeu () override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useScoreBIC () override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useScoreLog2Likelihood () override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useScoreMDL () override |
| void | useScorefNML () override |
Algorithm selection (recorded, replayed on each candidate k) | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useGreedyHillClimbing () override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useExtendedGreedyHillClimbing () override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useLocalSearchWithTabuList (Size tabu_size=100, Size nb_decrease=2) override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useMIIC () override |
MIIC correction (recorded, replayed on each candidate k) | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useNMLCorrection () override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useMDLCorrection () override |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useNoCorrection () override |
Prior selection (recorded, replayed on each candidate k) | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useSmoothingPrior (double weight=1.0) override |
Structural constraints (recorded, replayed on each candidate k) | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addForbiddenArc (std::string_view tailNode, std::string_view headNode) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addForbiddenArc (std::string_view tailBase, int tailSlice, std::string_view headBase, int headSlice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseForbiddenArc (std::string_view tailNode, std::string_view headNode) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseForbiddenArc (std::string_view tailBase, int tailSlice, std::string_view headBase, int headSlice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addMandatoryArc (std::string_view tailNode, std::string_view headNode) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addMandatoryArc (std::string_view tailBase, int tailSlice, std::string_view headBase, int headSlice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseMandatoryArc (std::string_view tailNode, std::string_view headNode) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseMandatoryArc (std::string_view tailBase, int tailSlice, std::string_view headBase, int headSlice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addForbiddenKernelArc (std::string_view tailBase, int lag, std::string_view headBase) |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseForbiddenKernelArc (std::string_view tailBase, int lag, std::string_view headBase) |
| Undo a previous addForbiddenKernelArc (same (tailBase, lag, headBase) triple). | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addMandatoryKernelArc (std::string_view tailBase, int lag, std::string_view headBase) |
Force an arc from tailBase, lag slices before the kernel, to headBase in the kernel. See addForbiddenKernelArc for the (base, slice) vs. kernel-relative distinction; the validity constraints (lag range, temporal bases, kMin effect) are the same. Always temporally feasible by construction (lag >= 0 guarantees headSlice = k-1 >= k-1-lag = tailSlice), so unlike the plain addMandatoryArc there is no separate feasibility check to run. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseMandatoryKernelArc (std::string_view tailBase, int lag, std::string_view headBase) |
| Undo a previous addMandatoryKernelArc (same (tailBase, lag, headBase) triple). | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addForbiddenIntraSliceArc (std::string_view tailBase, std::string_view headBase) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseForbiddenIntraSliceArc (std::string_view tailBase, std::string_view headBase) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addForbiddenArcAllSlices (std::string_view tailBase, std::string_view headBase) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseForbiddenArcAllSlices (std::string_view tailBase, std::string_view headBase) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addNoParentNode (std::string_view base, int slice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addNoParentNode (std::string_view name) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseNoParentNode (std::string_view base, int slice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseNoParentNode (std::string_view name) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addNoChildrenNode (std::string_view base, int slice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addNoChildrenNode (std::string_view name) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseNoChildrenNode (std::string_view base, int slice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | eraseNoChildrenNode (std::string_view name) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addPossibleEdge (std::string_view tailBase, int tailSlice, std::string_view headBase, int headSlice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | addPossibleEdge (std::string_view tail, std::string_view head) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | erasePossibleEdge (std::string_view tailBase, int tailSlice, std::string_view headBase, int headSlice) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | erasePossibleEdge (std::string_view tail, std::string_view head) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | allowArcAdditions (bool allow=true) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | allowArcDeletions (bool allow=true) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | allowArcReversals (bool allow=true) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | setMaxIndegree (Size max_indegree) override |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag. | |
Private Member Functions | |
| const std::unordered_set< std::string > & | _atemporalVarNames_ () const override |
| atemporal base names for IKTBNLearner's shared encode/_determineNode_; the set recorded at construction. | |
| bool | _isKnownBase_ (std::string_view base) const override |
whether base is one of this learner's variables; the base names read at construction, from the CSV header or the schema BN. | |
| void | _verifyBase_ (std::string_view base, int slice) const |
Throw InvalidArgument unless base is a known base variable and slice is valid for it: base must be in baseNames; an atemporal base requires slice == KTBN::ATEMPORAL, a temporal one requires slice in [0, kMax). Used by the constraint setters to reject unknown names / out-of-range slices eagerly. | |
| void | _verifyKernelArc_ (std::string_view tailBase, std::string_view headBase, int lag) const |
Throw InvalidArgument unless tailBase and headBase are known, temporal base variables (a kernel-relative arc has no meaning for an atemporal one: it has no kernel-slice instance) and lag is in [0, kMax) — so some candidate k in [2,kMax] can place tailBase at slice k-1-lag >= 0 and headBase at the kernel slice k-1. Used by the four kernel-arc setters (add/eraseForbiddenKernelArc, add/eraseMandatoryKernelArc) to reject bad calls eagerly. | |
| void | _raiseKMinForSlice_ (int slice) |
Raise kMin, if needed, so that kMin > slice: a smaller candidate would silently drop a constraint naming that slice (the "slice < k" rule applyConstraints's fits() filter uses). O(1), since adding a constraint can only push kMin up. No-op for KTBN::ATEMPORAL. | |
| void | _recomputeKMin_ () |
| Recompute kMin from scratch: max(2, 1 + the largest concrete slice named by any recorded forbidden/mandatory arc, possible edge, or no-parent/no-children node (the kinds fits() can drop). Intra-slice / all-slices constraints carry no slice and are excluded. Unlike raiseKMinForSlice, an erase can lower kMin with no O(1) way to tell, so every erase* setter runs this full rescan instead. | |
| void | _applyConfig_ (KTBNLearner< GUM_SCALAR > &learner) const |
Apply the recorded score / algorithm / correction / prior onto a freshly-built learner. Only knobs that differ from their default are touched, and only those the chosen algorithm actually consumes (a score-based algo takes a score; MIIC takes a correction) — so an unconfigured learner is left at its defaults and no irrelevant setting can trip checkScorePriorCompatibility(). | |
| void | _applyConstraints_ (KTBNLearner< GUM_SCALAR > &learner, Size k) const |
Replay the recorded structural constraints onto learner (built for order k). Engine-name constraints whose slice does not fit k (slice >= k) are skipped for this candidate; the base-only intra-slice / all-slices constraints are handed to learner, which expands them for its own k. The allow-* flags and max-indegree are applied when non-default. | |
| template<typename PerInstance, typename PerNodeFinal> | |
| void | _forEachScoredNode_ (const KTBN< GUM_SCALAR > &net, PerInstance perInstance, PerNodeFinal perNodeFinal) const |
Stream every scored template-node instance of net over the recorded trajectories, driving both the likelihood and the fNML penalty off one data walk, so the width-k window logic lives in one place. | |
| double | _log2Likelihood_ (const KTBN< GUM_SCALAR > &net) const |
Factorized log2-likelihood of net over the recorded trajectories, comparable across candidate k (the raw score types are not: their flattened tables differ from one k to another). The data is complete, so this is a closed-form sum of CPT lookups — no inference. A thin reduction over forEachScoredNode that sums log2 of the CPT entry over every visited node instance. | |
| double | _countParameters_ (const KTBN< GUM_SCALAR > &net) const |
Number of free parameters of net's template: summed over every template node (all initial slices, the kernel slice and the atemporal nodes), \((|X|-1)\prod_{P\in pa(X)}|P|\). This is the model-complexity term of the cross-k BIC and AIC scores used by learnKTBN(): it grows with \(k\) (a higher order adds initial-slice CPTs and can widen the kernel), which is what offsets the monotonic likelihood gain and prevents always picking the largest \(k\). | |
| double | _fNMLScore_ (const KTBN< GUM_SCALAR > &net) const |
fNML order score of net over the recorded trajectories: \(\log_2 L - \sum_i \sum_j \log_2 C^{r_i}_{N_{ij}}\), with \(r_i\) the node's domain size and \(N_{ij}\) the count for parent configuration \(j\). Unlike BIC/AIC the penalty is data-dependent, so the regret needs the same per-instance walk as the likelihood — both are accumulated in one forEachScoredNode pass. Mirrors aGrUM's ScorefNML. | |
| double | _orderSelectionScore_ (const KTBN< GUM_SCALAR > &net, double logN) const |
The cross-k order-selection score of net under the recorded orderScore criterion, given logN = log2 of the sample size. The single dispatch point learnKTBN() uses to compare candidates; add a branch here for each new OrderScoreType. | |
| KTBNAdaptiveLearner (const KTBNAdaptiveLearner< GUM_SCALAR > &)=delete | |
| KTBNAdaptiveLearner (KTBNAdaptiveLearner< GUM_SCALAR > &&)=delete | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | operator= (const KTBNAdaptiveLearner< GUM_SCALAR > &)=delete |
| KTBNAdaptiveLearner< GUM_SCALAR > & | operator= (KTBNAdaptiveLearner< GUM_SCALAR > &&)=delete |
Static Private Member Functions | |
| static std::unordered_set< std::string > | _inferAtemporalVars_ (std::string_view dirPath, std::string_view csvBaseName, Size nbSamples, Size kMax, const std::vector< std::string > &missingSymbols) |
checks kMax >= 2 and nbSamples >= 1, then delegates to the shared IKTBNLearner::scanConstantColumns(). Called from the atemporal-inferring constructor's member-initialiser list, before this object exists, so the checks live here rather than in the body — otherwise a bad argument would only surface after a wasted scan. | |
Private Attributes | |
| std::string | _dirPath_ |
| directory holding the trajectory CSV files | |
| std::string | _csvBaseName_ |
| stem of each trajectory file name | |
| Size | _nbSamples_ |
| number of CSV files to read | |
| Size | _kMax_ |
| largest order to explore (candidates are kMin..kMax) | |
| Size | _kMin_ {2} |
| smallest order worth exploring (candidates are kMin..kMax). Starts at 2 and is recomputed by recomputeKMin() from the recorded slice-bearing constraints every time one is added or erased; never set directly. See recomputeKMin() for why it must be a recompute rather than an incremental raise/lower. | |
| std::unordered_set< std::string > | _atemporalVars_ |
| base names of the atemporal (static) variables | |
| std::unordered_set< std::string > | _baseNames_ |
| all base variable names (temporal + atemporal), read from the first trajectory CSV header at construction. Authoritative universe used by the constraint setters to reject names that do not exist. | |
| std::vector< std::string > | _missingSymbols_ |
| symbols in the CSVs to interpret as missing values | |
| bool | _ignoreMissingSymbols_ {false} |
| whether incomplete rows/instances are dropped (see ignoreMissingSymbols()) | |
| bool | _induceTypes_ |
| whether numeric columns are retyped (see KTBNLearner); unused (and forced false) when a schema BN is supplied | |
| std::unique_ptr< BayesNet< GUM_SCALAR > > | _prior_bn_ |
| optional variable-schema BN (set by the BN constructor): when present, each per-k KTBNLearner is built from it so the variable domains are fixed explicitly instead of inferred from trajectory 1. Null in CSV mode. | |
| IBNLearner::ScoreType | _score_ {IBNLearner::ScoreType::BDeu} |
| recorded per-k structure score (the inner score, replayed on each candidate) | |
| OrderScoreType | _orderScore_ {OrderScoreType::BIC} |
| recorded cross-k order-selection criterion (the outer score used by learnKTBN() to pick the best k; independent of score) | |
| IBNLearner::AlgoType | _algo_ {IBNLearner::AlgoType::MIIC} |
| recorded structure-learning algorithm | |
| Size | _tabuSize_ {100} |
| tabu-list parameters (meaningful when algo is LOCAL_SEARCH_WITH_TABU_LIST) | |
| Size | _nbDecrease_ {2} |
| CorrectedMutualInformation::KModeTypes | _correction_ |
| recorded MIIC correction | |
| IBNLearner::BNLearnerPriorType | _prior_ {IBNLearner::BNLearnerPriorType::NO_prior} |
| recorded prior and its weight | |
| double | _priorWeight_ {1.0} |
| bool | _allowAdditions_ {true} |
| recorded graph-change permissions / indegree cap | |
| bool | _allowDeletions_ {true} |
| bool | _allowReversals_ {true} |
| Size | _maxIndegree_ {std::numeric_limits< Size >::max()} |
| std::set< std::pair< std::string, std::string > > | _forbiddenArcs_ |
| forbidden arcs, as (tail, head) engine-name pairs | |
| std::set< std::pair< std::string, std::string > > | _mandatoryArcs_ |
| mandatory arcs, as (tail, head) engine-name pairs | |
| std::set< std::pair< std::string, std::string > > | _possibleEdges_ |
| MIIC candidate edges, as (tail, head) engine-name pairs. | |
| std::set< std::pair< std::string, std::string > > | _forbiddenIntraSliceArcs_ |
| forbidden intra-slice arcs, as (tailBase, headBase) pairs | |
| std::set< std::pair< std::string, std::string > > | _forbiddenArcsAllSlices_ |
| forbidden all-slices arcs, as (tailBase, headBase) pairs | |
| std::set< std::tuple< std::string, std::string, int > > | _forbiddenKernelArcs_ |
| forbidden kernel-relative arcs, as (tailBase, headBase, lag) triples: tailBase at slice k-1-lag -> headBase at the kernel slice k-1. Kept separate from forbiddenArcs (which stores resolved engine names) since the slice here is only known once a candidate k is fixed. | |
| std::set< std::tuple< std::string, std::string, int > > | _mandatoryKernelArcs_ |
| mandatory kernel-relative arcs, same shape as forbiddenKernelArcs | |
| std::set< std::string > | _noParentNodes_ |
| root nodes (no parents), as engine names | |
| std::set< std::string > | _noChildrenNodes_ |
| leaf nodes (no children), as engine names | |
| Size | _bestK_ {0} |
| k selected by the last learnKTBN() call, or 0 as a sentinel while no learning has happened yet. 0 can never be a valid order (candidates are 2..kMax), so bestK() reads it to decide whether learnKTBN() has run. | |
| std::vector< std::pair< std::string, std::string > > | _bestLatentVariables_ |
| latent-variable arcs (engine-name pairs) reported by the winning candidate's MIIC run, captured by learnKTBN(); empty when the selected algorithm is not MIIC. Exposed by latentVariables(). | |
| std::vector< std::pair< Size, double > > | _scorePerCandidateK_ |
| per-candidate (k, order-score) pairs from the last learnKTBN() run, in ascending k. One entry appended per candidate; read by scorePerCandidateK(). Cleared at the start of each learnKTBN() (empty while bestK == 0). | |
| VariableLog2ParamComplexity | _ctable_ |
| cache of log2 of the multinomial parametric complexity C^r_n, used by the fNML order penalty. Mutable because log2Cnr() memoizes; the const order-score helpers may therefore call it. Only touched under fNML. | |
Order selection (cross-k model selection) | |
| enum class | OrderScoreType { BIC , AIC , fNML } |
| The criterion learnKTBN() uses to pick the best \(k\) among the candidates — the outer score, distinct from the per-k structure score set by useScoreX(). Only criteria that are comparable across \(k\) belong here (raw score types are not). Extended as more are added. More... | |
| log_2 | C {r_i}_{N_{ij}}@f$ |
| Select k by fNML (factorized Normalized Maximum Likelihood): keep the k whose learned model maximises . | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useOrderScoreBIC () |
| Select k by BIC (the default): keep the k whose learned model maximises \(\log_2 L - \tfrac{1}{2}\,d\,\log_2 N\). | |
| KTBNAdaptiveLearner< GUM_SCALAR > & | useOrderScoreAIC () |
| Select k by AIC: keep the k whose learned model maximises \(\log_2 L - d\) (a lighter, sample-size-independent complexity penalty than BIC). | |
| log_2 where the penalty replaces BIC s KTBNAdaptiveLearner< GUM_SCALAR > & | useOrderScorefNML () |
| \(\tfrac{1}{2}\,d\,\log_2 N\) by a sum of per-node, per-parent-configuration multinomial parametric complexities (regret) – data-dependent, unlike BIC/AIC, matching aGrUM's ScorefNML. | |
Name encoding: (base, slice) <-> engine name | |
| std::string | _encode_ (std::string_view base, int slice) const |
| (base, slice) -> engine name ("A[1]" / atemporal engine name). Pure function, shared by every learner. | |
| std::pair< std::string, int > | _determineNode_ (const std::string &name) const |
| engine name -> (base, slice); atemporal names map to KTBN::ATEMPORAL. Shared by every learner; only the atemporal test varies (via atemporalVarNames()). | |
| void | _checkArcTemporallyFeasible_ (std::string_view tail, std::string_view head, std::string_view action) const |
Reject an arc the k-TBN definition can never contain, so eraseForbiddenArc and addMandatoryArc both fail early (before any internal learner is touched) with a uniform message. action is the verb phrase completing "cannot <action> <tail> -> <head>: ..." (e.g. "force the mandatory arc", "un-forbid the arc"). Two arcs are refused: a temporal -> atemporal arc (a time-varying variable can never parent a static one) and a backward-in-time arc (head strictly before tail). | |
| void | _checkBaseIsTemporal_ (std::string_view base, std::string_view context) const |
Throw InvalidArgument unless base is a known temporal base. context completes "cannot appear in <context>" (e.g. "an
intra-slice constraint", "a kernel-relative arc"): every caller rejects an atemporal base for the same underlying reason – it has no per-slice instance – so they share the sentence and vary the setting. | |
| static void | _checkMinimalOrder_ (Size order, std::string_view label) |
Throw InvalidArgument unless order is at least 2, label naming the offending parameter ("k" for the fixed-k learner, "kMax" for the adaptive one). | |
| static std::unordered_set< std::string > | _scanConstantColumns_ (std::string_view dirPath, std::string_view csvBaseName, Size nbSamples, const std::vector< std::string > &missingSymbols) |
| Scans every trajectory and returns the base names classified atemporal: those whose value never changes across the rows of a single trajectory (checked independently per trajectory, so the value may still differ between trajectories). Shared by every atemporal-inferring CSV constructor (KTBNLearner, KTBNAdaptiveLearner): identical scanning logic regardless of which subclass calls it, so duplicating it per subclass would only invite the two copies to drift. Callers are responsible for validating their own arguments (e.g. k/kMax >= 2) before calling this — it does no such check itself, only opens files, so a bad argument would otherwise only be caught after a wasted scan. | |
Learns a k-TBN (order k + structure + parameters) from trajectory CSVs.
Definition at line 104 of file KTBNAdaptiveLearner.h.
|
strong |
The criterion learnKTBN() uses to pick the best \(k\) among the candidates — the outer score, distinct from the per-k structure score set by useScoreX(). Only criteria that are comparable across \(k\) belong here (raw score types are not). Extended as more are added.
| Enumerator | |
|---|---|
| BIC | |
| AIC | |
| fNML | |
Definition at line 266 of file KTBNAdaptiveLearner.h.
| gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::KTBNAdaptiveLearner | ( | std::string_view | dirPath, |
| std::string_view | csvBaseName, | ||
| Size | nbSamples, | ||
| Size | kMax, | ||
| const std::unordered_set< std::string > & | atemporalVars, | ||
| const std::vector< std::string > & | missingSymbols = {"?"}, | ||
| bool | induceTypes = true ) |
Constructor — the candidate orders are kMin..kMax.
Mirrors the CSV constructor of gum::learning::KTBNLearner, except that no single order k is given: the learner explores every \(k \in [k_{min}, kMax]\) at learn time. \(k_{min}\) starts at 2 (k = 1 is a static BN; use BNLearner) and is raised by the structural-constraint setters — see the class doc.
| dirPath | Directory holding the trajectory CSV files. |
| csvBaseName | Stem of each file name (1-based index and .csv appended, e.g. "traj" -> "traj1.csv", "traj2.csv", ...). |
| nbSamples | Number of CSV files to read. |
| kMax | Largest order to explore. Must be \(\geq 2\). |
| atemporalVars | Base names of the atemporal (static) variables. Pass an empty set for "every variable is temporal"; it has no default, since omitting it selects the inferring overload below. |
| missingSymbols | Symbols in the CSVs to interpret as missing values. |
| induceTypes | When true (default), columns whose values are all numeric are retyped (integer/range/continuous) instead of being treated as plain labels — same semantics as KTBNLearner. |
std::unordered_set<std::string>{"C","D"} — or pass a named variable. Definition at line 78 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _atemporalVars_, _baseNames_, gum::learning::IKTBNLearner< GUM_SCALAR >::_checkMinimalOrder_(), _csvBaseName_, _dirPath_, _induceTypes_, _kMax_, _missingSymbols_, _nbSamples_, gum::learning::CSVParser::current(), GUM_ERROR, kMax(), and gum::learning::CSVParser::next().
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), ~KTBNAdaptiveLearner(), operator=(), operator=(), useGreedyHillClimbing(), useMDLCorrection(), useMIIC(), useNMLCorrection(), useNoCorrection(), useOrderScoreAIC(), useOrderScoreBIC(), useOrderScorefNML(), useScoreAIC(), useScoreBD(), useScoreBDeu(), useScoreBIC(), useScoreLog2Likelihood(), and useScoreMDL().
| gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::KTBNAdaptiveLearner | ( | std::string_view | dirPath, |
| std::string_view | csvBaseName, | ||
| Size | nbSamples, | ||
| Size | kMax, | ||
| const std::vector< std::string > & | missingSymbols = {"?"}, | ||
| bool | induceTypes = true ) |
Structure-learning constructor — atemporal variables inferred from the CSVs.
Same as the explicit-atemporalVars constructor, except a base variable is classified atemporal iff its value never changes within a single trajectory (it may still differ between trajectories, e.g. a per-individual covariate such as age). A column with too few non-missing values to ever witness a change is classified atemporal optimistically.
This is a heuristic: a genuinely temporal variable that happens to hold one value throughout every sampled trajectory (short horizon, near-deterministic process) will be misclassified. Prefer the explicit-atemporalVars constructor when the classification is already known.
| dirPath | Directory holding the trajectory CSV files. |
| csvBaseName | Stem of each file name (1-based index and .csv appended, e.g. "traj" -> "traj1.csv", "traj2.csv", ...). |
| nbSamples | Number of CSV files to read. |
| kMax | Largest order to explore. Must be \(\geq 2\). |
| missingSymbols | Symbols in the CSVs to interpret as missing values. |
| induceTypes | When true (default), columns whose values are all numeric are retyped (integer/range/continuous) instead of being treated as plain labels. |
Definition at line 118 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _inferAtemporalVars_(), and kMax().
| gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::KTBNAdaptiveLearner | ( | std::string_view | dirPath, |
| std::string_view | csvBaseName, | ||
| Size | nbSamples, | ||
| Size | kMax, | ||
| const BayesNet< GUM_SCALAR > & | bn, | ||
| const std::unordered_set< std::string > & | atemporalVars = {}, | ||
| const std::vector< std::string > & | missingSymbols = {"?"} ) |
Variable-schema constructor — types and domains supplied via a BN.
The adaptive counterpart of gum::learning::KTBNLearner's BN constructor. Use it when a variable's full domain is not guaranteed to appear in the first trajectory — most notably atemporal variables, which are constant within a trajectory and so only ever reveal one value per file, and the CSV constructor would then infer an incomplete domain and later throw gum::UnknownLabelInDatabase. Each per-k KTBNLearner is built from bn so every variable's type and domain is fixed up front; induceTypes and the trajectory-1 domain inference are bypassed entirely.
| dirPath | Directory holding the trajectory CSV files. |
| csvBaseName | Stem of each file name (index and .csv appended). |
| nbSamples | Number of CSV files to read. |
| kMax | Largest order to explore. Must be \(\geq 2\). |
| bn | A BayesNet with one node per base variable providing the variable types and domains. Arcs in bn are ignored. |
| atemporalVars | Base names of the atemporal (static) variables present in bn. |
| missingSymbols | Symbols in the CSVs to interpret as missing values. |
Definition at line 158 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _atemporalVars_, _baseNames_, gum::learning::IKTBNLearner< GUM_SCALAR >::_checkMinimalOrder_(), _csvBaseName_, _dirPath_, _induceTypes_, _kMax_, _missingSymbols_, _nbSamples_, _prior_bn_, GUM_ERROR, and kMax().
| gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::~KTBNAdaptiveLearner | ( | ) |
Constructor — the candidate orders are kMin..kMax.
Mirrors the CSV constructor of gum::learning::KTBNLearner, except that no single order k is given: the learner explores every \(k \in [k_{min}, kMax]\) at learn time. \(k_{min}\) starts at 2 (k = 1 is a static BN; use BNLearner) and is raised by the structural-constraint setters — see the class doc.
| dirPath | Directory holding the trajectory CSV files. |
| csvBaseName | Stem of each file name (1-based index and .csv appended, e.g. "traj" -> "traj1.csv", "traj2.csv", ...). |
| nbSamples | Number of CSV files to read. |
| kMax | Largest order to explore. Must be \(\geq 2\). |
| atemporalVars | Base names of the atemporal (static) variables. Pass an empty set for "every variable is temporal"; it has no default, since omitting it selects the inferring overload below. |
| missingSymbols | Symbols in the CSVs to interpret as missing values. |
| induceTypes | When true (default), columns whose values are all numeric are retyped (integer/range/continuous) instead of being treated as plain labels — same semantics as KTBNLearner. |
std::unordered_set<std::string>{"C","D"} — or pass a named variable. Definition at line 189 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner().
|
privatedelete |
|
privatedelete |
|
private |
Apply the recorded score / algorithm / correction / prior onto a freshly-built learner. Only knobs that differ from their default are touched, and only those the chosen algorithm actually consumes (a score-based algo takes a score; MIIC takes a correction) — so an unconfigured learner is left at its defaults and no irrelevant setting can trip checkScorePriorCompatibility().
Definition at line 1151 of file KTBNAdaptiveLearner_tpl.h.
References _algo_, _correction_, _nbDecrease_, _prior_, _priorWeight_, _score_, _tabuSize_, gum::learning::IBNLearner::AIC, gum::learning::IBNLearner::BD, gum::learning::IBNLearner::BDeu, gum::learning::IBNLearner::BIC, gum::learning::IBNLearner::EXTENDED_GREEDY_HILL_CLIMBING, gum::learning::IBNLearner::fNML, gum::learning::IBNLearner::GREEDY_HILL_CLIMBING, gum::learning::IBNLearner::LOCAL_SEARCH_WITH_TABU_LIST, gum::learning::IBNLearner::LOG2LIKELIHOOD, gum::learning::CorrectedMutualInformation::MDL, gum::learning::IBNLearner::MDL, gum::learning::IBNLearner::MIIC, gum::learning::CorrectedMutualInformation::NML, gum::learning::IBNLearner::NO_prior, gum::learning::CorrectedMutualInformation::NoCorr, gum::learning::KTBNLearner< GUM_SCALAR >::useExtendedGreedyHillClimbing(), gum::learning::KTBNLearner< GUM_SCALAR >::useGreedyHillClimbing(), gum::learning::KTBNLearner< GUM_SCALAR >::useLocalSearchWithTabuList(), gum::learning::KTBNLearner< GUM_SCALAR >::useNMLCorrection(), gum::learning::KTBNLearner< GUM_SCALAR >::useNoCorrection(), gum::learning::KTBNLearner< GUM_SCALAR >::useScoreAIC(), gum::learning::KTBNLearner< GUM_SCALAR >::useScoreBD(), gum::learning::KTBNLearner< GUM_SCALAR >::useScoreBIC(), gum::learning::KTBNLearner< GUM_SCALAR >::useScorefNML(), gum::learning::KTBNLearner< GUM_SCALAR >::useScoreLog2Likelihood(), gum::learning::KTBNLearner< GUM_SCALAR >::useScoreMDL(), and gum::learning::KTBNLearner< GUM_SCALAR >::useSmoothingPrior().
Referenced by learnKTBN().
|
private |
Replay the recorded structural constraints onto learner (built for order k). Engine-name constraints whose slice does not fit k (slice >= k) are skipped for this candidate; the base-only intra-slice / all-slices constraints are handed to learner, which expands them for its own k. The allow-* flags and max-indegree are applied when non-default.
Definition at line 1201 of file KTBNAdaptiveLearner_tpl.h.
References _allowAdditions_, _allowDeletions_, _allowReversals_, gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _forbiddenArcs_, _forbiddenArcsAllSlices_, _forbiddenIntraSliceArcs_, _forbiddenKernelArcs_, _mandatoryArcs_, _mandatoryKernelArcs_, _maxIndegree_, _noChildrenNodes_, _noParentNodes_, _possibleEdges_, gum::learning::KTBNLearner< GUM_SCALAR >::addForbiddenArc(), gum::learning::KTBNLearner< GUM_SCALAR >::addForbiddenArcAllSlices(), gum::learning::KTBNLearner< GUM_SCALAR >::addForbiddenIntraSliceArc(), gum::learning::KTBNLearner< GUM_SCALAR >::addMandatoryArc(), gum::learning::KTBNLearner< GUM_SCALAR >::addNoChildrenNode(), gum::learning::KTBNLearner< GUM_SCALAR >::addNoParentNode(), gum::learning::KTBNLearner< GUM_SCALAR >::addPossibleEdge(), gum::learning::KTBNLearner< GUM_SCALAR >::allowArcAdditions(), gum::learning::KTBNLearner< GUM_SCALAR >::allowArcDeletions(), gum::learning::KTBNLearner< GUM_SCALAR >::allowArcReversals(), and gum::learning::KTBNLearner< GUM_SCALAR >::setMaxIndegree().
Referenced by learnKTBN().
|
overrideprivatevirtual |
atemporal base names for IKTBNLearner's shared encode/_determineNode_; the set recorded at construction.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 1040 of file KTBNAdaptiveLearner_tpl.h.
References _atemporalVars_.
|
protectedinherited |
Reject an arc the k-TBN definition can never contain, so eraseForbiddenArc and addMandatoryArc both fail early (before any internal learner is touched) with a uniform message. action is the verb phrase completing "cannot <action> <tail> -> <head>: ..." (e.g. "force the mandatory arc", "un-forbid the arc"). Two arcs are refused: a temporal -> atemporal arc (a time-varying variable can never parent a static one) and a backward-in-time arc (head strictly before tail).
Definition at line 95 of file IKTBNLearner_tpl.h.
References _determineNode_(), gum::KTBN< GUM_SCALAR >::ATEMPORAL, and GUM_ERROR.
Referenced by _isKnownBase_(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addMandatoryArc(), gum::learning::KTBNLearner< GUM_SCALAR >::addMandatoryArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseForbiddenArc(), and gum::learning::KTBNLearner< GUM_SCALAR >::eraseForbiddenArc().
|
protectedinherited |
Throw InvalidArgument unless base is a known temporal base. context completes "cannot appear in <context>" (e.g. "an
intra-slice constraint", "a kernel-relative arc"): every caller rejects an atemporal base for the same underlying reason – it has no per-slice instance – so they share the sentence and vary the setting.
Definition at line 196 of file IKTBNLearner_tpl.h.
References _atemporalVarNames_(), _isKnownBase_(), gum::contains(), and GUM_ERROR.
Referenced by _isKnownBase_(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::_verifyKernelArc_(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addForbiddenIntraSliceArc(), gum::learning::KTBNLearner< GUM_SCALAR >::addForbiddenIntraSliceArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseForbiddenIntraSliceArc(), and gum::learning::KTBNLearner< GUM_SCALAR >::eraseForbiddenIntraSliceArc().
|
staticprotectedinherited |
Throw InvalidArgument unless order is at least 2, label naming the offending parameter ("k" for the fixed-k learner, "kMax" for the adaptive one).
This is a learner constraint, not a model one – gum::KTBN, gum::KTBNGenerator and gum::KTBNInference all accept k = 1 – which is why it lives here rather than on the model. Static because four of its call sites are themselves static helpers invoked from member-initialiser lists, before any object exists.
Definition at line 210 of file IKTBNLearner_tpl.h.
References GUM_ERROR.
Referenced by gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::KTBNAdaptiveLearner(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::KTBNAdaptiveLearner(), gum::learning::KTBNLearner< GUM_SCALAR >::_buildPriorFromBN_(), gum::learning::KTBNLearner< GUM_SCALAR >::_buildPriorFromCSV_(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::_inferAtemporalVars_(), gum::learning::KTBNLearner< GUM_SCALAR >::_inferAtemporalVars_(), and _isKnownBase_().
|
private |
Number of free parameters of net's template: summed over every template node (all initial slices, the kernel slice and the atemporal nodes), \((|X|-1)\prod_{P\in pa(X)}|P|\). This is the model-complexity term of the cross-k BIC and AIC scores used by learnKTBN(): it grows with \(k\) (a higher order adds initial-slice CPTs and can widen the kernel), which is what offsets the monotonic likelihood gain and prevents always picking the largest \(k\).
Definition at line 1470 of file KTBNAdaptiveLearner_tpl.h.
Referenced by _orderSelectionScore_().
|
protectedinherited |
engine name -> (base, slice); atemporal names map to KTBN::ATEMPORAL. Shared by every learner; only the atemporal test varies (via atemporalVarNames()).
Definition at line 64 of file IKTBNLearner_tpl.h.
References _atemporalVarNames_(), gum::KTBN< GUM_SCALAR >::ATEMPORAL, gum::contains(), and GUM_ERROR.
Referenced by gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::_applyConstraints_(), _checkArcTemporallyFeasible_(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::_forEachScoredNode_(), gum::learning::KTBNLearner< GUM_SCALAR >::_forOwningLearner_(), _isKnownBase_(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::_recomputeKMin_(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addForbiddenArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addMandatoryArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addNoChildrenNode(), gum::learning::KTBNLearner< GUM_SCALAR >::addNoChildrenNode(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addNoParentNode(), gum::learning::KTBNLearner< GUM_SCALAR >::addNoParentNode(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addPossibleEdge(), gum::learning::KTBNLearner< GUM_SCALAR >::addPossibleEdge(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseForbiddenArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseMandatoryArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseNoChildrenNode(), gum::learning::KTBNLearner< GUM_SCALAR >::eraseNoChildrenNode(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseNoParentNode(), gum::learning::KTBNLearner< GUM_SCALAR >::eraseNoParentNode(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::erasePossibleEdge(), gum::learning::KTBNLearner< GUM_SCALAR >::erasePossibleEdge(), and gum::learning::KTBNLearner< GUM_SCALAR >::names().
|
protectedinherited |
(base, slice) -> engine name ("A[1]" / atemporal engine name). Pure function, shared by every learner.
Definition at line 57 of file IKTBNLearner_tpl.h.
References gum::KTBN< GUM_SCALAR >::ATEMPORAL.
Referenced by gum::learning::KTBNLearner< GUM_SCALAR >::_assemble_(), gum::learning::KTBNLearner< GUM_SCALAR >::_build_(), _isKnownBase_(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addForbiddenArc(), gum::learning::KTBNLearner< GUM_SCALAR >::addForbiddenArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addMandatoryArc(), gum::learning::KTBNLearner< GUM_SCALAR >::addMandatoryArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addNoChildrenNode(), gum::learning::KTBNLearner< GUM_SCALAR >::addNoChildrenNode(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addNoParentNode(), gum::learning::KTBNLearner< GUM_SCALAR >::addNoParentNode(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addPossibleEdge(), gum::learning::KTBNLearner< GUM_SCALAR >::addPossibleEdge(), gum::learning::KTBNLearner< GUM_SCALAR >::domainSize(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseForbiddenArc(), gum::learning::KTBNLearner< GUM_SCALAR >::eraseForbiddenArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseMandatoryArc(), gum::learning::KTBNLearner< GUM_SCALAR >::eraseMandatoryArc(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseNoChildrenNode(), gum::learning::KTBNLearner< GUM_SCALAR >::eraseNoChildrenNode(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseNoParentNode(), gum::learning::KTBNLearner< GUM_SCALAR >::eraseNoParentNode(), gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::erasePossibleEdge(), gum::learning::KTBNLearner< GUM_SCALAR >::erasePossibleEdge(), and gum::learning::KTBNLearner< GUM_SCALAR >::learnParameters().
|
private |
fNML order score of net over the recorded trajectories: \(\log_2 L - \sum_i \sum_j \log_2 C^{r_i}_{N_{ij}}\), with \(r_i\) the node's domain size and \(N_{ij}\) the count for parent configuration \(j\). Unlike BIC/AIC the penalty is data-dependent, so the regret needs the same per-instance walk as the likelihood — both are accumulated in one forEachScoredNode pass. Mirrors aGrUM's ScorefNML.
Definition at line 1444 of file KTBNAdaptiveLearner_tpl.h.
References _ctable_, and _forEachScoredNode_().
Referenced by _orderSelectionScore_().
|
private |
Stream every scored template-node instance of net over the recorded trajectories, driving both the likelihood and the fNML penalty off one data walk, so the width-k window logic lives in one place.
Each trajectory is streamed row by row through a width-k circular buffer (absolute time t at slot t % k): every temporal node X[t] is visited against net's template CPT for slice min(t, k-1), reading each parent from row t - lag; atemporal nodes are visited once per trajectory. perInstance runs once per instance with the observed labels loaded into e.inst; perNodeFinal runs once per template node after the stream, for criteria reducing accumulated per-node state (e.g. fNML's regret).
Definition at line 1253 of file KTBNAdaptiveLearner_tpl.h.
References gum::Instantiation::Instantiation(), _csvBaseName_, gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _dirPath_, _missingSymbols_, _nbSamples_, gum::KTBN< GUM_SCALAR >::ATEMPORAL, gum::learning::CSVParser::current(), GUM_ERROR, and gum::learning::CSVParser::next().
Referenced by _fNMLScore_(), and _log2Likelihood_().
|
staticprivate |
checks kMax >= 2 and nbSamples >= 1, then delegates to the shared IKTBNLearner::scanConstantColumns(). Called from the atemporal-inferring constructor's member-initialiser list, before this object exists, so the checks live here rather than in the body — otherwise a bad argument would only surface after a wasted scan.
Definition at line 143 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_checkMinimalOrder_(), gum::learning::IKTBNLearner< GUM_SCALAR >::_scanConstantColumns_(), GUM_ERROR, and kMax().
Referenced by KTBNAdaptiveLearner().
|
overrideprivatevirtual |
whether base is one of this learner's variables; the base names read at construction, from the CSV header or the schema BN.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 1045 of file KTBNAdaptiveLearner_tpl.h.
References _baseNames_.
|
private |
Factorized log2-likelihood of net over the recorded trajectories, comparable across candidate k (the raw score types are not: their flattened tables differ from one k to another). The data is complete, so this is a closed-form sum of CPT lookups — no inference. A thin reduction over forEachScoredNode that sums log2 of the CPT entry over every visited node instance.
Definition at line 1432 of file KTBNAdaptiveLearner_tpl.h.
References _forEachScoredNode_().
Referenced by _orderSelectionScore_().
|
private |
The cross-k order-selection score of net under the recorded orderScore criterion, given logN = log2 of the sample size. The single dispatch point learnKTBN() uses to compare candidates; add a branch here for each new OrderScoreType.
Definition at line 1486 of file KTBNAdaptiveLearner_tpl.h.
References _countParameters_(), _fNMLScore_(), _log2Likelihood_(), _orderScore_, AIC, BIC, and fNML.
Referenced by learnKTBN().
|
private |
Raise kMin, if needed, so that kMin > slice: a smaller candidate would silently drop a constraint naming that slice (the "slice < k" rule applyConstraints's fits() filter uses). O(1), since adding a constraint can only push kMin up. No-op for KTBN::ATEMPORAL.
Definition at line 1106 of file KTBNAdaptiveLearner_tpl.h.
References _kMin_, and gum::KTBN< GUM_SCALAR >::ATEMPORAL.
Referenced by _recomputeKMin_(), addForbiddenArc(), addForbiddenKernelArc(), addMandatoryArc(), addMandatoryKernelArc(), addNoChildrenNode(), addNoParentNode(), and addPossibleEdge().
|
private |
Recompute kMin from scratch: max(2, 1 + the largest concrete slice named by any recorded forbidden/mandatory arc, possible edge, or no-parent/no-children node (the kinds fits() can drop). Intra-slice / all-slices constraints carry no slice and are excluded. Unlike raiseKMinForSlice, an erase can lower kMin with no O(1) way to tell, so every erase* setter runs this full rescan instead.
Definition at line 1112 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _forbiddenArcs_, _forbiddenKernelArcs_, _kMin_, _mandatoryArcs_, _mandatoryKernelArcs_, _noChildrenNodes_, _noParentNodes_, _possibleEdges_, and _raiseKMinForSlice_().
Referenced by eraseForbiddenArc(), eraseForbiddenKernelArc(), eraseMandatoryArc(), eraseMandatoryKernelArc(), eraseNoChildrenNode(), eraseNoParentNode(), and erasePossibleEdge().
|
staticprotectedinherited |
Scans every trajectory and returns the base names classified atemporal: those whose value never changes across the rows of a single trajectory (checked independently per trajectory, so the value may still differ between trajectories). Shared by every atemporal-inferring CSV constructor (KTBNLearner, KTBNAdaptiveLearner): identical scanning logic regardless of which subclass calls it, so duplicating it per subclass would only invite the two copies to drift. Callers are responsible for validating their own arguments (e.g. k/kMax >= 2) before calling this — it does no such check itself, only opens files, so a bad argument would otherwise only be caught after a wasted scan.
Column indices still "live" (not yet proven non-constant) are tracked as a shrinking list rather than rescanned from scratch, and scanning stops opening further trajectories once that list is empty — falsification is one-way, so nothing left to test can ever become atemporal again.
Definition at line 113 of file IKTBNLearner_tpl.h.
References gum::learning::CSVParser::current(), GUM_ERROR, gum::learning::CSVParser::nbLine(), and gum::learning::CSVParser::next().
Referenced by gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::_inferAtemporalVars_(), gum::learning::KTBNLearner< GUM_SCALAR >::_inferAtemporalVars_(), and _isKnownBase_().
|
private |
Throw InvalidArgument unless base is a known base variable and slice is valid for it: base must be in baseNames; an atemporal base requires slice == KTBN::ATEMPORAL, a temporal one requires slice in [0, kMax). Used by the constraint setters to reject unknown names / out-of-range slices eagerly.
Definition at line 1054 of file KTBNAdaptiveLearner_tpl.h.
References _atemporalVars_, _baseNames_, _kMax_, gum::KTBN< GUM_SCALAR >::ATEMPORAL, and GUM_ERROR.
Referenced by addForbiddenArc(), addForbiddenArc(), addForbiddenArcAllSlices(), addMandatoryArc(), addMandatoryArc(), addNoChildrenNode(), addNoChildrenNode(), addNoParentNode(), addNoParentNode(), addPossibleEdge(), addPossibleEdge(), eraseForbiddenArc(), eraseForbiddenArc(), eraseForbiddenArcAllSlices(), eraseMandatoryArc(), eraseMandatoryArc(), eraseNoChildrenNode(), eraseNoChildrenNode(), eraseNoParentNode(), eraseNoParentNode(), erasePossibleEdge(), and erasePossibleEdge().
|
private |
Throw InvalidArgument unless tailBase and headBase are known, temporal base variables (a kernel-relative arc has no meaning for an atemporal one: it has no kernel-slice instance) and lag is in [0, kMax) — so some candidate k in [2,kMax] can place tailBase at slice k-1-lag >= 0 and headBase at the kernel slice k-1. Used by the four kernel-arc setters (add/eraseForbiddenKernelArc, add/eraseMandatoryKernelArc) to reject bad calls eagerly.
Definition at line 1082 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_checkBaseIsTemporal_(), _kMax_, and GUM_ERROR.
Referenced by addForbiddenKernelArc(), addMandatoryKernelArc(), eraseForbiddenKernelArc(), and eraseMandatoryKernelArc().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 673 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and addForbiddenArc().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 656 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _forbiddenArcs_, _raiseKMinForSlice_(), and _verifyBase_().
Referenced by addForbiddenArc().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 850 of file KTBNAdaptiveLearner_tpl.h.
References _forbiddenArcsAllSlices_, _verifyBase_(), and gum::KTBN< GUM_SCALAR >::ATEMPORAL.
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 823 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_checkBaseIsTemporal_(), and _forbiddenIntraSliceArcs_.
| KTBNAdaptiveLearner< GUM_SCALAR > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addForbiddenKernelArc | ( | std::string_view | tailBase, |
| int | lag, | ||
| std::string_view | headBase ) |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Definition at line 776 of file KTBNAdaptiveLearner_tpl.h.
References _forbiddenKernelArcs_, _raiseKMinForSlice_(), and _verifyKernelArc_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 731 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and addMandatoryArc().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 713 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_checkArcTemporallyFeasible_(), gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _mandatoryArcs_, _raiseKMinForSlice_(), and _verifyBase_().
Referenced by addMandatoryArc().
| KTBNAdaptiveLearner< GUM_SCALAR > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::addMandatoryKernelArc | ( | std::string_view | tailBase, |
| int | lag, | ||
| std::string_view | headBase ) |
Force an arc from tailBase, lag slices before the kernel, to headBase in the kernel. See addForbiddenKernelArc for the (base, slice) vs. kernel-relative distinction; the validity constraints (lag range, temporal bases, kMin effect) are the same. Always temporally feasible by construction (lag >= 0 guarantees headSlice = k-1 >= k-1-lag = tailSlice), so unlike the plain addMandatoryArc there is no separate feasibility check to run.
Definition at line 798 of file KTBNAdaptiveLearner_tpl.h.
References _mandatoryKernelArcs_, _raiseKMinForSlice_(), and _verifyKernelArc_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 908 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and addNoChildrenNode().
Referenced by addNoChildrenNode().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 916 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _noChildrenNodes_, _raiseKMinForSlice_(), and _verifyBase_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 872 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and addNoParentNode().
Referenced by addNoParentNode().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 880 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _noParentNodes_, _raiseKMinForSlice_(), and _verifyBase_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 957 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _possibleEdges_, _raiseKMinForSlice_(), and _verifyBase_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 944 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and addPossibleEdge().
Referenced by addPossibleEdge().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 1008 of file KTBNAdaptiveLearner_tpl.h.
References _allowAdditions_.
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 1015 of file KTBNAdaptiveLearner_tpl.h.
References _allowDeletions_.
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 1022 of file KTBNAdaptiveLearner_tpl.h.
References _allowReversals_.
| Size gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::bestK | ( | ) | const |
Order k selected by the last learnKTBN() call.
| OperationNotAllowed | if learnKTBN() has not run yet. |
Definition at line 299 of file KTBNAdaptiveLearner_tpl.h.
References _bestK_, and GUM_ERROR.
Referenced by learnKTBN().
| std::string gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::checkScorePriorCompatibility | ( | ) | const |
Warning string if the recorded score and prior are incompatible, empty otherwise. Data-free: it evaluates the recorded (score, prior) pair exactly as KTBNLearner/BNLearner would, so an incompatible combination can be caught before learnKTBN() reads any trajectory.
Definition at line 338 of file KTBNAdaptiveLearner_tpl.h.
References _algo_, _prior_, _priorWeight_, _score_, gum::learning::IBNLearner::AIC, gum::learning::IBNLearner::BD, gum::learning::IBNLearner::BDeu, gum::learning::IBNLearner::BIC, gum::learning::IBNLearner::fNML, gum::learning::ScoreAIC::isPriorCompatible(), gum::learning::ScoreBD::isPriorCompatible(), gum::learning::ScoreBDeu::isPriorCompatible(), gum::learning::ScoreBIC::isPriorCompatible(), gum::learning::ScorefNML::isPriorCompatible(), gum::learning::ScoreLog2Likelihood::isPriorCompatible(), gum::learning::IBNLearner::LOG2LIKELIHOOD, gum::learning::IBNLearner::MDL, gum::learning::IBNLearner::MIIC, gum::learning::NoPriorType, gum::learning::IBNLearner::SMOOTHING, and gum::learning::SmoothingPriorType.
Referenced by state().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 700 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and eraseForbiddenArc().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 686 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_checkArcTemporallyFeasible_(), gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _forbiddenArcs_, _recomputeKMin_(), and _verifyBase_().
Referenced by eraseForbiddenArc().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 862 of file KTBNAdaptiveLearner_tpl.h.
References _forbiddenArcsAllSlices_, _verifyBase_(), and gum::KTBN< GUM_SCALAR >::ATEMPORAL.
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 838 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_checkBaseIsTemporal_(), and _forbiddenIntraSliceArcs_.
| KTBNAdaptiveLearner< GUM_SCALAR > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseForbiddenKernelArc | ( | std::string_view | tailBase, |
| int | lag, | ||
| std::string_view | headBase ) |
Undo a previous addForbiddenKernelArc (same (tailBase, lag, headBase) triple).
Definition at line 787 of file KTBNAdaptiveLearner_tpl.h.
References _forbiddenKernelArcs_, _recomputeKMin_(), and _verifyKernelArc_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 759 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and eraseMandatoryArc().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 744 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _mandatoryArcs_, _recomputeKMin_(), and _verifyBase_().
Referenced by eraseMandatoryArc().
| KTBNAdaptiveLearner< GUM_SCALAR > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::eraseMandatoryKernelArc | ( | std::string_view | tailBase, |
| int | lag, | ||
| std::string_view | headBase ) |
Undo a previous addMandatoryKernelArc (same (tailBase, lag, headBase) triple).
Definition at line 812 of file KTBNAdaptiveLearner_tpl.h.
References _mandatoryKernelArcs_, _recomputeKMin_(), and _verifyKernelArc_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 926 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and eraseNoChildrenNode().
Referenced by eraseNoChildrenNode().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 934 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _noChildrenNodes_, _recomputeKMin_(), and _verifyBase_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 890 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and eraseNoParentNode().
Referenced by eraseNoParentNode().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 898 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _noParentNodes_, _recomputeKMin_(), and _verifyBase_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 991 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_determineNode_(), _possibleEdges_, _recomputeKMin_(), and _verifyBase_().
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 978 of file KTBNAdaptiveLearner_tpl.h.
References gum::learning::IKTBNLearner< GUM_SCALAR >::_encode_(), _verifyBase_(), and erasePossibleEdge().
Referenced by erasePossibleEdge().
| KTBNAdaptiveLearner< GUM_SCALAR > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::ignoreMissingSymbols | ( | bool | ignore = true | ) |
Learn and score on the fully observed data only, dropping every row and every scoring instance that carries a missing symbol.
Without this, learnKTBN() refuses trajectories containing missing values: aGrUM's structure learning cannot cope with them (gum::learning::IBNLearner::learnDag_ raises MissingValueInDatabase), so there is nothing sensible to hand it. With it, each candidate's databases are built by complete-case selection and the cross-k score skips any instance whose family is incomplete — the two agree on which data counts.
A row or instance is dropped as soon as one cell of its window is missing, so a single gap costs up to \(k\) of them. A larger \(k\) spans more rows per window and loses proportionally more.
\(\log_2 L\) is a sum of per-instance terms, each \(\leq 0\). Dropping instances removes negative terms and therefore raises the total: the candidate is not fitting better, it is being charged for less data. Since the larger \(k\) drops more, it gains more — precisely the comparison bestK() rests on.
The BIC penalty does not compensate. \(\log_2 N\) is computed once from the raw trajectory lengths (deliberately, so it is identical across candidates) and so describes a sample size the likelihood no longer uses; the penalty is unchanged while the likelihood is inflated.
The distortion grows with the missing-value rate. At a few percent it is usually harmless; on heavily incomplete trajectories bestK() can be pulled a full order upwards. Inspect scorePerCandidateK() rather than trusting bestK() alone, and prefer complete trajectories whenever the order itself is the question. gum::learning::KTBNLearner::nbDroppedRows() reports how much each candidate actually lost.
Definition at line 573 of file KTBNAdaptiveLearner_tpl.h.
References _ignoreMissingSymbols_.
| INLINE bool gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::isIgnoringMissingSymbols | ( | ) | const |
Whether incomplete rows and instances are dropped. False by default.
Definition at line 579 of file KTBNAdaptiveLearner_tpl.h.
References _ignoreMissingSymbols_.
| Size gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::kMax | ( | ) | const |
Largest order explored (the kMax argument of the constructor).
Definition at line 333 of file KTBNAdaptiveLearner_tpl.h.
References _kMax_.
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), and _inferAtemporalVars_().
| const std::vector< std::pair< std::string, std::string > > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::latentVariables | ( | ) | const |
Engine-name (tail, head) pairs of arcs the selected model's MIIC run flagged as hiding a latent variable. Empty when the recorded algorithm is not MIIC (only MIIC produces latent-variable annotations) or when none were found.
| OperationNotAllowed | if learnKTBN() has not run yet. |
Definition at line 310 of file KTBNAdaptiveLearner_tpl.h.
References _bestK_, _bestLatentVariables_, and GUM_ERROR.
|
overridevirtual |
Learns the best k in [kMin, kMax] together with the structure and the CPTs: one KTBNLearner is built and run per candidate k, the recorded configuration is replayed on each, and the k-TBN with the best model-selection score is returned. kMin starts at 2 and is raised by the structural-constraint setters (see class doc).
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 198 of file KTBNAdaptiveLearner_tpl.h.
References _algo_, _applyConfig_(), _applyConstraints_(), _atemporalVars_, _bestK_, _bestLatentVariables_, _csvBaseName_, _dirPath_, _ignoreMissingSymbols_, _induceTypes_, _kMax_, _kMin_, _missingSymbols_, _nbSamples_, _orderSelectionScore_(), _prior_bn_, _scorePerCandidateK_, bestK(), GUM_ERROR, and gum::learning::IBNLearner::MIIC.
|
privatedelete |
|
privatedelete |
| const std::vector< std::pair< Size, double > > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::scorePerCandidateK | ( | ) | const |
Per-candidate cross-k scores from the last learnKTBN() call, as (k, score) pairs for k = kMin..kMax in ascending k order — the values the order selection compared to choose bestK() (higher is better; the argmax is bestK()). Under the default useOrderScoreBIC() each score is \(\log_2 L - \tfrac{1}{2}\,d\,\log_2 N\) of the k-TBN learned for that k.
| OperationNotAllowed | if learnKTBN() has not run yet. |
Definition at line 319 of file KTBNAdaptiveLearner_tpl.h.
References _bestK_, _scorePerCandidateK_, and GUM_ERROR.
|
overridevirtual |
Forbid an arc from tailBase, lag slices before the kernel, to headBase in the kernel: tailBase at slice k-1-lag -> headBase at slice k-1, for whichever k is selected. The slice is not given directly but derived from lag relative to the kernel slice k-1, which moves with the candidate — so no absolute slice could express it at record time. Adaptive-only: the fixed-k learners have no moving kernel slice to anchor it to. lag must be in [0, kMax) and both bases temporal (an atemporal variable has no kernel-slice instance). Raises kMin to at least lag+1, like a constraint naming slice lag.
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 1029 of file KTBNAdaptiveLearner_tpl.h.
References _maxIndegree_.
| std::vector< std::tuple< std::string, std::string, std::string > > gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::state | ( | ) | const |
The recorded configuration as (key, value, comment) tuples (mirrors KTBNLearner::state()); toString() is a formatted view of it.
Definition at line 365 of file KTBNAdaptiveLearner_tpl.h.
References _algo_, _allowAdditions_, _allowDeletions_, _allowReversals_, _atemporalVars_, _baseNames_, _bestK_, _correction_, _forbiddenArcs_, _forbiddenArcsAllSlices_, _forbiddenIntraSliceArcs_, _forbiddenKernelArcs_, _kMax_, _kMin_, _mandatoryArcs_, _mandatoryKernelArcs_, _maxIndegree_, _nbDecrease_, _noChildrenNodes_, _noParentNodes_, _orderScore_, _possibleEdges_, _prior_, _priorWeight_, _score_, _tabuSize_, gum::learning::IBNLearner::AIC, AIC, gum::learning::IBNLearner::BD, gum::learning::IBNLearner::BDeu, gum::learning::IBNLearner::BIC, BIC, checkScorePriorCompatibility(), gum::learning::IBNLearner::EXTENDED_GREEDY_HILL_CLIMBING, gum::learning::IBNLearner::fNML, fNML, gum::learning::IBNLearner::GREEDY_HILL_CLIMBING, gum::learning::IBNLearner::LOCAL_SEARCH_WITH_TABU_LIST, gum::learning::IBNLearner::LOG2LIKELIHOOD, gum::learning::CorrectedMutualInformation::MDL, gum::learning::IBNLearner::MDL, gum::learning::IBNLearner::MIIC, gum::learning::CorrectedMutualInformation::NML, gum::learning::CorrectedMutualInformation::NoCorr, and gum::learning::IBNLearner::SMOOTHING.
Referenced by toString().
| std::string gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::toString | ( | ) | const |
Human-readable summary of the recorded configuration (candidate order range, algorithm / score / correction / prior, structural constraints) plus the selected k once learnKTBN() has run.
Definition at line 484 of file KTBNAdaptiveLearner_tpl.h.
References state().
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 595 of file KTBNAdaptiveLearner_tpl.h.
References _algo_, and gum::learning::IBNLearner::EXTENDED_GREEDY_HILL_CLIMBING.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 588 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _algo_, and gum::learning::IBNLearner::GREEDY_HILL_CLIMBING.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 602 of file KTBNAdaptiveLearner_tpl.h.
References _algo_, _nbDecrease_, _tabuSize_, and gum::learning::IBNLearner::LOCAL_SEARCH_WITH_TABU_LIST.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 627 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _correction_, and gum::learning::CorrectedMutualInformation::MDL.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 611 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _algo_, and gum::learning::IBNLearner::MIIC.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 621 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _correction_, and gum::learning::CorrectedMutualInformation::NML.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 633 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _correction_, and gum::learning::CorrectedMutualInformation::NoCorr.
| KTBNAdaptiveLearner< GUM_SCALAR > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::useOrderScoreAIC | ( | ) |
Select k by AIC: keep the k whose learned model maximises \(\log_2 L - d\) (a lighter, sample-size-independent complexity penalty than BIC).
Definition at line 556 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _orderScore_, and AIC.
| KTBNAdaptiveLearner< GUM_SCALAR > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::useOrderScoreBIC | ( | ) |
Select k by BIC (the default): keep the k whose learned model maximises \(\log_2 L - \tfrac{1}{2}\,d\,\log_2 N\).
Definition at line 550 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _orderScore_, and BIC.
| KTBNAdaptiveLearner< GUM_SCALAR > & gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::useOrderScorefNML | ( | ) |
\(\tfrac{1}{2}\,d\,\log_2 N\) by a sum of per-node, per-parent-configuration multinomial parametric complexities (regret) – data-dependent, unlike BIC/AIC, matching aGrUM's ScorefNML.
Definition at line 562 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _orderScore_, and fNML.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 505 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _score_, and gum::learning::IBNLearner::AIC.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 511 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _score_, and gum::learning::IBNLearner::BD.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 517 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _score_, and gum::learning::IBNLearner::BDeu.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 523 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _score_, and gum::learning::IBNLearner::BIC.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 541 of file KTBNAdaptiveLearner_tpl.h.
References _score_, and gum::learning::IBNLearner::fNML.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 529 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _score_, and gum::learning::IBNLearner::LOG2LIKELIHOOD.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 535 of file KTBNAdaptiveLearner_tpl.h.
References KTBNAdaptiveLearner(), _score_, and gum::learning::IBNLearner::MDL.
|
overridevirtual |
Implements gum::learning::IKTBNLearner< GUM_SCALAR >.
Definition at line 644 of file KTBNAdaptiveLearner_tpl.h.
References _prior_, _priorWeight_, and gum::learning::IBNLearner::SMOOTHING.
|
private |
recorded structure-learning algorithm
Definition at line 565 of file KTBNAdaptiveLearner.h.
Referenced by _applyConfig_(), checkScorePriorCompatibility(), learnKTBN(), state(), useExtendedGreedyHillClimbing(), useGreedyHillClimbing(), useLocalSearchWithTabuList(), and useMIIC().
|
private |
recorded graph-change permissions / indegree cap
Definition at line 580 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), allowArcAdditions(), and state().
|
private |
Definition at line 581 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), allowArcDeletions(), and state().
|
private |
Definition at line 582 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), allowArcReversals(), and state().
|
private |
base names of the atemporal (static) variables
Definition at line 531 of file KTBNAdaptiveLearner.h.
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), _atemporalVarNames_(), _verifyBase_(), learnKTBN(), and state().
|
private |
all base variable names (temporal + atemporal), read from the first trajectory CSV header at construction. Authoritative universe used by the constraint setters to reject names that do not exist.
Definition at line 536 of file KTBNAdaptiveLearner.h.
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), _isKnownBase_(), _verifyBase_(), and state().
|
private |
k selected by the last learnKTBN() call, or 0 as a sentinel while no learning has happened yet. 0 can never be a valid order (candidates are 2..kMax), so bestK() reads it to decide whether learnKTBN() has run.
Definition at line 624 of file KTBNAdaptiveLearner.h.
Referenced by bestK(), latentVariables(), learnKTBN(), scorePerCandidateK(), and state().
|
private |
latent-variable arcs (engine-name pairs) reported by the winning candidate's MIIC run, captured by learnKTBN(); empty when the selected algorithm is not MIIC. Exposed by latentVariables().
Definition at line 629 of file KTBNAdaptiveLearner.h.
Referenced by latentVariables(), and learnKTBN().
|
private |
recorded MIIC correction
Definition at line 572 of file KTBNAdaptiveLearner.h.
Referenced by _applyConfig_(), state(), useMDLCorrection(), useNMLCorrection(), and useNoCorrection().
|
private |
stem of each trajectory file name
Definition at line 515 of file KTBNAdaptiveLearner.h.
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), _forEachScoredNode_(), and learnKTBN().
|
mutableprivate |
cache of log2 of the multinomial parametric complexity C^r_n, used by the fNML order penalty. Mutable because log2Cnr() memoizes; the const order-score helpers may therefore call it. Only touched under fNML.
Definition at line 771 of file KTBNAdaptiveLearner.h.
Referenced by _fNMLScore_().
|
private |
directory holding the trajectory CSV files
Definition at line 512 of file KTBNAdaptiveLearner.h.
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), _forEachScoredNode_(), and learnKTBN().
|
private |
forbidden arcs, as (tail, head) engine-name pairs
Definition at line 592 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), _recomputeKMin_(), addForbiddenArc(), eraseForbiddenArc(), and state().
|
private |
forbidden all-slices arcs, as (tailBase, headBase) pairs
Definition at line 604 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), addForbiddenArcAllSlices(), eraseForbiddenArcAllSlices(), and state().
|
private |
forbidden intra-slice arcs, as (tailBase, headBase) pairs
Definition at line 601 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), addForbiddenIntraSliceArc(), eraseForbiddenIntraSliceArc(), and state().
|
private |
forbidden kernel-relative arcs, as (tailBase, headBase, lag) triples: tailBase at slice k-1-lag -> headBase at the kernel slice k-1. Kept separate from forbiddenArcs (which stores resolved engine names) since the slice here is only known once a candidate k is fixed.
Definition at line 610 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), _recomputeKMin_(), addForbiddenKernelArc(), eraseForbiddenKernelArc(), and state().
|
private |
whether incomplete rows/instances are dropped (see ignoreMissingSymbols())
Definition at line 542 of file KTBNAdaptiveLearner.h.
Referenced by ignoreMissingSymbols(), isIgnoringMissingSymbols(), and learnKTBN().
|
private |
whether numeric columns are retyped (see KTBNLearner); unused (and forced false) when a schema BN is supplied
Definition at line 546 of file KTBNAdaptiveLearner.h.
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), and learnKTBN().
|
private |
largest order to explore (candidates are kMin..kMax)
Definition at line 521 of file KTBNAdaptiveLearner.h.
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), _verifyBase_(), _verifyKernelArc_(), kMax(), learnKTBN(), and state().
|
private |
smallest order worth exploring (candidates are kMin..kMax). Starts at 2 and is recomputed by recomputeKMin() from the recorded slice-bearing constraints every time one is added or erased; never set directly. See recomputeKMin() for why it must be a recompute rather than an incremental raise/lower.
Definition at line 528 of file KTBNAdaptiveLearner.h.
Referenced by _raiseKMinForSlice_(), _recomputeKMin_(), learnKTBN(), and state().
|
private |
mandatory arcs, as (tail, head) engine-name pairs
Definition at line 595 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), _recomputeKMin_(), addMandatoryArc(), eraseMandatoryArc(), and state().
|
private |
mandatory kernel-relative arcs, same shape as forbiddenKernelArcs
Definition at line 613 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), _recomputeKMin_(), addMandatoryKernelArc(), eraseMandatoryKernelArc(), and state().
|
private |
Definition at line 583 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), setMaxIndegree(), and state().
|
private |
symbols in the CSVs to interpret as missing values
Definition at line 539 of file KTBNAdaptiveLearner.h.
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), _forEachScoredNode_(), and learnKTBN().
|
private |
Definition at line 569 of file KTBNAdaptiveLearner.h.
Referenced by _applyConfig_(), state(), and useLocalSearchWithTabuList().
|
private |
number of CSV files to read
Definition at line 518 of file KTBNAdaptiveLearner.h.
Referenced by KTBNAdaptiveLearner(), KTBNAdaptiveLearner(), _forEachScoredNode_(), and learnKTBN().
|
private |
leaf nodes (no children), as engine names
Definition at line 619 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), _recomputeKMin_(), addNoChildrenNode(), eraseNoChildrenNode(), and state().
|
private |
root nodes (no parents), as engine names
Definition at line 616 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), _recomputeKMin_(), addNoParentNode(), eraseNoParentNode(), and state().
|
private |
recorded cross-k order-selection criterion (the outer score used by learnKTBN() to pick the best k; independent of score)
Definition at line 562 of file KTBNAdaptiveLearner.h.
Referenced by _orderSelectionScore_(), state(), useOrderScoreAIC(), useOrderScoreBIC(), and useOrderScorefNML().
|
private |
MIIC candidate edges, as (tail, head) engine-name pairs.
Definition at line 598 of file KTBNAdaptiveLearner.h.
Referenced by _applyConstraints_(), _recomputeKMin_(), addPossibleEdge(), erasePossibleEdge(), and state().
|
private |
recorded prior and its weight
Definition at line 576 of file KTBNAdaptiveLearner.h.
Referenced by _applyConfig_(), checkScorePriorCompatibility(), state(), and useSmoothingPrior().
|
private |
optional variable-schema BN (set by the BN constructor): when present, each per-k KTBNLearner is built from it so the variable domains are fixed explicitly instead of inferred from trajectory 1. Null in CSV mode.
Definition at line 551 of file KTBNAdaptiveLearner.h.
Referenced by KTBNAdaptiveLearner(), and learnKTBN().
|
private |
Definition at line 577 of file KTBNAdaptiveLearner.h.
Referenced by _applyConfig_(), checkScorePriorCompatibility(), state(), and useSmoothingPrior().
|
private |
recorded per-k structure score (the inner score, replayed on each candidate)
Definition at line 558 of file KTBNAdaptiveLearner.h.
Referenced by _applyConfig_(), checkScorePriorCompatibility(), state(), useScoreAIC(), useScoreBD(), useScoreBDeu(), useScoreBIC(), useScorefNML(), useScoreLog2Likelihood(), and useScoreMDL().
|
private |
per-candidate (k, order-score) pairs from the last learnKTBN() run, in ascending k. One entry appended per candidate; read by scorePerCandidateK(). Cleared at the start of each learnKTBN() (empty while bestK == 0).
Definition at line 634 of file KTBNAdaptiveLearner.h.
Referenced by learnKTBN(), and scorePerCandidateK().
|
private |
tabu-list parameters (meaningful when algo is LOCAL_SEARCH_WITH_TABU_LIST)
Definition at line 568 of file KTBNAdaptiveLearner.h.
Referenced by _applyConfig_(), state(), and useLocalSearchWithTabuList().
| log_2 gum::learning::KTBNAdaptiveLearner< GUM_SCALAR >::C {r_i}_{N_{ij}}@f$ |
Select k by fNML (factorized Normalized Maximum Likelihood): keep the k whose learned model maximises .
Definition at line 279 of file KTBNAdaptiveLearner.h.