fwd_seq_gen: Calculate the order in which nodes in the dag should be...

View source: R/fwd_seq_gen.R

fwd_seq_genR Documentation

Calculate the order in which nodes in the dag should be traversed during the forward pass(roots to leaves)

Description

dag is a complex graphical model where we can have multiple parents and multiple children for a node. Hence the order in which the dag should be tranversed becomes significant. Forward algorithm is a dynamic programming problem where to calculate the values at a node, we need the values of the parent nodes beforehand, which need to be traversed before this node. This algorithm outputs a possible(not unique) order of the traversal of nodes ensuring that the parents are traversed first before the children.

Usage

fwd_seq_gen(hmm, nlevel = 100)

Arguments

hmm

hmm Object of class List given as output by initHMM

nlevel

No. of levels in the dag, if known. Default is 100

Value

Vector of length "D", where "D" is the number of nodes in the dag

See Also

forward

Examples

library(bnlearn)

tmat = matrix(c(0,0,1,0,0,0,0,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0),
               5,5, byrow= TRUE ) #for "X" (5 nodes) shaped dag
states = c("P","N") #"P" represent cases(or positive) and "N" represent controls(or negative)
bnet = model2network("[A][C|A:B][D|A:C][B|A]") #A is the target variable while
                                               #B, C and D are covariates
obsvA=data.frame(list(B=c("L","H","H","L","L"),C=c("H","H","L","L","H"),D=c("L","L","L","H","H")))
hmmA = initHMM(States=states, dagmat= tmat, net=bnet, observation=obsvA)
ft_sq = fwd_seq_gen(hmmA)

dagHMM documentation built on Jan. 11, 2023, 1:13 a.m.

Related to fwd_seq_gen in dagHMM...