blog
Class Sampler

java.lang.Object
  extended by blog.Sampler
Direct Known Subclasses:
LWSampler, MHSampler, RejectionSampler

public abstract class Sampler
extends java.lang.Object

An object that stochastically generates a sequence of samples, which are possible worlds of a given BLOG model. A Sampler object may generate independent samples, or it may maintain internal state (e.g., a Markov chain sampler). The samples generated may also have associated weights, as in likelihood weighting.

A concrete Sampler subclass should have a constructor that takes two arguments: a blog.Model object and a java.util.Properties object. The properties object specifies configuration parameters for the sampler.


Field Summary
protected  Evidence evidence
          Evidence specified by the last call to initialize, or null if initialize has not been called.
protected  Model model
          BLOG model for which this sampler generates partial worlds.
protected  java.util.List queries
          List of Query objects specified by the last call to initialize, or null if initialize has not been called.
 
Constructor Summary
Sampler(Model model)
          Creates a Sampler object for the given BLOG model.
 
Method Summary
 double getLatestWeight()
          Returns the weight for the world generated by the most recent call to nextSample.
abstract  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.
abstract  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
 

Field Detail

model

protected Model model
BLOG model for which this sampler generates partial worlds.


evidence

protected Evidence evidence
Evidence specified by the last call to initialize, or null if initialize has not been called.


queries

protected java.util.List queries
List of Query objects specified by the last call to initialize, or null if initialize has not been called.

Constructor Detail

Sampler

public Sampler(Model model)
Creates a Sampler object for the given BLOG model.

Method Detail

initialize

public 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. 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.

Parameters:
queries - List of Query objects

nextSample

public abstract void nextSample()
Generates the next sample (world), and possibly assigns it a weight.

Throws:
java.lang.IllegalStateException - if initialize has not been called on this Sampler

getLatestWorld

public abstract PartialWorld getLatestWorld()
Returns the world generated by the most recent call to nextSample. The returned PartialWorld object may be modified by the next call to nextSample.

Throws:
java.lang.IllegalStateException - if nextSample has not been called, or if initialize has been called since the last call to nextSample

getLatestWeight

public double getLatestWeight()
Returns the weight for the world generated by the most recent call to nextSample. The default implementation returns 1.0.

Throws:
java.lang.IllegalStateException - if nextSample has not been called, or if initialize has been called since the last call to nextSample

printStats

public void printStats()
Prints statistics about the internal activities of this sampler. The default implementation does nothing.