WriteFindings {RNetica}R Documentation

Appends the current findings to a Netica case file.

Description

This function writes the current findings for a network as a row in a Netica case file. If filename already exists, the new row is appended on the end of the file. Variables that are not instantiated are written out using the missing code.

Usage

WriteFindings(nodes, pathOrStream, id = -1L, freq = -1.0)

Arguments

nodes

The a list of active NeticaNode objects to be written out.

pathOrStream

Either a character scalar giving the path name of the file to which the results are to be written, or a CaseStream object. It is recommended that it have the extension “.cas”.

id

An integer scalar giving the case ID. The default value of -1 suppresses the writing of cases. If an ID is supplied for the first case, it should be supplied for all cases.

freq

An integer scalar giving the number of cases with the currently instantiated set of findings. The default value -1 suppresses writing the cases, implicitly assuming that all cases have weight 1. If supplied for the first row, this should be supplied for all rows.

Details

A case file is a table where the rows represent cases, and the columns represent variables. WriteFindings writes out the currently instantiated value of the nodes in nodeset. If a node in nodeset does not currently have a finding attached, then the value of CaseFileMissingCode() is printed out instead. The values in the columns are separated by the value of CaseFileDelimiter().

There are two special columns in the file. The column “IDnum” is set to the value id, which should contain an integer case number. The column “NumCases” is set to the value of freq which should give a weight to assign to the case (in various algorithms when freq is supplied, it is treated as if that case was repeated weight times). Assigning either of these fields a value of -1 means the corresponding column is appended to the output.

The function WriteFindings will create a new file associated with filename if it does not exist. In that case it will write out a header row containing the variable names followed by the current findings as the first case row. Subsequent calls to WriteFindings with the same filename append additional rows to the end of the file. In such cases, the nodelist should be the same, and if id or freq was -1, it should be in the following calls as well.

Value

Returns the caseOrStream argument invisibly. Note that the values of getCaseStreamPos(stream), getCaseStreamLastId(stream), and getCaseStreamLastFreq(stream) will be updated to reflect the values from the last read record.

Author(s)

Russell G. Almond

References

http://norsys.com/onLineAPIManual/index.html: WriteNetFindings_bn()

See Also

CaseFileDelimiter, CaseFileMissingCode, NodeFinding, RetractNetFindings ReadFindings, CaseStream

Examples

sess <- NeticaSession()
startSession(sess)

abc <- CreateNetwork("ABC", session=sess)
A <- NewDiscreteNode(abc,"A",c("A1","A2","A3","A4"))
B <- NewDiscreteNode(abc,"B",c("B1","B2","B3"))
C <- NewDiscreteNode(abc,"C",c("C1","C2"))

AddLink(A,B)
AddLink(A,C)
AddLink(B,C)

## Outputfilename
casefile <- tempfile("testcase",fileext=".cas")
filestream <- CaseFileStream(casefile, session=sess)
stopifnot(is.CaseFileStream(filestream),
          isCaseStreamOpen(filestream))

## Case 1
NodeFinding(A) <- "A1"
NodeFinding(B) <- "B1"
NodeFinding(C) <- "C1"
WriteFindings(list(A,B,C),casefile,1)
RetractNetFindings(abc)

## Case 2
NodeFinding(A) <- "A2"
NodeFinding(B) <- "B2"
NodeFinding(C) <- "C2"
WriteFindings(list(A,B,C),casefile,2)
RetractNetFindings(abc)

## Case 3
NodeFinding(A) <- "A3"
NodeFinding(B) <- "B3"
## C will be missing
WriteFindings(list(A,B,C),casefile,3)
RetractNetFindings(abc)


DeleteNetwork(abc)
stopSession(sess)


[Package RNetica version 0.7-3 Index]