NeticaRNG-class {RNetica} | R Documentation |
"NeticaRNG"
This is an object containing a reference to a Netica Random Number
Generator. Note that the storage for NeticaRNG objects should be
freed when you are done with them by calling
FreeNeticaRNG(rng)
.
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).
All reference classes extend and inherit methods from
"envRefClass"
. Note that because this is a
reference class unlike traditional S3 and S4 classes it can be
destructively modified. Also fields (slots) are accessed using the
‘$’ operator.
signature(x = "NeticaRNG")
: Produces a printer
representation of the RNG object.
signature(x = "NeticaRNG")
: Produces a string
representation of the RNG object.
Note these should be regarded as read-only from user code.
Name
:Object of class character
giving a name
to the RNG. These are autogenerated with a number.
Session
:Object of class NeticaSession
: a back
pointer to the NeticaSession
object in which
the network was created.
Netica_RNG
:Object of class externalptr
which
hold the pointer to the RNG object in the Netica workspace.
Seed
:Object of class integer
giving the seed
used to initialize the RNG.
show()
:Provides a printed description
free()
: Frees the RNG in Netica Memory. Equivalent
to FreeNeticaRNG
.
isActive()
:Test to see if the RNG is active (been created in Netica) or inactive (already freed).
clearErrors(severity)
: Calls clearErrors
on
the Session
object.
reportErrors(maxreport, clear)
: Calls
reportErrors
on the Session
object.
initialize(Name, Session, Seed, ...)
:Initialization function. Should not be called by user code.
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.
Russell Almond
http://norsys.com/onLineAPIManual/index.html: NewRandomGenerator_ns(), DeleteRandomGen_ns() http://homepage.stat.uiowa.edu/~luke/R/references/weakfinex.html
An object of NeticaRNG
which is produced
by a call to NewNeticaRNG
.
NetworkSetRNG()
, GenerateRandomCase()
sess <- NeticaSession() startSession(sess) rng <- NewNeticaRNG(123456789,sess) stopifnot(is.NeticaRNG(rng), isNeticaRNGActive(rng)) FreeNeticaRNG(rng) stopifnot(!isNeticaRNGActive(rng)) stopSession(sess)