NNWarehouse-class: Class '"NNWarehouse"'

NNWarehouse-classR Documentation

Class "NNWarehouse"

Description

This is a container for node objects, which are instances of the Pnode class. If a requested node is not already built, it can be built from the description found in the warehouse. In implements the Warehouse protocol.

Details

The NNWarehouse generally works with a paired BNWarehouse which supplies the network. It assumes that the referenced network already exists or has been loaded from a file. If the node already exists in the network, it simply returns it. If not, it creates it using the metadata in the manifest.

The manifest is an object of type data.frame where the columns have the values show below. The key is the pair of columns (“Model”, “NodeName”), with each pair identifying a set of rows correpsonding to the possible states of the node. The name argument to WarehouseData should be a character vector of length 2 with the first component corresonding to the network name and the second to the node name; it will return a data.frame with multiple rows.

Some of the fields of the manifest data apply to the whole node. In these fields, the value in the first row is used and the rest are ignored.

NStates

A integer giving the number of states for a discrete variable or the discritzation of a continuous one. The number of rows of the manifest data for this node should match this.

Continuous

A logical value telling whether or not the node should be regarded as continuous.

NodeTitle

This is a longer unconstrained name for the node.

NodeDescription

This is a longer string describing the node.

NodeLabels

This is a comma separated list of tags identifying sets to which the node belongs. See PnodeLabels.

These fields are repeated for each of the states in the node, as they are different for each state. The “StateName” field is required and must be unique for each row.

StateName

The name of the state, this should follow the Netica IDname conventions.

StateTitle

This is a longer unconstrained name for the state.

StateDescription

This is a longer string describing the state.

Additionally, the following field is used only for discrete nodes:

StateValue

This is a numeric value assigned to the state. This value is used when calculating the node expected value.

The StateValue plays two important roles. First, when used with the PnodeEAP and PnodeSD functions, it is the value assigned to the node. Second, when constructing CPTs using the DiBello framework, it is used at the effective thetas. See PnodeParentTvals and PnodeStateValues

Continuous nodes in Netica are handled by breaking the interval up into pieces. This is the function PnodeStateBounds. Note that the bounds should be either monotonically increasing or decreasing and that the lower bound for one category should match lower bound for the next to within a tolerance of .002. The values Inf and -Inf can be used where appropriate.

LowerBound

This is a numeric value giving the lower bound for the range for the discritization of the node.

UpperBound

This is a numeric value giving the upper bound for the range for the

Objects from the Class

Objects can be using the constructor NNWarehouse.

This class is a subclass of PnodeWarehouse in the Peanut-package.

This is a reference object and typically there is only one instance per project.

Slots

manifest:

A data frame that gives details of how to build the nodes.

session:

Object of class NeticaSession, which is a pointer back to the Netica user space.

key:

A character vector of length two, which gives the name of the fields in the manifest which which identify the network and variable names.

prefix:

Object of class "character" which is used as a prefix if the name needs to be mangled to fit Netica IDname conventions.

Extends

Class "PnodeWarehouse", directly.

Methods

For all of these methods, the name argument is expected to be a vector of length 2 with the first component specifying the network and the second the node.

WarehouseSupply

signature(warehouse = "NNWarehouse", name = "character", restoreOnly). In this case the name is expected to be a vector of length 2 with the first component identifying the network and the second the node within the network. This finds a node with the appropriate name in the referenced network. If one does not exist, it is created with the properities specified in the manifest.

WarehouseFetch

signature(warehouse = "NNWarehouse", name="character"): Fetches the node if it already exists, or returns NULL if it does not.

WarehouseMake

signature(warehouse = "NNWarehouse", restoreOnly): Makes a new node, calling MakePnode.NeticaNode. The restoreOnly argument is ignored.

as.legal.name

signature(warehouse = "NNWarehouse"): If necessary, mangles a node name to follow the Netica IDname conventions.

ClearWarehouse

signature(warehouse = "NNWarehouse"): Removes prebuilt objects from the warehouse.

is.legal.name

signature(warehouse = "NNWarehouse"): Checks to see if a node name follows the Netica IDname conventions.

is.PnodeWarehouse

signature(obj = "NNWarehouse"): Returns true.

is.valid

signature(warehouse = "NNWarehouse"): Checks an object to see if it is a valid Netica Node.

WarehouseCopy

signature(warehouse = "NNWarehouse", obj = "NeticaNode"): Makes a copy of a node.

WarehouseData

signature(warehouse = "NNWarehouse"): Returns the hunk of manifest for a single node.

WarehouseFree

signature(warehouse = "NNWarehouse"): Deletes the node.

WarehouseInventory

signature(warehouse = "NNWarehouse"): Returns a list of all nodes which have already been built.

WarehouseManifest

signature(warehouse = "NNWarehouse"): Returns the current warehous manifest

WarehouseManifest<-

signature(warehouse = "NNWarehouse", value = "data.frame"): sets the manifest

WarehouseSave

signature(warehouse = "NNWarehouse", obj = "ANY"): Does nothing. Saving is done at the netowrk level.

Extends

Class "PnodeWarehouse", directly.

Note

The test for matching upper and lower bounds is perhaps too strict. In particular, if the upper and lower bounds mismatch by the least significant digit (e.g., a rounding difference) they will not match. This is a frequent cause of errors.

Author(s)

Russell Almond

References

The following is a Google sheet where an example node manifest can be found on the nodes tab. https://docs.google.com/spreadsheets/d/1SiHQTLBNHQ-FUPnNzf9jPm9ifUG-c8f_6ljOrEcdl9M/

See Also

In Peanut Package: Warehouse, WarehouseManifest, BuildNodeManifest

Implementation in the PNetica package: NNWarehouse, MakePnode.NeticaNode

Examples


sess <- NeticaSession()
startSession(sess)

## BNWarehouse is the PNetica Net Warehouse.
## This provides an example network manifest.
netman1 <- read.csv(system.file("auxdata", "Mini-PP-Nets.csv",
                     package="Peanut"),
                    row.names=1, stringsAsFactors=FALSE)
Nethouse <- BNWarehouse(manifest=netman1,session=sess,key="Name")

nodeman1 <- read.csv(system.file("auxdata", "Mini-PP-Nodes.csv", 
                     package="Peanut"),
                     row.names=1,stringsAsFactors=FALSE)

Nodehouse <- NNWarehouse(manifest=nodeman1,
                         key=c("Model","NodeName"),
                         session=sess)

CM <- WarehouseSupply(Nethouse,"miniPP_CM")
WarehouseSupply(Nethouse,"PPdurAttEM")

WarehouseData(Nodehouse,c("miniPP_CM","Physics"))
WarehouseSupply(Nodehouse,c("miniPP_CM","Physics"))

WarehouseData(Nodehouse,c("PPdurAttEM","Attempts"))
WarehouseSupply(Nodehouse,c("PPdurAttEM","Attempts"))

WarehouseData(Nodehouse,c("PPdurAttEM","Duration"))
WarehouseSupply(Nodehouse,c("PPdurAttEM","Duration"))

WarehouseFree(Nethouse,"miniPP_CM")
WarehouseFree(Nethouse,"PPdurAttEM")
stopSession(sess)


ralmond/PNetica documentation built on Sept. 19, 2023, 8:27 a.m.