edu.ksu.cis.bnj.bbn.inference.approximate.sampling
Class MCMC

java.lang.Object
  extended byedu.ksu.cis.bnj.bbn.inference.Inference
      extended byedu.ksu.cis.bnj.bbn.inference.ApproximateInference
          extended byedu.ksu.cis.bnj.bbn.inference.approximate.sampling.MCMC
All Implemented Interfaces:
DataGenerator, Optionable
Direct Known Subclasses:
AIS, ChavezMCMC, ForwardSampling, LikelihoodWeighting, LogicSampling, PearlMCMC, SelfImportance

public abstract class MCMC
extends ApproximateInference
implements DataGenerator

Super class for MCMC based approximate inference engine

Author:
Roby Joehanes

Field Summary
protected  boolean abort
          flag that signals the getMarginals function of subclasses to abort
protected  java.util.Timer abortTimer
          Timer used to set the abort flag after a given amount of time
static int defaultMaxIteration
           
protected  boolean generateSamples
           
protected  java.util.LinkedList listeners
           
protected  int maxIteration
           
static long NO_TIME_LIMIT
           
protected static java.lang.String OPT_GENERATE_DATA
           
protected static java.lang.String OPT_MAX_ITERATION
           
protected static java.lang.String OPT_RUNNING_TIME_LIMIT
           
protected static java.lang.String OPT_USE_MARKOV_BLANKET
           
protected static MersenneTwisterFast random
           
protected  long runningTimeLimit
          Sets the limit (in milliseconds) for how long the procedure should run
protected  Table tuples
           
protected  boolean useMarkovBlanketScore
           
 
Fields inherited from class edu.ksu.cis.bnj.bbn.inference.ApproximateInference
rmseWriter
 
Fields inherited from class edu.ksu.cis.bnj.bbn.inference.Inference
graph, inferenceClassName, MAP, MARGINALS, marginalsResult, MPE, OPT_RUN_TYPE, options
 
Fields inherited from interface edu.ksu.cis.kdd.util.gui.Optionable
OPT_OUTPUT_FILE
 
Constructor Summary
MCMC()
           
MCMC(BBNGraph g)
           
 
Method Summary
protected  void abort()
          Sets the abort flag to true, which tells the getMarginals functions to exit at the end of the current iteration.
 void addListener(MCMCListener l)
           
protected  void cancelAbortTimer()
          Cancel the abort timer.
 void generateData(boolean d)
           
 Table generateData(int howmuch)
          Generate data out of a BBN.
 Table getData()
           
 java.util.Hashtable getDefaultOptions()
          TODO: need to read from config file and/or through Settings.java
 java.util.Hashtable getMarkovBlanketScore(BBNNode n, java.util.Hashtable chosen)
          Get Markov blanket scoring.
 int getMaxIteration()
           
 OptionGUI getOptionsDialog()
           
 long getRunningTimeLimit()
          Gets the Running time limit, which methods can use to abort an inference after a specific amount of time.
 boolean isUseMarkovBlanketScore()
           
 void removeListener(MCMCListener l)
           
protected  void sendEvent(MCMCEvent e)
           
protected  void setAbortTimer()
          Set a timer to expire in the number of milliseconds specified by runningTimeLimit.
 void setMaxIteration(int maxIteration)
          Sets the maxIteration.
 void setRunningTimeLimit(long mseconds)
          Sets the Running time limit, which methods can use to abort an inference after a specific amount of time.
 void setUseMarkovBlanketScore(boolean useMarkovBlanketScore)
          Sets the useMarkovBlanketScore.
 
Methods inherited from class edu.ksu.cis.bnj.bbn.inference.ApproximateInference
computeRMSE, getRMSEWriter, setRMSEfile
 
Methods inherited from class edu.ksu.cis.bnj.bbn.inference.Inference
execute, getCurrentOptions, getGraph, getMAP, getMarginals, getMarginalsResult, getMPE, getName, getOutputFile, getRunType, load, setGraph, setOption, setOptions, setOutputFile, setRunType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.ksu.cis.bnj.bbn.datagen.DataGenerator
getName
 

Field Detail

OPT_MAX_ITERATION

protected static final java.lang.String OPT_MAX_ITERATION
See Also:
Constant Field Values

