BNWarehouse-class: Class '"BNWarehouse"'

BNWarehouse-classR Documentation

Class "BNWarehouse"

Description

A Warehouse (specifically a PnetWarehouse) object which holds and builds NeticaBN objects. In particular, its WarehouseManifest contains a network manifest (see BuildNetManifest) which contains information about how to either load the networks from the file system, or build them on demand.

Details

The BNWarehouse either supplies prebuilt (i.e., already in the Netica session) nets or builds them from the instructions found in the manifest. In particular, the function WarehouseSupply will attempt to:

  1. Find an existing network with name in the session.

  2. Try to read the network from the location given in the Pathname column of the manifest.

  3. Build a blank network, 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 “Name” column which should be unique for each row. The name argument to WarehouseData should be a character scalar corresponding to name, and it will return a data.frame with a single row.

Name

A character value giving the name of the network. This should be unique for each row and normally must conform to variable naming conventions. Corresponds to the function PnetName.

Title

An optional character value giving a longer human readable name for the netowrk. Corresponds to the function PnetTitle.

Hub

If this model is incomplete without being joined to another network, then the name of the hub network. Otherwise an empty character vector. Corresponds to the function PnetHub.

Pathname

The location of the file from which the network should be read or to which it should be written. Corresponds to the function PnetPathname.

Description

An optional character value documenting the purpose of the network. Corresponds to the function PnetDescription.

The function BuildNetManifest will build a manifest for an existing collection of networks.

Objects from the Class

Objects can be created by calls of the form BNWarehouse( ...).

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

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

Methods

WarehouseSupply

signature(warehouse = "BNWarehouse", name = "character", restoreOnly). This finds a network with the appropriate name in the session. If one does not exist, it is created by reading it from the pathname specified in the manifest. If no file exists at the pathname, a new blank network with the properities specified in the manifest is created.

WarehouseFetch

signature(warehouse = "BNWarehouse", name = "character"). This fetches the network with the given name from the session object, or returns NULL if it has not been built in Netica yet.

WarehouseMake

signature(warehouse = "BNWarehouse", name = "character", restoreOnly). This loads the network from a file into the Netica session, or builds the network (in the Netica session) using the data in the Manifest. If restoreOnly=TRUE, then the function will generate an error if there is not file to restore the network from.

WarehouseFree

signature(warehouse = "BNWarehouse", name = "character"). This removes the network from the warehouse inventory. Warning: This deletes the network.

ClearWarehouse

signature(warehouse = "BNWarehouse"). This removes all networks from the warehouse inventory. Warning: This deletes all the networks.

is.PnetWarehouse

signature(obj = "BNWarehouse"). This returns TRUE.

WarehouseManifest

signature(warehouse = "BNWarehouse"). This returns the data frame with instructions on how to build networks. (see Details)

WarehouseManifest<-

signature(warehouse = "BNWarehouse", value="data.frame"). This sets the data frame with instructions on how to build networks.(see Details)

WarehouseData

signature(warehouse = "BNWarehouse", name="character"). This returns the portion of the data frame with instructions on how to build a particular network. (see Details)

WarehouseUnpack

signature(warehouse = "BNWarehouse", serial="list"). This restores a serialized network, in particular, it is used for saving network state across sessions. See PnetSerialize for an example.

as.legal.name

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

is.legal.name

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

WarehouseCopy

signature(warehouse = "BNWarehouse", obj = "NeticaBN"): Makes a copy of a network.

is.valid

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

WarehouseSave

signature(warehouse = "NNWarehouse", obj = "NeticaBN"): Saves the network to the pathname in the PnetPathname property.

WarehouseSave

signature(warehouse = "NNWarehouse", obj = "character"): Saves the network with the given name.

Slots

manifest:

A data.frame which consists of the manifest. (see details).

session:

Object of class NeticaSession. This is the session in which the nets are created.

address:

Object of class "character" which gives the path to the directory in which written descriptions of the nets are stored.

key:

Object of class "character" giving the name of the column which has the key for the manifest. This is usually "Name".

prefix:

Object of class "character" giving a short string to insert in front of numeric names to make legal Netica names (see as.IDname).

Extends

Class "PnetWarehouse", directly.

Note

The BNWarehouse implementatation contains an embedded NeticaSession object. When WarehouseSupply is called, it attempts to satisfy the demand by trying in order:

  1. Search for the named network in the active networks in the session.

  2. If not found in the session, it will attempt to load the network from the Pathname field in the manifest.

  3. If the network is not found and there is not file at the target pathename, a new blank network is built and the appropriate fields are set from the metadata.

Author(s)

Russell Almond

References

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

See Also

In Peanut Package: Warehouse, WarehouseManifest, BuildNetManifest

Implementation in the PNetica package: BNWarehouse, MakePnet.NeticaBN

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")

## is.PnetWarehouse -- tests for PnetWarehouse.
stopifnot(is.PnetWarehouse(Nethouse))

## WarehouseManifest
stopifnot(all.equal(WarehouseManifest(Nethouse),netman1))

## WarehouseData
stopifnot(all.equal(WarehouseData(Nethouse,"miniPP_CM")[-4],
   netman1["miniPP_CM",-4]),
   ## Pathname has leading address prefix instered.
   basename(WarehouseData(Nethouse,"miniPP_CM")$Pathname) ==
   basename(netman1["miniPP_CM","Pathname"]))

## WarehouseManifest<- 
netman2 <- netman1
netman2["miniPP_CM","Pathname"] <- "mini_CM.dne"
WarehouseManifest(Nethouse) <- netman2

stopifnot(all.equal(WarehouseData(Nethouse,"miniPP_CM")[,-4],
   netman2["miniPP_CM",-4]),
   basename(WarehouseData(Nethouse,"miniPP_CM")$Pathname) ==
   basename(netman2["miniPP_CM","Pathname"]))
WarehouseManifest(Nethouse) <- netman1

## Usually way to access nets is through warehouse supply
CM <- WarehouseSupply(Nethouse, "miniPP_CM")
EM <- WarehouseSupply(Nethouse, "PPcompEM")
stopifnot(is.active(CM),is.active(EM))

## WarehouseFetch -- Returns NULL if does not exist
stopifnot(is.null(WarehouseFetch(Nethouse,"PPconjEM")))

## WarehouseMake -- Make the net anew.
EM1 <- WarehouseMake(Nethouse,"PPconjEM")
EM1a <- WarehouseFetch(Nethouse,"PPconjEM")
stopifnot(PnetName(EM1)==PnetName(EM1a))

## WarehouseFree -- Deletes the Net
WarehouseFree(Nethouse,"PPconjEM")
stopifnot(!is.active(EM1))

## ClearWarehouse -- Deletes all nets
ClearWarehouse(Nethouse)
stopifnot(!is.active(EM),!is.active(CM))

stopSession(sess)


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