ftree.bdd.prob<-function(ftree, ft_node=1, bdd=NULL) {
if(length(bdd)==0) {
# generate the bdd
bdd<-ftree2bdd(ftree, ft_node)
# global FT and T1 objects now exist
}else{
# the ftree object is used to populate basic element probabilities
# there is no pre-validation that the elements in the provided bdd
# are present in the ftree object, but a stop is included in bdd.prob
FT<-ftree
}
## initialize the table to be used to store probability calculations that need not be repeated
## the dataframe object is actually a list of matched vectors, but appropriate here
T2<<-data.frame(bdd=NULL, ite_prob=NULL, stringsAsFactors=FALSE)
prob<-bdd.prob(bdd)
prob
}
bdd.prob<-function(bdd) {
if(!exists("FT")) stop("FT and a null T2 object are required in global environment")
if(bdd=="0") {return (0)
}else{
if(bdd=="1") {return (1)
}else{
## a table lookup occurs here
## with another else block
ite<-tx2ite(bdd)
## need to look up the probability for basic element with FT$prob[which( FT$Tag==ite$node)[1]]
nodeID<-which( FT$Tag==ite$node)
if(length(nodeID)==0) stop(paste0("undefined tag ", ite$node, " in ftree object"))
# prob<-FT$PBF[which( FT$Tag==ite$node)[1]]
prob<-FT$PBF[nodeID[1]]
LHS<-prob*bdd.prob(ite$X1)
RHS<-(1-prob) * bdd.prob(ite$X0)
ite_prob<-LHS+ RHS
## ite_prob<-prob*bdd.prob(as.character(ite$X.1)) + (1-prob) * bdd.prob(as.character(ite$X.0))
## add a line to a table of ite_prob calcs
T2line<-data.frame(bdd=bdd, ite_prob=ite_prob, stringsAsFactors=FALSE)
T2<<-rbind(T2, T2line)
return(ite_prob)
}
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.