OPT_USE_MARKOV_BLANKET

protected static final java.lang.String OPT_USE_MARKOV_BLANKET
See Also:
Constant Field Values

OPT_GENERATE_DATA

protected static final java.lang.String OPT_GENERATE_DATA
See Also:
Constant Field Values

OPT_RUNNING_TIME_LIMIT

protected static final java.lang.String OPT_RUNNING_TIME_LIMIT
See Also:
Constant Field Values

defaultMaxIteration

public static final int defaultMaxIteration
See Also:
Constant Field Values

NO_TIME_LIMIT

public static final long NO_TIME_LIMIT
See Also:
Constant Field Values

random

protected static MersenneTwisterFast random

runningTimeLimit

protected long runningTimeLimit
Sets the limit (in milliseconds) for how long the procedure should run


abort

protected boolean abort
flag that signals the getMarginals function of subclasses to abort


abortTimer

protected java.util.Timer abortTimer
Timer used to set the abort flag after a given amount of time


maxIteration

protected int maxIteration

useMarkovBlanketScore

protected boolean useMarkovBlanketScore

generateSamples

protected boolean generateSamples

tuples

protected Table tuples

listeners

protected java.util.LinkedList listeners
Constructor Detail

MCMC

public MCMC()

MCMC

public MCMC(BBNGraph g)
Parameters:
g -
Method Detail

addListener

public void addListener(MCMCListener l)

sendEvent

protected void sendEvent(MCMCEvent e)

removeListener

public void removeListener(MCMCListener l)

getMarkovBlanketScore

public java.util.Hashtable getMarkovBlanketScore(BBNNode n,
                                                 java.util.Hashtable chosen)
Get Markov blanket scoring.

Parameters:
n - The node we want to have the Markov blanket scored upon
chosen - The chosen values so far
Returns:
Hashtable The table from value -> score

getData

public Table getData()

generateData

public void generateData(boolean d)

generateData

public Table generateData(int howmuch)
Description copied from interface: DataGenerator
Generate data out of a BBN. It uses an inference engine

Specified by:
generateData in interface DataGenerator
Parameters:
howmuch - The number
Returns:
Table
See Also:
DataGenerator.generateData(int)

isUseMarkovBlanketScore

public boolean isUseMarkovBlanketScore()
Returns:
boolean

setUseMarkovBlanketScore

public void setUseMarkovBlanketScore(boolean useMarkovBlanketScore)
Sets the useMarkovBlanketScore.

Parameters:
useMarkovBlanketScore - The useMarkovBlanketScore to set

getMaxIteration

public int getMaxIteration()
Returns:
int

setMaxIteration

public void setMaxIteration(int maxIteration)
Sets the maxIteration.

Parameters:
maxIteration - The maxIteration to set

getDefaultOptions

public java.util.Hashtable getDefaultOptions()
TODO: need to read from config file and/or through Settings.java

Specified by:
getDefaultOptions in interface Optionable
Overrides:
getDefaultOptions in class Inference
See Also:
Optionable.getDefaultOptions()

getOptionsDialog

public OptionGUI getOptionsDialog()
Specified by:
getOptionsDialog in interface Optionable
Overrides:
getOptionsDialog in class Inference

setRunningTimeLimit

public void setRunningTimeLimit(long mseconds)
Sets the Running time limit, which methods can use to abort an inference after a specific amount of time. The procedures do not stop abruptly at the limit; they stop after completing the current iteration


getRunningTimeLimit

public long getRunningTimeLimit()
Gets the Running time limit, which methods can use to abort an inference after a specific amount of time. The procedures do not stop abruptly at the limit; they stop after completing the current iteration


setAbortTimer

protected void setAbortTimer()
Set a timer to expire in the number of milliseconds specified by runningTimeLimit. When the timer expires, it will set the abort flag to true, signaling the getMarginals function to exit before performing all iterations.


cancelAbortTimer

protected void cancelAbortTimer()
Cancel the abort timer. This should be called by subclasses that call setAbortTimer. It is necessary to handle the case where the inference procedure completes all iterations before the timer expires. Currently, not calling this routine will not cause a problem, but later additions may change this.


abort

protected void abort()
Sets the abort flag to true, which tells the getMarginals functions to exit at the end of the current iteration.