LearnFindings {RNetica} | R Documentation |
This function updates the conditional probabilities associated with
the given list of nodes based on the findings associated with that
node and its parents. Before calling this function the findings to be
learned should be set using NodeFinding
.
LearnFindings(nodes, weight = 1)
nodes |
A list of active |
weight |
The weight of the current observation in terms of number of observations. Negative weights unlearn previously learned cases. |
For the purposes of this function, Netica regards the probabilities in Row j of the CPT for each selected node as having an independent Dirichlet distribution with parameters (a_{j1},…,a_{jK}) = n_j (p_{j1},…,p_{jK}) where p_{jk} is the probability associated with State k in Row j and n_j is the experience associated with Row j.
If LearnFindings
is called on a node which is currently
instantiated to State k and whose parents are currently
instantiated to the configuration which selects Row j of the
table, then n'_j = n_j + weight and a'_{jk} =
a_{jk}+weight with all other values remaining the same. The new
conditional probabilities are p'_{jk} = a'_{jk}/n'_j.
The function FadeCPT
is often used between calls to
LearnFindings
to down weight old cases when the conditional
probabilities are thought to be changing slowly over time.
This returns the list of nodes whose conditional probability tables have been modified.
Do not confuse this function with NodeFinding
.
NodeFinding
instantiates a node and updates all of the other
beliefs associated with a node to reflect the new evidence.
LearnFindings
incorporates the current case (the currently
instantiated set of findings) into the CPTs for the nodes.
The LearnFindings
function will not update the conditional
probability table of a node unless NodeExperience
has
been set for that node. Instead it will issue a warning and update
the other nodes.
Russell G. Almond
http://norsys.com/onLineAPIManual/index.html: ReviseCPTsByFindings_bn()
NodeExperience
, NodeProbs
,
NodeFinding
, FadeCPT
,
RetractNetFindings
, LearnCases
,
LearnCPTs
sess <- NeticaSession() startSession(sess) abb <- CreateNetwork("ABB", session=sess) A <- NewDiscreteNode(abb,"A",c("A1","A2")) B1 <- NewDiscreteNode(abb,"B1",c("B1","B2")) B2 <- NewDiscreteNode(abb,"B2",c("B1","B2")) AddLink(A,B1) AddLink(A,B2) A[] <- c(.5,.5) NodeExperience(A) <- 10 B1["A1"] <- c(.8,.2) B1["A2"] <- c(.2,.8) B2["A1"] <- c(.8,.2) B2["A2"] <- c(.2,.8) NodeExperience(B1) <- c(10,10) NodeExperience(B2) <- c(10,10) ## First Case NodeFinding(A) <- "A1" NodeFinding(B1) <- "B1" NodeFinding(B2) <- "B2" LearnFindings(list(A,B1)) ## Probs for A & B1 modified, but B2 left alone stopifnot( NodeExperience(A)==11, NodeExperience(B1)==c(11,10), NodeExperience(B2)==c(10,10), sum(abs(NodeProbs(A) - c(6,5)/11)) < .001, sum(abs(B1[["A1"]] - c(9,2)/11)) < .001, sum(abs(B1[["A2"]] - c(2,8)/10)) < .001, sum(abs(B2[["A1"]] - c(8,2)/10)) < .001, sum(abs(B2[["A2"]] - c(2,8)/10)) < .001 ) ## Second Case RetractNetFindings(abb) NodeFinding(A) <- "A2" NodeFinding(B1) <- "B1" NodeFinding(B2) <- "B1" LearnFindings(list(A,B1)) ## Probs for A & B1 modified, but B2 left alone stopifnot( NodeExperience(A)==12, NodeExperience(B1)==c(11,11), NodeExperience(B2)==c(10,10), sum(abs(NodeProbs(A) - c(6,6)/12)) < .001, sum(abs(B1[["A1"]] - c(9,2)/11)) < .001, sum(abs(B1[["A2"]] - c(3,8)/11)) < .001, sum(abs(B2[["A1"]] - c(8,2)/10)) < .001, sum(abs(B2[["A2"]] - c(2,8)/10)) < .001 ) ## Retract Case 2 LearnFindings(list(A,B1),-1) ## Back to where we were before Case 1 stopifnot( NodeExperience(A)==11, NodeExperience(B1)==c(11,10), NodeExperience(B2)==c(10,10), sum(abs(NodeProbs(A) - c(6,5)/11)) < .001, sum(abs(B1[["A1"]] - c(9,2)/11)) < .001, sum(abs(B1[["A2"]] - c(2,8)/10)) < .001, sum(abs(B2[["A1"]] - c(8,2)/10)) < .001, sum(abs(B2[["A2"]] - c(2,8)/10)) < .001 ) DeleteNetwork(abb) stopSession(sess)