NeticaRNG {RNetica}R Documentation

Creates a Netica Random Number Generator

Description

These functions create and manipulate Netica Random Number Generators (NeticaRNG. Note that the storage for NeticaRNG objects should be freed when you are done with them by calling FreeNeticaRNG(rng).

Usage

NewNeticaRNG(seed = sample.int(.Machine$integer.max,1L), session=getDefaultSession())
FreeNeticaRNG(rng)
WithRNG(rng,expr)
is.NeticaRNG(x)
isNeticaRNGActive(rng)

Arguments

seed

An unsigned integer to use as a seed for the random number generator.

session

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

rng

A NeticaRNG object

x

An arbitrary object

expr

An expression to be executed.

Details

Netica supports random number generator objects which serve can be used to generate random cases (GenerateRandomCase()). In either case explicitly creating a random number generator is optional. If this is not done, the default random number generator is uses, which is slightly slower because it needs to be threadsafe. As RNetica probably adds more overhead than the non-threadsafe RNG, the primary use for creating a NeticaRNG is to produce a reproducable sequence of random cases.

Creating a random number generator with rng <- NewNeticaRNG(seed) generates an object in Netica space. The memory for that object should be freed when that is complete. The expression FreeNeticaRNG(rng) frees this object. The function WithRNG can be used to execute code in a context where the RNG will be freed after after completion or in the case of early termination due to an error.

When the random number generator is freed, or if the R session or Netica session is terminated, the NeticaRNG object will become inactive. The function isNeticaRNGActive(rng) tests to see if the random number generator is active (the Netica version still exists).

Value

The value of NewNetiaRNG(seed) is an active NeticaRNG object.

The value of FreeRNG(rng) is its argument which is now inactive.

The value of WithRNG(rng,expr) is the result of evaluating expr.

The values of is.NeticaRNG(x) and isNeticaRNGActive(rng) are logical scalars.

Note

There are two other uses of newly created Netica RNG objects in the Netica Manual which are not currently supported by RNetica. One is to simply generate uniform random numbers which seems superfluous given R's richer random number generation facilities. The second it to associate the RNG with a network. According to the manual, such RNGs no longer need to be deleted when you are done with them. This seems like it could lead to a situation where a single RNG was associated with two networks and then the RNG was deleted when the first network was deleted. Therefore the function NetworkSetRNG() always creates a new RNG.

Internally, a weak reference system is used to keep a list of Netica RNG objects which need to be closed when RNetica is unloaded. RNG objects should also be forced closed when garbage collected. The weak reference system is somewhat experimental, so well designed code should manually close the RNG when the program is through with it.

Author(s)

Russell Almond

References

http://norsys.com/onLineAPIManual/index.html: NewRandomGenerator_ns(), DeleteRandomGen_ns() http://homepage.stat.uiowa.edu/~luke/R/references/weakfinex.html

See Also

An object of NeticaRNG which is what is produced by a call to NewNeticaRNG.

NetworkSetRNG(), GenerateRandomCase()

Examples


sess <- NeticaSession()
startSession(sess)

rng <- NewNeticaRNG(123456789,sess)

stopifnot(is.NeticaRNG(rng),
          isNeticaRNGActive(rng))

FreeNeticaRNG(rng)
stopifnot(!isNeticaRNGActive(rng))

stopSession(sess)



[Package RNetica version 0.8-4 Index]