updateHist: Update the node history in a student record

View source: R/EngineGears.R

updateHistR Documentation

Update the node history in a student record

Description

The StudentRecord object can track the history of zero or more Pnode in the student model (sm). The history is a data frame with columns corresponding to the states of the variables and the rows corresponding to the EvidenceSets absorbed into the student record. The function updateHist add a new row to each history corresponding to the evidence set. The function baselineHist creates the initial row.

Usage

updateHist(eng, rec, evidMess, debug = 0)
baselineHist(eng, rec)

Arguments

eng

The BNEngine controlling the operation.

rec

The StudentRecord which will be updated.

evidMess

The EvidenceSet which has just been added to the student model using updateSM.

debug

An integer flag. If bigger than 1, then a call to recover will be made inside the function call.

Details

A history tracks a single node in the student model as it changes in response to the incomming evidence sets. The history for a node is data frame with columns representing variable states and rows representing evidence sets (evidence from different scoring windows or tasks).

The function baselineHist is called as part of setupDefaultSR. This initializes a history data frame for each node in the histNodes field of the BNEngine. It inserts a first row, which is always given the name “*Baseline*”. The values in the first row are the marginal distribution of those nodes (PnodeMargin).

The function updateHist adds row to each history table. The name of the row corresponds to the context field of the EvidenceSet. The value is the curent marginal distribution for the history nodes.

The function history retrieves the history. The functions woeHist and woeBal in the CPTtools-package describe possible applications for the history function.

Value

Both functions return the modified StudentRecord

Note

With the Netica implementation, the student model needs to be compiled (PnetCompile(sm(rec))) before the baselineHist function is run.

This is probably true of updateHist as well, but updateSM recompiles the network.

Author(s)

Russell Almond

References

Madigan, Mosurski and Almond, (1997). Graphical explanation in belief networks. Journal of Computational and Graphical Statistics, 6, 160–181.

Almond, Kim, Shute and Ventura (2013). Debugging the evidence chain. Proceeings of the 2013 UAI Application Workshops (UAI2013AW). 1–10. CEUR workshop proceedings, vol 1024. http://ceur-ws.org/Vol-1024/paper-01.pdf

See Also

Classes: BNEngine, EvidenceSet StudentRecord

Functions in EABN: accumulateEvidence, updateStats, updateSM, history

Peanut Functions: PnodeMargin

CPTtools Functions woeHist, woeBal

Examples



## Requires PNetica
library(PNetica)  ## Must load to setup Netica DLL
app <- "ecd://epls.coe.fsu.edu/EITest"
sess <- RNetica::NeticaSession()
RNetica::startSession(sess)

config.dir <- file.path(library(help="Peanut")$path, "auxdata")
net.dir <- file.path(library(help="PNetica")$path,"testnets")

netman <- read.csv(file.path(config.dir, "Mini-PP-Nets.csv"),
                    row.names=1, stringsAsFactors=FALSE)
stattab <- read.csv(file.path(config.dir, "Mini-PP-Statistics.csv"),
                    as.is=TRUE)

Nethouse <- PNetica::BNWarehouse(netman,session=sess,
             address=net.dir)

cl <- new("CaptureListener")
listeners <- list("cl"=cl)

ls <- ListenerSet(sender= paste("EAEngine[",app,"]"),
                  db=MongoDB(noMongo=TRUE), listeners=listeners)

eng <- newBNEngineNDB(app=app,warehouse=Nethouse,
                     listenerSet=ls,manifest=netman,
                     profModel="miniPP_CM",
                     histNodes="Physics",
                     statmat=stattab,
                     activeTest="EAActive.txt")

## Standard initialization methods.                     
loadManifest(eng,netman)
eng$setHistNodes(character())
configStats(eng,stattab)
setupDefaultSR(eng)



sr1 <- getRecordForUser(eng,"S1")
history(sr1,"Physics")
stopifnot(is.null(history(sr1,"Physics")))

## Now set up history.
eng$setHistNodes("Physics")
PnetCompile(sm(sr1))
sr1 <- baselineHist(eng,sr1)  
history(sr1,"Physics")
stopifnot(nrow(history(sr1,"Physics"))==1L)

e1 <- EvidenceSet(uid="S1",app="Test",context="PPcompEM",
                  obs=list("CompensatoryObs"="Right"))
sr1 <- updateSM(eng,sr1,e1)
sr1 <- updateHist(eng,sr1,e1)

e2 <- EvidenceSet(uid="S1",app="Test",context="PPconjEM",
                  obs=list("ConjunctiveObs"="Wrong"))
sr1 <- updateSM(eng,sr1,e2)
sr1 <- updateHist(eng,sr1,e2)

history(sr1,"Physics")
stopifnot(nrow(history(sr1,"Physcis"))==3L)
woeHist(history(sr1,"Physics"),pos="High",neg=c("Medium","Low"))




ralmond/EABN documentation built on Aug. 30, 2023, 12:52 p.m.