blog
Class MHSampler

java.lang.Object
  extended by blog.Sampler
      extended by blog.MHSampler
Direct Known Subclasses:
DMHSampler

public class MHSampler
extends Sampler

Generates samples from a Markov chain over possible worlds using a Metropolis-Hastings algorithm. The proposal distribution for this algorithm is represented by an object that implements the Proposer interface.

The MHSampler constructor looks at the following properties in the properties table that is passed in:

proposerClass
Name of the proposer class to use. This class must implement the Proposer interface. Default: blog.GenericProposer.
The property table is also passed to the proposer's constructor.


Field Summary
protected  Timer acceptProbTimer
           
protected  PartialWorldDiff curWorld
           
protected  int numAcceptedThisTrial
           
protected  int numSamplesThisTrial
           
protected  int numTrials
           
protected  Proposer proposer
           
protected  int totalNumAccepted
           
protected  int totalNumSamples
           
protected  Timer worldUpdateTimer
           
 
Fields inherited from class blog.Sampler
evidence, model, queries
 
Constructor Summary
MHSampler(Model model, java.util.Properties properties)
          Creates a new sampler for the given BLOG model.
 
Method Summary
protected  void constructProposer(java.util.Properties properties)
          Method responsible for initializing the proposer field.
 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 nextSample()
          Generates the next world in the Markov chain.
 PartialWorld nextSample(PartialWorld world)
          Samples from some given world, leaving the current world in sampler undisturbed.
 void printStats()
          Print statistics gathered during sampling to standard out.
 void setWorld(PartialWorld w)
           
 
Methods inherited from class blog.Sampler
getLatestWeight
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

acceptProbTimer

protected Timer acceptProbTimer

worldUpdateTimer

protected Timer worldUpdateTimer

proposer

protected Proposer proposer

curWorld

protected PartialWorldDiff curWorld

numTrials

protected int numTrials

totalNumSamples

protected int totalNumSamples

totalNumAccepted

protected int totalNumAccepted

numSamplesThisTrial

protected int numSamplesThisTrial

numAcceptedThisTrial

protected int numAcceptedThisTrial
Constructor Detail

MHSampler

public MHSampler(Model model,
                 java.util.Properties properties)
Creates a new sampler for the given BLOG model. The properties table specifies configuration parameters.

Method Detail

constructProposer

protected void constructProposer(java.util.Properties properties)
Method responsible for initializing the proposer field.


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

setWorld

public void setWorld(PartialWorld w)

nextSample

public void nextSample()
Generates the next world in the Markov chain. This method gets a proposed world from the Proposer. If the proposal is accepted, then the next world is the proposed world; otherwise the next world is the same as the previous world.

Specified by:
nextSample in class Sampler

nextSample

public PartialWorld nextSample(PartialWorld world)
Samples from some given world, leaving the current world in sampler undisturbed.


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

printStats

public void printStats()
Print statistics gathered during sampling to standard out. These figures are gathered during each call to sample() and is called once at the end of each trial.

Overrides:
printStats in class Sampler