int GenerateRandomCase_bn ( const nodelist_bn*  nodes,   sampling_bn  method,   double  timeout,   randgen_ns*  rand )

Generates a random case for nodes (i.e., positive findings for each of them), by sampling from a probability distribution matching that of the net containing nodes, and conditioned on all findings already entered in the net. Returns 0 or greater if it was successful, otherwise negative.

If method is JOIN_TREE_SAMPLING, then the net must be compiled, and the junction tree is used to do very fast sampling with no rejections (i.e., findings don't slow it down).

If method is FORWARD_SAMPLING, then forward sampling is used. This evaluates equations directly if they are available, rather than just using CPT entries (which may just approximate the equation). However, it uses a rejection method, so it may be very slow if the findings currently entered are improbable.

If method is DEFAULT_SAMPLING (the recommended value), then the default method is used. Currently this is method FORWARD_SAMPLING if rejections won't be a problem or the net is uncompiled, otherwise method JOIN_TREE_SAMPLING.

timeout indicates how much time to allocate for the task (in relative units). If it cannot finish in time, it will return a negative quantity (no Netica error will be generated). If method is JOIN_TREE_SAMPLING, or no findings are entered, then it always returns successfully, and within a fixed amount of time, so then timeout is ignored.

For rand you can pass an object created by NewRandomGenerator_ns to control the pseudo-random number sequence. It has the same effect effect as associating rand to the net with SetNetRandomGen_bn; see that function for more info.

Uses the randgen_ns rand passed to it to generate the case. If NULL is passed, it uses the randgen_ns associated with the net by SetNetRandomGen_bn. If there is no randgen_ns associated with the net, it uses Netica's internal global randgen_ns (which is slightly slower due to the required mutex protection).

WARNING:: Be sure to remove unwanted findings first (e.g., with RetractNetFindings_bn), otherwise it will take them into account. For example, if you call this function multiple times without retracting between, the node findings will not change.


In versions previous to 2.26, this function did not have the rand parameter.
In versions previous to 2.09, this function was named RandomCase_bn.
In versions previous to 1.07, this function always used forward sampling.

See also:

GetNodeFinding_bn    Retrieve the random value generated
GetNodeValueEntered_bn    Retrieve the random value generated for a continuous node
NewNodeList2_bn    Create the node list
RetractNetFindings_bn    Probably want to call this first
NewRandomGenerator_ns    To control the sequence of cases produced


See NewRandomGenerator_ns