aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
KTBNAdaptiveLearner.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
69
70#ifndef GUM_LEARNING_KTBN_ADAPTIVE_LEARNER_H
71#define GUM_LEARNING_KTBN_ADAPTIVE_LEARNER_H
72
73#include <limits>
74#include <memory>
75#include <set>
76#include <string>
77#include <tuple>
78#include <utility>
79#include <vector>
80
81#include <agrum/agrum.h>
82
83#include <agrum/KTBN/KTBN.h>
85
86#include <string_view>
87#include <unordered_set>
88
89namespace gum {
90
91 namespace learning {
92
103 template < GUM_Numeric GUM_SCALAR >
104 class KTBNAdaptiveLearner: public IKTBNLearner< GUM_SCALAR > {
105 public:
106 // #######################################################################
108 // #######################################################################
110
138 KTBNAdaptiveLearner(std::string_view dirPath,
139 std::string_view csvBaseName,
140 Size nbSamples,
141 Size kMax,
142 const std::unordered_set< std::string >& atemporalVars,
143 const std::vector< std::string >& missingSymbols = {"?"},
144 bool induceTypes = true);
145
185 KTBNAdaptiveLearner(std::string_view dirPath,
186 std::string_view csvBaseName,
187 Size nbSamples,
188 Size kMax,
189 const std::vector< std::string >& missingSymbols = {"?"},
190 bool induceTypes = true);
191
214 KTBNAdaptiveLearner(std::string_view dirPath,
215 std::string_view csvBaseName,
216 Size nbSamples,
217 Size kMax,
218 const BayesNet< GUM_SCALAR >& bn,
219 const std::unordered_set< std::string >& atemporalVars = {},
220 const std::vector< std::string >& missingSymbols = {"?"});
221
223
225 // #######################################################################
227 // #######################################################################
229
235 KTBN< GUM_SCALAR > learnKTBN() override;
236
239 Size bestK() const;
240
247 const std::vector< std::pair< Size, double > >& scorePerCandidateK() const;
248
254 const std::vector< std::pair< std::string, std::string > >& latentVariables() const;
255
257 // #######################################################################
259 // #######################################################################
261
266 enum class OrderScoreType { BIC, AIC, fNML };
267
271
276
284
286 // #######################################################################
288 // #######################################################################
290
328
330 bool isIgnoringMissingSymbols() const;
331
333 // #######################################################################
335 // #######################################################################
337
339 Size kMax() const;
340
345 std::string checkScorePriorCompatibility() const;
346
350 std::string toString() const;
351
354 std::vector< std::tuple< std::string, std::string, std::string > > state() const;
355
357 // #######################################################################
359 // #######################################################################
361
368 void useScorefNML() override;
369
371 // #######################################################################
373 // #######################################################################
375
379 Size nb_decrease = 2) override;
381
383 // #######################################################################
385 // #######################################################################
387
391
393 // #######################################################################
395 // #######################################################################
397
398 KTBNAdaptiveLearner< GUM_SCALAR >& useSmoothingPrior(double weight = 1.0) override;
399
401 // #######################################################################
403 // #######################################################################
405
406 KTBNAdaptiveLearner< GUM_SCALAR >& addForbiddenArc(std::string_view tailNode,
407 std::string_view headNode) override;
408 KTBNAdaptiveLearner< GUM_SCALAR >& addForbiddenArc(std::string_view tailBase,
409 int tailSlice,
410 std::string_view headBase,
411 int headSlice) override;
412 KTBNAdaptiveLearner< GUM_SCALAR >& eraseForbiddenArc(std::string_view tailNode,
413 std::string_view headNode) override;
414 KTBNAdaptiveLearner< GUM_SCALAR >& eraseForbiddenArc(std::string_view tailBase,
415 int tailSlice,
416 std::string_view headBase,
417 int headSlice) override;
418
419 KTBNAdaptiveLearner< GUM_SCALAR >& addMandatoryArc(std::string_view tailNode,
420 std::string_view headNode) override;
421 KTBNAdaptiveLearner< GUM_SCALAR >& addMandatoryArc(std::string_view tailBase,
422 int tailSlice,
423 std::string_view headBase,
424 int headSlice) override;
425 KTBNAdaptiveLearner< GUM_SCALAR >& eraseMandatoryArc(std::string_view tailNode,
426 std::string_view headNode) override;
427 KTBNAdaptiveLearner< GUM_SCALAR >& eraseMandatoryArc(std::string_view tailBase,
428 int tailSlice,
429 std::string_view headBase,
430 int headSlice) override;
431
442 addForbiddenKernelArc(std::string_view tailBase, int lag, std::string_view headBase);
443
447 eraseForbiddenKernelArc(std::string_view tailBase, int lag, std::string_view headBase);
448
457 addMandatoryKernelArc(std::string_view tailBase, int lag, std::string_view headBase);
458
462 eraseMandatoryKernelArc(std::string_view tailBase, int lag, std::string_view headBase);
463
465 addForbiddenIntraSliceArc(std::string_view tailBase, std::string_view headBase) override;
467 eraseForbiddenIntraSliceArc(std::string_view tailBase,
468 std::string_view headBase) override;
469
471 addForbiddenArcAllSlices(std::string_view tailBase, std::string_view headBase) override;
473 eraseForbiddenArcAllSlices(std::string_view tailBase, std::string_view headBase) override;
474
475 KTBNAdaptiveLearner< GUM_SCALAR >& addNoParentNode(std::string_view base, int slice) override;
476 KTBNAdaptiveLearner< GUM_SCALAR >& addNoParentNode(std::string_view name) override;
478 int slice) override;
479 KTBNAdaptiveLearner< GUM_SCALAR >& eraseNoParentNode(std::string_view name) override;
480
482 int slice) override;
483 KTBNAdaptiveLearner< GUM_SCALAR >& addNoChildrenNode(std::string_view name) override;
485 int slice) override;
486 KTBNAdaptiveLearner< GUM_SCALAR >& eraseNoChildrenNode(std::string_view name) override;
487
488 KTBNAdaptiveLearner< GUM_SCALAR >& addPossibleEdge(std::string_view tailBase,
489 int tailSlice,
490 std::string_view headBase,
491 int headSlice) override;
493 std::string_view head) override;
494 KTBNAdaptiveLearner< GUM_SCALAR >& erasePossibleEdge(std::string_view tailBase,
495 int tailSlice,
496 std::string_view headBase,
497 int headSlice) override;
499 std::string_view head) override;
500
501 KTBNAdaptiveLearner< GUM_SCALAR >& allowArcAdditions(bool allow = true) override;
502 KTBNAdaptiveLearner< GUM_SCALAR >& allowArcDeletions(bool allow = true) override;
503 KTBNAdaptiveLearner< GUM_SCALAR >& allowArcReversals(bool allow = true) override;
505
507
508 private:
509 // ----- data source (kept so a KTBNLearner can be built per candidate k) -----
510
512 std::string _dirPath_;
513
515 std::string _csvBaseName_;
516
519
522
529
531 std::unordered_set< std::string > _atemporalVars_;
532
536 std::unordered_set< std::string > _baseNames_;
537
539 std::vector< std::string > _missingSymbols_;
540
543
547
551 std::unique_ptr< BayesNet< GUM_SCALAR > > _prior_bn_;
552
553 // ----- recorded state parameters (replayed on each candidate k) -----
554 // Defaults mirror IBNLearner's own defaults, so an unconfigured
555 // KTBNAdaptiveLearner behaves like an unconfigured KTBNLearner.
556
559
563
566
570
574
577 double _priorWeight_{1.0};
578
583 Size _maxIndegree_{std::numeric_limits< Size >::max()};
584
585 // ----- recorded constraints (replayed on each candidate k) -----
586 // Everything is stored by name: NodeIds are meaningless here because the
587 // internal NodeId spaces differ from one candidate k to another. Arcs and
588 // edges are stored as engine-name pairs ("X[1]", "C", ...); the per-base
589 // constraints (intra-slice / all-slices) are stored as base-name pairs.
590
592 std::set< std::pair< std::string, std::string > > _forbiddenArcs_;
593
595 std::set< std::pair< std::string, std::string > > _mandatoryArcs_;
596
598 std::set< std::pair< std::string, std::string > > _possibleEdges_;
599
601 std::set< std::pair< std::string, std::string > > _forbiddenIntraSliceArcs_;
602
604 std::set< std::pair< std::string, std::string > > _forbiddenArcsAllSlices_;
605
610 std::set< std::tuple< std::string, std::string, int > > _forbiddenKernelArcs_;
611
613 std::set< std::tuple< std::string, std::string, int > > _mandatoryKernelArcs_;
614
616 std::set< std::string > _noParentNodes_;
617
619 std::set< std::string > _noChildrenNodes_;
620
625
629 std::vector< std::pair< std::string, std::string > > _bestLatentVariables_;
630
634 std::vector< std::pair< Size, double > > _scorePerCandidateK_;
635
636 // ----- construction (runs once, in the constructor) -----
637
643 static std::unordered_set< std::string >
644 _inferAtemporalVars_(std::string_view dirPath,
645 std::string_view csvBaseName,
646 Size nbSamples,
647 Size kMax,
648 const std::vector< std::string >& missingSymbols);
649
650 // ----- name encoding -----
651
654 const std::unordered_set< std::string >& _atemporalVarNames_() const override;
655
658 bool _isKnownBase_(std::string_view base) const override;
659
662 using IKTBNLearner< GUM_SCALAR >::_encode_;
663 using IKTBNLearner< GUM_SCALAR >::_determineNode_;
664 using IKTBNLearner< GUM_SCALAR >::_checkBaseIsTemporal_;
665
666 // ----- validation -----
667
673 void _verifyBase_(std::string_view base, int slice) const;
674
682 void _verifyKernelArc_(std::string_view tailBase, std::string_view headBase, int lag) const;
683
684 // ----- candidate-range bookkeeping -----
685
691 void _raiseKMinForSlice_(int slice);
692
699 void _recomputeKMin_();
700
701 // ----- configuration replay (used by learnKTBN() for each candidate k) -----
702
709 void _applyConfig_(KTBNLearner< GUM_SCALAR >& learner) const;
710
716 void _applyConstraints_(KTBNLearner< GUM_SCALAR >& learner, Size k) const;
717
718 // ----- model selection (learnKTBN() helper) -----
719
732 template < typename PerInstance, typename PerNodeFinal >
733 void _forEachScoredNode_(const KTBN< GUM_SCALAR >& net,
734 PerInstance perInstance,
735 PerNodeFinal perNodeFinal) const;
736
743 double _log2Likelihood_(const KTBN< GUM_SCALAR >& net) const;
744
752 double _countParameters_(const KTBN< GUM_SCALAR >& net) const;
753
760 double _fNMLScore_(const KTBN< GUM_SCALAR >& net) const;
761
766 double _orderSelectionScore_(const KTBN< GUM_SCALAR >& net, double logN) const;
767
772
773 // forbidden copies / moves (same policy as KTBNLearner)
777 = delete;
779 };
780
781#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
782 extern template class GUM_PUBLIC_KTBN KTBNAdaptiveLearner< double >;
783#endif
784
785 } /* namespace learning */
786} /* namespace gum */
787
789
790#endif /* GUM_LEARNING_KTBN_ADAPTIVE_LEARNER_H */
Implementation of the KTBNAdaptiveLearner class.
A structure/parameter learner for k-order dynamic Bayesian networks.
Class representing k-order dynamic Bayesian networks (k-DBN).
the class for computing the log2 of the parametric complexity of an r-ary multinomial variable
KModeTypes
the description type for the complexity correction
AlgoType
an enumeration to select easily the learning algorithm to use
Definition IBNLearner.h:125
ScoreType
an enumeration enabling to select easily the score we wish to use
Definition IBNLearner.h:109
BNLearnerPriorType
an enumeration to select the prior
Definition IBNLearner.h:116
Pure-virtual configuration interface shared by all k-TBN learners.
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 <cont...
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 t...
Learns a k-TBN (order k + structure + parameters) from trajectory CSVs.
std::string toString() const
Human-readable summary of the recorded configuration (candidate order range, algorithm / score / corr...
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 sli...
bool _induceTypes_
whether numeric columns are retyped (see KTBNLearner); unused (and forced false) when a schema BN is ...
std::set< std::string > _noParentNodes_
root nodes (no parents), as engine names
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 sli...
std::vector< std::string > _missingSymbols_
symbols in the CSVs to interpret as missing values
std::unordered_set< std::string > _atemporalVars_
base names of the atemporal (static) variables
bool _allowAdditions_
recorded graph-change permissions / indegree cap
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-relat...
KTBNAdaptiveLearner< GUM_SCALAR > & useOrderScoreBIC()
Select k by BIC (the default): keep the k whose learned model maximises .
std::unique_ptr< BayesNet< GUM_SCALAR > > _prior_bn_
optional variable-schema BN (set by the BN constructor): when present, each per-k KTBNLearner is buil...
Size _bestK_
k selected by the last learnKTBN() call, or 0 as a sentinel while no learning has happened yet....
std::string _dirPath_
directory holding the trajectory CSV files
Size _kMax_
largest order to explore (candidates are kMin..kMax)
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 sli...
bool _isKnownBase_(std::string_view base) const override
whether base is one of this learner's variables; the base names read at construction,...
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 sli...
KTBNAdaptiveLearner< GUM_SCALAR > & useNMLCorrection() override
void _applyConstraints_(KTBNLearner< GUM_SCALAR > &learner, Size k) const
Replay the recorded structural constraints onto learner (built for order k). Engine-name constraints ...
std::vector< std::pair< std::string, std::string > > _bestLatentVariables_
latent-variable arcs (engine-name pairs) reported by the winning candidate's MIIC run,...
IBNLearner::BNLearnerPriorType _prior_
recorded prior and its weight
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 o...
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 varia...
std::set< std::string > _noChildrenNodes_
leaf nodes (no children), as engine names
KTBNAdaptiveLearner< GUM_SCALAR > & useGreedyHillClimbing() override
double _fNMLScore_(const KTBN< GUM_SCALAR > &net) const
fNML order score of net over the recorded trajectories: , with the node's domain size and the count...
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 sli...
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 li...
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 sli...
IBNLearner::AlgoType _algo_
recorded structure-learning algorithm
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....
OrderScoreType _orderScore_
recorded cross-k order-selection criterion (the outer score used by learnKTBN() to pick the best k; i...
Size kMax() const
Largest order explored (the kMax argument of the constructor).
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 sli...
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 sli...
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< GUM_SCALAR > & useSmoothingPrior(double weight=1.0) override
bool _ignoreMissingSymbols_
whether incomplete rows/instances are dropped (see ignoreMissingSymbols())
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 sli...
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 sli...
std::set< std::pair< std::string, std::string > > _forbiddenArcsAllSlices_
forbidden all-slices arcs, as (tailBase, headBase) pairs
KTBNAdaptiveLearner< GUM_SCALAR > & operator=(const KTBNAdaptiveLearner< GUM_SCALAR > &)=delete
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 sli...
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.
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....
const std::unordered_set< std::string > & _atemporalVarNames_() const override
atemporal base names for IKTBNLearner's shared encode/_determineNode_; the set recorded at constructi...
IBNLearner::ScoreType _score_
recorded per-k structure score (the inner score, replayed on each candidate)
KTBNAdaptiveLearner< GUM_SCALAR > & useScoreBDeu() override
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 > > _forbiddenIntraSliceArcs_
forbidden intra-slice arcs, as (tailBase, headBase) pairs
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 sli...
Size bestK() const
Order k selected by the last learnKTBN() call.
KTBNAdaptiveLearner(KTBNAdaptiveLearner< GUM_SCALAR > &&)=delete
bool isIgnoringMissingSymbols() const
Whether incomplete rows and instances are dropped. False by default.
Size _nbSamples_
number of CSV files to read
KTBNAdaptiveLearner< GUM_SCALAR > & useScoreMDL() override
double _log2Likelihood_(const KTBN< GUM_SCALAR > &net) const
Factorized log2-likelihood of net over the recorded trajectories, comparable across candidate k (the ...
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 > & useScoreAIC() override
void _applyConfig_(KTBNLearner< GUM_SCALAR > &learner) const
Apply the recorded score / algorithm / correction / prior onto a freshly-built learner....
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 > & useExtendedGreedyHillClimbing() override
Size _kMin_
smallest order worth exploring (candidates are kMin..kMax). Starts at 2 and is recomputed by recomput...
std::set< std::tuple< std::string, std::string, int > > _mandatoryKernelArcs_
mandatory kernel-relative arcs, same shape as forbiddenKernelArcs
log_2 where the penalty replaces BIC s KTBNAdaptiveLearner< GUM_SCALAR > & useOrderScorefNML()
by a sum of per-node, per-parent-configuration multinomial parametric complexities (regret) – data-de...
OrderScoreType
The criterion learnKTBN() uses to pick the best among the candidates — the outer score,...
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 sli...
void _recomputeKMin_()
Recompute kMin from scratch: max(2, 1 + the largest concrete slice named by any recorded forbidden/ma...
KTBNAdaptiveLearner< GUM_SCALAR > & useMDLCorrection() override
std::vector< std::pair< Size, double > > _scorePerCandidateK_
per-candidate (k, order-score) pairs from the last learnKTBN() run, in ascending k....
VariableLog2ParamComplexity _ctable_
cache of log2 of the multinomial parametric complexity C^r_n, used by the fNML order penalty....
double _countParameters_(const KTBN< GUM_SCALAR > &net) const
Number of free parameters of net's template: summed over every template node (all initial slices,...
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 sli...
std::vector< std::tuple< std::string, std::string, std::string > > state() const
The recorded configuration as (key, value, comment) tuples (mirrors KTBNLearner::state()); toString()...
KTBNAdaptiveLearner< GUM_SCALAR > & operator=(KTBNAdaptiveLearner< GUM_SCALAR > &&)=delete
KTBN< GUM_SCALAR > learnKTBN() override
Learns the best k in [kMin, kMax] together with the structure and the CPTs: one KTBNLearner is built ...
KTBNAdaptiveLearner< GUM_SCALAR > & useScoreLog2Likelihood() override
std::unordered_set< std::string > _baseNames_
all base variable names (temporal + atemporal), read from the first trajectory CSV header at construc...
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 sli...
KTBNAdaptiveLearner< GUM_SCALAR > & ignoreMissingSymbols(bool ignore=true)
Learn and score on the fully observed data only, dropping every row and every scoring instance that c...
void _raiseKMinForSlice_(int slice)
Raise kMin, if needed, so that kMin > slice: a smaller candidate would silently drop a constraint nam...
KTBNAdaptiveLearner< GUM_SCALAR > & useOrderScoreAIC()
Select k by AIC: keep the k whose learned model maximises (a lighter, sample-size-independent comple...
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...
std::string _csvBaseName_
stem of each trajectory file name
Size _tabuSize_
tabu-list parameters (meaningful when algo is LOCAL_SEARCH_WITH_TABU_LIST)
KTBNAdaptiveLearner< GUM_SCALAR > & useLocalSearchWithTabuList(Size tabu_size=100, Size nb_decrease=2) override
KTBNAdaptiveLearner(const KTBNAdaptiveLearner< GUM_SCALAR > &)=delete
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()...
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 sli...
KTBNAdaptiveLearner< GUM_SCALAR > & useScoreBD() override
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 sli...
KTBNAdaptiveLearner< GUM_SCALAR > & useScoreBIC() override
CorrectedMutualInformation::KModeTypes _correction_
recorded MIIC correction
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 sli...
KTBNAdaptiveLearner< GUM_SCALAR > & useNoCorrection() override
KTBNAdaptiveLearner< GUM_SCALAR > & useMIIC() override
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 sli...
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 -> he...
std::string checkScorePriorCompatibility() const
Warning string if the recorded score and prior are incompatible, empty otherwise. Data-free: it evalu...
Learns a k-TBN (structure and/or parameters) from trajectory CSVs.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
include the inlined functions if necessary
Definition CSVParser.h:55
template class GUM_PUBLIC_KTBN KTBNAdaptiveLearner< double >
gum is the global namespace for all aGrUM entities
Definition agrum.h:46