GetNamedNetworks {RNetica}R Documentation

Finds a Netica network (if it exists) for the name.

Description

This searches through the currently open Netica networks in the NeticaSession and returns a NeticaBN object pointing to the networks with the given names. If no network with the name is found NULL is returned instead, so this provides a way to check whether a network exists.

CheckNamedNetworks checks the internal Netica list of networks, not the networks cached in the NeticaSession object, so it can be used to check for inconsistencies.

Usage

GetNamedNetworks(namelist, session=getDefaultSession())
CheckNamedNetworks(namelist, session=getDefaultSession())

Arguments

namelist

A character vector giving the name or names of the networks to be found.

session

An object of type NeticaSession which defines the reference to the Netica workspace.

Details

GetNamedNetworks() searches the list of network names looking for a network with the appropriate name. If it is found, a handle to that network is returned as a NeticaBN object. If not, NULL is returned. Note that if a network of the specified name existed, it could return an inactive NeticaBN object corresponding to the deleted network, so it is probably good to check the result with is.active.

There are two ways that RNetica can check for a network of a given name. The first the network cache maintained by the NeticaSession object (session$nets). The function GetNamedNetworks just checks the cache, so it should be relatively fast. The function CheckNamedNetworks iterates through all of the networks in Netica's internal memory, so it should be slower, but should also spot problems with RNetica and Netica getting out of sync.

Value

If namelist is of length 1, then a single NeticaBN object or NULL will be returned.

If namelist is of length greater than 1, then a list of the same length as namelist is returned. Each element is a NeticaBN related to the corresponding name or NULL if the name does not refer to a network.

Note

Each NeticaBN is given a name when it is created. When the network is created, either through a call to CreateNetwork or ReadNetworks, the NeticaSession object updates its cache of the network names in its nets field. The nets field of the session object is an environment which associate the network's name with a NeticaBN object. Internally, functions that return a NeticaBN object (primarily NodeNet), search the network cache in the session object for the network with the corresponding name.

GetNamedNetworks uses the cache (which is hashed) and so should be fairly fast.

CheckNamedNetworks does a linear search through all networks, so it could be pretty slow if there are a large number of networks open. It should raise an error if the cache and the internal Netica specs are out of sync.

Author(s)

Russell Almond

References

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

See Also

CreateNetwork(), GetNthNetwork()

Examples

sess <- NeticaSession()
startSession(sess)

net1 <- CreateNetwork("myNet", session=sess)
## Fetch the network we just created by name.
net2 <- GetNamedNetworks("myNet", session=sess)
stopifnot(is(net2,"NeticaBN"))
stopifnot(NetworkName(net1)==NetworkName(net2))
stopifnot(net1==net2)

net3 <- CheckNamedNetworks("myNet", session=sess)
stopifnot(net1==net3)

## No network named "fish", this should return NULL
fish <- GetNamedNetworks("fish", session=sess)
stopifnot(all(sapply(fish,is.null)))
fish <- CheckNamedNetworks("fish", session=sess)
stopifnot(all(sapply(fish,is.null)))

DeleteNetwork(net1)
net1a <- GetNamedNetworks("myNet", session=sess)
stopifnot(NetworkName(net1a)=="myNet",!is.active(net1a))

net1b <- CheckNamedNetworks("myNet", session=sess)
stopifnot(is.null(net1b))

stopSession(sess)


[Package RNetica version 0.8-2 Index]