WarehouseManifest: Manipulates the manifest for a warehouse

WarehouseManifestR Documentation

Manipulates the manifest for a warehouse

Description

A Warehouse is an object which can either retrieve an existing object or create a new one on demand. The manifest is a data.frame which contains data used for building the objects managed by the warehouse on demand. The function WarehouseManifest access the entire manifest and WarehouseData extracts the warehouse data for a single item. WarehouseInventory returns a list of objects which have already been built.

Usage

WarehouseManifest(warehouse)
WarehouseManifest(warehouse) <- value
WarehouseData(warehouse, name)
WarehouseInventory(warehouse)

Arguments

warehouse

A Warehouse object

value

A data.frame which provides the new manifest data. The required columns depend on the type of data managed by the warehouse

name

A character vector which provides a key for a single object in the warehouse.

Details

The Warehouse design pattern is a combination of a factory and a cache. The idea is that if an object is needed, the warehouse will search the cache and return it if it already exists. If it does not exits, the warehouse will create it using the data in the manifest. The manifest is a data.frame with one or more columns serving as keys. The function ManifestData extracts the data necessary to create a given object.

Two kinds of warehouses are needed in the Peanut interface: net warehouses and node warehouses.

Net Warehouse. A network warehouse will return an already existing network, read the network from disk, or build it from scratch as needed. The required fields for a network warehouse manifest are given in the documentation for BuildNetManifest. 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.

Node Warehouse. A network warehouse will return an already existing node in a network, or build it from scratch as needed. The required fields for a network warehouse manifest are given in the documentation for BuildNodeManifest. Note that node names are only unique within a network, so the key is the pair of columns “Model” and “NodeName”. If the variable has more than 2 states, there may be more than two rows of the manifest which correspond to that node. These should have unique values for the field “StateName”. The name argument to WarehouseData should be a character vector with the first element being the model name and the section the node name. That function will return a data.frame with multiple rows (depending on the number of states).

Value

The function WarehouseManifest returns a data.frame giving the complete warehouse manifest. The function WarehouseData returns selected rows from that data.frame.

The setter function returns the warehouse object.

The function WarehouseInventory returns a data frame where each row corresponds to the key of an object which has been built.

Note

The best way to build a manifest is probably to call BuildNetManifest or BuildNodeManifest on a couple of objects and use that to build a skeleton, which can then be edited with the specific needed data.

Author(s)

Russell Almond

References

Almond, R. G. (presented 2017, August). Tabular views of Bayesian networks. In John-Mark Agosta and Tomas Singlair (Chair), Bayeisan Modeling Application Workshop 2017. Symposium conducted at the meeting of Association for Uncertainty in Artificial Intelligence, Sydney, Australia. (International) Retrieved from http://bmaw2017.azurewebsites.net/

See Also

Warehouse, BuildNetManifest, BuildNodeManifest

Examples

## This provides an example network manifest.
netman1 <- read.csv(system.file("auxdata", "Mini-PP-Nets.csv", 
                                package="Peanut"),
                    row.names=1,stringsAsFactors=FALSE)


## This provides an example node manifest
nodeman1 <- read.csv(system.file("auxdata", "Mini-PP-Nodes.csv", 
                                package="Peanut"),
                     row.names=1,stringsAsFactors=FALSE)

## Not run: 
library(PNetica)  ## Example requires PNetica
sess <- NeticaSession()
startSession(sess)


## BNWarehouse is the PNetica Net Warehouse.
Nethouse <- BNWarehouse(manifest=netman1,session=sess,key="Name")
stopifnot(all.equal(WarehouseManifest(Nethouse),netman1))

stopifnot(all.equal(WarehouseData(Nethouse,"miniPP_CM"),
   netman1["miniPP_CM",]))

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

stopifnot(all.equal(WarehouseData(Nethouse,"miniPP_CM"),
   netman2["miniPP_CM",]))


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

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


stopSession(sess)


## End(Not run)

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