LearnCases {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 found in the caseStream
argument, which
should be a CaseStream
object.
LearnCases(caseStream, nodelist, weight = 1)
caseStream |
This should be a |
nodelist |
A list of active |
weight |
A multiplier for the weights of the cases in terms of number of observations. Negative weights unlearn previously learned cases. |
This is like calling the function LearnFindings
repeatedly with the values of the nodes set to each of the case rows
in turn. Thus, it updates the conditional probability tables for each
nodes based on observed counts in the case files, taking the current
probability and the NodeExperience
as the prior
distribution.
If the case stream has a column NumCases
, then the weight
assigned to Row j is weight*NumCases[j]
. If the case
stream does not have such a column, then it is treated as if each
column has weight 1. (Among other purposes, this allows case data to
be stored in a compact format where all of the possible cases are
enumerated along with a count of repetitions.) Note that negative
weights will unlearn cases.
This function returns the CaseStream
used in the
analysis. This might have either been passed directly as the
caseStream
argument, or created from the value of the
caseStream
argument. In either case, the stream is closed at
the end of the function.
In version 5.04 of the Netica API, there is a problem with using
Memory Streams that seems to affect the functions
LearnCases
and LearnCPTs
. Until this
problem is fixed, most uses of Memory Streams will require file
streams instead. Write the case file using
write.CaseFile
, and then create a file stream using
CaseFileStream
.
To learn without using the current probabilities as priors, call
DeleteNodeTable
first.
Russell Almond
http://norsys.com/onLineAPIManual/index.html: ReviseCPTsByCaseFile_bn()
NodeExperience
, NodeProbs
,
NodeFinding
, FadeCPT
,
LearnFindings
, DeleteNodeTable
,
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) casesabb <- data.frame(A=c("A1","A1","A1","A1","A1","A2","A2","A2","A2","A2"), B1=c("B1","B1","B1","B2","B2","B2","B2","B2","B1","B1"), B2=c("B1","B1","B1","B1","B2","B2","B2","B2","B2","B1")) ## LearnCases(casesabb,list(A,B1)) ## There is currently a bug in Netica, so that this function does not ## work with memory streams. As a work around, use proper file streams ## instead. outfile <- tempfile("casesabb",fileext=".cas") write.CaseFile(casesabb,outfile, session=sess) LearnCases(outfile,list(A,B1)) ## Probs for A & B1 modified, but B2 left alone stopifnot( NodeExperience(A)==20, NodeExperience(B1)==c(15,15), NodeExperience(B2)==c(10,10), sum(abs(NodeProbs(A) - .5)) < .001, sum(abs(B1["A1",drop=TRUE] - c(11,4)/15)) < .001, sum(abs(B1["A2",drop=TRUE] - c(4,11)/15)) < .001, sum(abs(B2["A1",drop=TRUE] - c(8,2)/10)) < .001, sum(abs(B2["A2",drop=TRUE] - c(2,8)/10)) < .001 ) DeleteNetwork(abb) stopSession(sess)