accumulateEvidence: Merge evidence from an evidence set with the student record.

View source: R/EngineGears.R

accumulateEvidenceR Documentation

Merge evidence from an evidence set with the student record.

Description

The function accumulateEvidence combines the evidence in the EvidenceSet with the exiting beliefs in the StudentRecord, updating the student record. The function handleEvidence is a wrapper around this which takes care of finding and updating the evidence sets.

Usage

accumulateEvidence(eng, rec, evidMess, debug = 0)
handleEvidence(eng, evidMess, srser = NULL, debug = 0)

Arguments

eng

The BNEngine which controls the process.

rec

The StudentRecord which will be updated.

srser

A serialized version of the student record for the no-database version of the model.

evidMess

An EvidenceSet which has the evidence to be incorporated.

debug

An integer flag. If greater than 1, then recover() will be called at strategic places during the processing to allow inspection of the process.

Details

The function accumulateEvidence performs the following steps:

  1. Update the student record to associate it with the new evidence (updateRecord).

  2. Update the student model with the new evidence (updateSM).

  3. Update the statistics for the new student model (updateStats).

  4. Update the history for the new evidence (updateHist).

  5. Announce the availablity of new statistics (announceStats).

  6. Save the updated student record (saveSR).

The function handleEvidence is a wrapper around accumulateEvidence which finds the student record. Note for BNEngineNDB, it is expected that the student record will be passed in as a serialized object (see getRecordForUser). It performs the following steps:

  1. Fetch the student record for the uid associated with the evidence set (getRecordForUser).

  2. Mark the evidence as belonging to this student record (logEvidence).

  3. Update the record by calling accumulateEvidence.

  4. Mark the evidence as processed (markAsProcessed).

If an error is encountered, then the error message is added to the evidence set.

Value

The modified StudentRecord which was just processed. If an error occurs during the call to accumulateEvidence both function will return an object of class try-error instead of the student record.

Logging, Error Handling and Debugging

The functions handleEvidence, accumulateEvidence and many of the functions they call use the flog.logger protocol. The default logging level of INFO will give messages in response to the announcements and warnings when an error occur. The DEBUG and TRACE levels will provide more information about the details of the update algorithm.

The body of accumulateEvidence is wrapped in withFlogging which captures and logs errors. This function returns an object of class try-error when an error occurs. Although handleEvidence does not use the flogging error handler, it will still pass on the try-error if one is generated.

The debug argument can be used to pause execution. Basically, recover() will be called between every step. This only happens in interactive mode as it just does not make sense in batch model.

Known Bugs

There is a bug in version 5.04 of Netica which causes the absorbNodes function when called with a node that does not have display information to generate an internal Netica error. This has been fixed with version 6.07, which is currently in beta release (Linux only).

To work around, make sure that either all nodes do not have display information, or that all do.

Author(s)

Russell Almond

References

Almond, Mislevy, Steinberg, Yan and Williamson (2015). Bayesian Networks in Educational Assessment. Springer. Especially Chapters 5 and 13.

See Also

Classes: BNEngine BNEngineMongo, BNEngineNDB StudentRecord, EvidenceSet

Main Loop Functions: mainLoop, getRecordForUser, logEvidence, updateRecord, updateSM, updateStats, updateHist, announceStats, saveSR

Examples



## Requires database setup, also PNetica
library(RNetica)  ## 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("Physics")
configStats(eng,stattab)
setupDefaultSR(eng)

sr0 <- getRecordForUser(eng,"S1")

eap0 <- stat(sr0,"Physics_EAP")

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

e1 <- logEvidence(eng,sr0,e1)
sr1 <- accumulateEvidence(eng,sr0,e1)
stopifnot(!is(sr1,'try-error'))
stopifnot(m_id(sr1)!=m_id(sr0),sr1@prev_id==m_id(sr0))
stopifnot(seqno(sr1)==1L, seqno(e1)==1L)

eap1 <- stat(sr1,"Physics_EAP")
stopifnot(abs(eap1-eap0) > .001)
stopifnot(nrow(history(sr1,"Physcis"))==2L)

## handle Evidence.
sr1.ser <- as.json(sr1)
e2 <- EvidenceSet(uid="S2",app="Test",context="PPconjEM",
                  obs=list("ConjunctiveObs"="Wrong"))

sr2 <- handleEvidence(eng,e2,jsonlite::fromJSON(sr1.ser))
stopifnot(!is(sr2,'try-error'))
eap2 <- stat(sr2,"Physics_EAP")
stopifnot(uid(sr2)==uid(sr1),
          m_id(sr1)==sr2@prev_id,
          nrow(history(sr2,"Physics"))==3L,
          abs(eap1-eap2) > .001)

## <<HERE>> Need test with Mongo engine.





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