blog
Class RejectionSampler

java.lang.Object
  extended by blog.Sampler
      extended by blog.RejectionSampler

public class RejectionSampler
extends Sampler

Generates a partial world by sampling basic random variables in an order that does not depend on the evidence or queries, but only on which basic RVs are supported by the instantiation created so far. If it was initialized with the usual initialize method, the RejectionSampler stops when all the query and evidence variables have been instantiated. If it was initialized with initializeCompleteSampling, however, it keeps going until it has instantiated all the basic RVs whose arguments exist in the generated world.

The RejectionSampler constructor looks for the following properties in the properties table:

intBound
The sampler will not instantiate any random variables with integer (or natural number) arguments greater in magnitude then the specified integer. The bound is ignored if it is negative (so 0 is always allowed as an argument).
depthBound
The sampler will not instantiate any random variables whose arguments include non-guaranteed objects of depth greater than the specified integer. The depth of an object generated by the empty tuple is 0; for other non-guaranteed objects, the depth is one greater than the maximum depth of their generating objects. This bound is ignored if it is negative (so objects of depth 0 are always allowed as arguments).
These bounding flags may prevent the sampler from instantiating evidence or query variables, if those variables depend on variables with "large" arguments. In such cases, the sampler will print an error message and exit the program.


Field Summary
 
Fields inherited from class blog.Sampler
evidence, model, queries
 
Constructor Summary
RejectionSampler(Model model, java.util.Properties properties)
          Creates a new RejectionSampler for the given model, with configuration parameters specified by the given properties table.
 
Method Summary
 double getLatestWeight()
          Returns the weight for the world generated by the most recent call to nextSample.
 PartialWorld getLatestWorld()
          Returns the world generated by the most recent call to nextSample.
 void initialize(Evidence evidence, java.util.List queries)
          Prepares this sampler to sample from the distribution conditioned on the given evidence, returning PartialWorld objects that are complete enough to answer the given queries.
 void initializeCompleteSampling()
          Alternative initialization method that does not specify any evidence or queries, but tells this object to generate complete worlds (possibly up to the bounds specified by the intBound and depthBound properties).
 void nextSample()
          Generates the next sample (world), and possibly assigns it a weight.
 void printStats()
          Prints statistics about the internal activities of this sampler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RejectionSampler

public RejectionSampler(Model model,
                        java.util.Properties properties)
Creates a new RejectionSampler for the given model, with configuration parameters specified by the given properties table.

Method Detail

initialize

public void initialize(Evidence evidence,
                       java.util.List queries)
Description copied from class: Sampler
Prepares this sampler to sample from the distribution conditioned on the given evidence, returning PartialWorld objects that are complete enough to answer the given queries. Also clears the internal state of this sampler so that the next sample generated will be independent of all previous ones.

The default implementation just sets the evidence and queries member variables.

Overrides:
initialize in class Sampler
queries - List of Query objects

initializeCompleteSampling

public void initializeCompleteSampling()
Alternative initialization method that does not specify any evidence or queries, but tells this object to generate complete worlds (possibly up to the bounds specified by the intBound and depthBound properties).


nextSample

public void nextSample()
Description copied from class: Sampler
Generates the next sample (world), and possibly assigns it a weight.

Specified by:
nextSample in class Sampler

getLatestWorld

public PartialWorld getLatestWorld()
Description copied from class: Sampler
Returns the world generated by the most recent call to nextSample. The returned PartialWorld object may be modified by the next call to nextSample.

Specified by:
getLatestWorld in class Sampler

getLatestWeight

public double getLatestWeight()
Description copied from class: Sampler
Returns the weight for the world generated by the most recent call to nextSample. The default implementation returns 1.0.

Overrides:
getLatestWeight in class Sampler

printStats

public void printStats()
Description copied from class: Sampler
Prints statistics about the internal activities of this sampler. The default implementation does nothing.

Overrides:
printStats in class Sampler