k-order Dynamic Bayesian Networks (k-TBN)
A dynamic Bayesian network models a stochastic process by describing how the distribution over a set of variables at time \(t\) depends on the past. The classical 2-TBN limits that dependency to a single step backward (\(t-1\)). A k-order dynamic Bayesian network (k-TBN) generalizes this: a variable at time \(t\) may depend on any of the \(k\) most recent time slices \(t, t-1, \ldots, t-k+1\).
Rather than storing an (infinite) unrolled network, a k-TBN stores a compact template made of exactly \(k\) time slices. This template captures both the initial distribution (slices \(0, \ldots, k-2\)) and the transition kernel (slice \(k-1\), reused for every \(t \geq k-1\) since the process is time-homogeneous).
Two kinds of variables are distinguished:
temporal variables (processes), which evolve through time and are therefore represented by \(k\) instances (one per slice) in the template;
atemporal variables, which are constant through time (e.g. a static context parameter) and are represented by a single instance.
Internally, a temporal node is named with bracket notation: the \(t\)-th
instance of a process base is base[t] (e.g. \"X[0]\", \"X[1]\").
Atemporal variables keep their bare name. Most of the public API lets you
address a node either that way, or through an explicit (base, slice) pair,
slice being pyagrum.ktbn.KTBN.ATEMPORAL (-1) for an atemporal
variable.
A minimal example
import pyagrum as gum
import pyagrum.ktbn as ktbn
model = ktbn.KTBN(2) # order k=2
model.addTemporal("X[2]") # a binary process
model.addAtemporal("C[2]") # a binary static context
model.addArc("X", 0, "X", 1) # X[0] -> X[1]
model.addArc("C", ktbn.KTBN.ATEMPORAL, "X", 0)
model.generateCPTs() # or fillCPT(...) node by node
bn10 = model.unroll(10) # a plain BayesNet over 10 slices
ie = ktbn.KTBNInference(model)
ie.addObservation("X", 1, 1) # observe X[1] = 1
ie.addIntervention("C", ktbn.KTBN.ATEMPORAL, 0) # do(C = 0)
ie.addTarget("X")
ie.makeInference(5)
print(ie.posteriors("X")) # P(X[t] | ...) for t = 0..4
Tutorial
Input / Output
k-TBNs can be saved using the native JGUM / BGUM Format Reference.
ktbn.saveKTBN(model, "model.jgum") # jgum (JSON)
ktbn.saveKTBN(model, "model.bgum") # bgum (binary)
Reference
- The k-TBN model and its generator
KTBNKTBN.ATEMPORALKTBN.add()KTBN.addArc()KTBN.addAtemporal()KTBN.addTemporal()KTBN.arcs()KTBN.atemporalVarNames()KTBN.baseName()KTBN.bnToDot()KTBN.changeVariableName()KTBN.children()KTBN.clear()KTBN.cpt()KTBN.empty()KTBN.erase()KTBN.eraseArc()KTBN.exists()KTBN.existsArc()KTBN.fillCPT()KTBN.fromBN()KTBN.generateCPT()KTBN.generateCPTs()KTBN.k()KTBN.load()KTBN.nbAtemporalVars()KTBN.nbTemporalVars()KTBN.nodes()KTBN.parents()KTBN.save()KTBN.size()KTBN.sizeArcs()KTBN.summaryGraph()KTBN.temporalVarNames()KTBN.timeSlice()KTBN.toBN()KTBN.toDot()KTBN.toString()KTBN.toUnrolledDot()KTBN.unroll()KTBN.variable()
KTBNGenerator
- Inference in k-TBNs
KTBNInferenceKTBNInference.ATEMPORALKTBNInference.addIntervention()KTBNInference.addObservation()KTBNInference.addObservations()KTBNInference.addTarget()KTBNInference.clearInterventions()KTBNInference.clearObservation()KTBNInference.clearTargets()KTBNInference.eraseIntervention()KTBNInference.eraseObservation()KTBNInference.eraseTarget()KTBNInference.hasIntervention()KTBNInference.hasObservation()KTBNInference.interfaceSize()KTBNInference.isInTargetMode()KTBNInference.isTarget()KTBNInference.ktbn()KTBNInference.logObservationProbability()KTBNInference.makeInference()KTBNInference.observationProbability()KTBNInference.posterior()KTBNInference.posteriors()KTBNInference.toString()KTBNInference.windowJunctionTree()
- Learning k-TBNs
KTBNDatabaseGeneratorKTBNDatabaseGenerator.DiscretizedLabelMode_INTERVALKTBNDatabaseGenerator.DiscretizedLabelMode_MEDIANKTBNDatabaseGenerator.DiscretizedLabelMode_RANDOMKTBNDatabaseGenerator.VarOrderMode_ANTI_TOPOLOGICALKTBNDatabaseGenerator.VarOrderMode_RANDOMKTBNDatabaseGenerator.VarOrderMode_TOPOLOGICALKTBNDatabaseGenerator.drawSamples()KTBNDatabaseGenerator.nbVars()KTBNDatabaseGenerator.setDiscretizedLabelModeInterval()KTBNDatabaseGenerator.setDiscretizedLabelModeMedian()KTBNDatabaseGenerator.setDiscretizedLabelModeRandom()
KTBNLearnerKTBNLearner.addForbiddenArc()KTBNLearner.addForbiddenArcAllSlices()KTBNLearner.addForbiddenIntraSliceArc()KTBNLearner.addMandatoryArc()KTBNLearner.addNoChildrenNode()KTBNLearner.addNoParentNode()KTBNLearner.addPossibleEdge()KTBNLearner.allowArcAdditions()KTBNLearner.allowArcDeletions()KTBNLearner.allowArcReversals()KTBNLearner.checkScorePriorCompatibility()KTBNLearner.copyState()KTBNLearner.domainSize()KTBNLearner.domainSizes()KTBNLearner.eraseForbiddenArc()KTBNLearner.eraseForbiddenArcAllSlices()KTBNLearner.eraseForbiddenIntraSliceArc()KTBNLearner.eraseMandatoryArc()KTBNLearner.eraseNoChildrenNode()KTBNLearner.eraseNoParentNode()KTBNLearner.erasePossibleEdge()KTBNLearner.hasMissingValues()KTBNLearner.isConstraintBased()KTBNLearner.isIgnoringMissingSymbols()KTBNLearner.isScoreBased()KTBNLearner.k()KTBNLearner.latentVariables()KTBNLearner.learnKTBN()KTBNLearner.learnParameters()KTBNLearner.names()KTBNLearner.nbCols()KTBNLearner.nbDroppedRows()KTBNLearner.nbRows()KTBNLearner.nbSamples()KTBNLearner.setMaxIndegree()KTBNLearner.state()KTBNLearner.toString()KTBNLearner.useExtendedGreedyHillClimbing()KTBNLearner.useGreedyHillClimbing()KTBNLearner.useLocalSearchWithTabuList()KTBNLearner.useMDLCorrection()KTBNLearner.useMIIC()KTBNLearner.useNMLCorrection()KTBNLearner.useNoCorrection()KTBNLearner.useScoreAIC()KTBNLearner.useScoreBD()KTBNLearner.useScoreBDeu()KTBNLearner.useScoreBIC()KTBNLearner.useScoreLog2Likelihood()KTBNLearner.useScoreMDL()KTBNLearner.useScorefNML()KTBNLearner.useSmoothingPrior()
KTBNAdaptiveLearnerKTBNAdaptiveLearner.OrderScoreType_AICKTBNAdaptiveLearner.OrderScoreType_BICKTBNAdaptiveLearner.OrderScoreType_fNMLKTBNAdaptiveLearner.addForbiddenArc()KTBNAdaptiveLearner.addForbiddenArcAllSlices()KTBNAdaptiveLearner.addForbiddenIntraSliceArc()KTBNAdaptiveLearner.addForbiddenKernelArc()KTBNAdaptiveLearner.addMandatoryArc()KTBNAdaptiveLearner.addMandatoryKernelArc()KTBNAdaptiveLearner.addNoChildrenNode()KTBNAdaptiveLearner.addNoParentNode()KTBNAdaptiveLearner.addPossibleEdge()KTBNAdaptiveLearner.allowArcAdditions()KTBNAdaptiveLearner.allowArcDeletions()KTBNAdaptiveLearner.allowArcReversals()KTBNAdaptiveLearner.bestK()KTBNAdaptiveLearner.checkScorePriorCompatibility()KTBNAdaptiveLearner.eraseForbiddenArc()KTBNAdaptiveLearner.eraseForbiddenArcAllSlices()KTBNAdaptiveLearner.eraseForbiddenIntraSliceArc()KTBNAdaptiveLearner.eraseForbiddenKernelArc()KTBNAdaptiveLearner.eraseMandatoryArc()KTBNAdaptiveLearner.eraseMandatoryKernelArc()KTBNAdaptiveLearner.eraseNoChildrenNode()KTBNAdaptiveLearner.eraseNoParentNode()KTBNAdaptiveLearner.erasePossibleEdge()KTBNAdaptiveLearner.ignoreMissingSymbols()KTBNAdaptiveLearner.isIgnoringMissingSymbols()KTBNAdaptiveLearner.kMax()KTBNAdaptiveLearner.latentVariables()KTBNAdaptiveLearner.learnKTBN()KTBNAdaptiveLearner.scorePerCandidateK()KTBNAdaptiveLearner.setMaxIndegree()KTBNAdaptiveLearner.state()KTBNAdaptiveLearner.toString()KTBNAdaptiveLearner.useExtendedGreedyHillClimbing()KTBNAdaptiveLearner.useGreedyHillClimbing()KTBNAdaptiveLearner.useLocalSearchWithTabuList()KTBNAdaptiveLearner.useMDLCorrection()KTBNAdaptiveLearner.useMIIC()KTBNAdaptiveLearner.useNMLCorrection()KTBNAdaptiveLearner.useNoCorrection()KTBNAdaptiveLearner.useOrderScoreAIC()KTBNAdaptiveLearner.useOrderScoreBIC()KTBNAdaptiveLearner.useOrderScorefNML()KTBNAdaptiveLearner.useScoreAIC()KTBNAdaptiveLearner.useScoreBD()KTBNAdaptiveLearner.useScoreBDeu()KTBNAdaptiveLearner.useScoreBIC()KTBNAdaptiveLearner.useScoreLog2Likelihood()KTBNAdaptiveLearner.useScoreMDL()KTBNAdaptiveLearner.useScorefNML()KTBNAdaptiveLearner.useSmoothingPrior()