SSJ
V. labo.

umontreal.iro.lecuyer.markovchain
Class MarkovChain

java.lang.Object
  extended by umontreal.iro.lecuyer.markovchain.MarkovChain
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
MarkovChainComparable

public abstract class MarkovChain
extends Object
implements Cloneable

This class defines a generic Markov chain and provides basic tools to simulate it for a given number of steps or until it stops and recover the performance measure. Chains can be cloned, so one can simulate many replicates in parallel.

In a concrete subclass, it suffices to implement the three abstract methods initialState(), nextStep(stream) and getPerformance() to get things going. Though it is recommended to implement subclasses of MarkovChainComparable or MarkovChainDouble rather than directly from this class. Some other methods are then needed.

Also, it is VERY IMPORTANT to override the method clone, if the class contains non primitive objects, in order to clone these objects.

Methods of this class simulates the chain over a certain number of steps using Monte Carlo methods or randomized quasi-Monte Carlo. Statistics for the performance mesure of the chain are computed during these simulations.


Constructor Summary
MarkovChain()
           
 
Method Summary
 Object clone()
          Returns a clone of the chain.
 String formatResults(Tally stat)
          Returns a string containing the mean, the variance, and a 90% confidence interval for stat.
 String formatResultsRQMC(Tally stat, int numPoints)
          Returns a string containing the mean, the variance multiplied by numPoints, and a 90% confidence interval for stat.
abstract  double getPerformance()
          Returns the performance measure (total or average cost or gain) so far, for the current simulation run.
 boolean hasStopped()
          Tells if the chain has stopped.
abstract  void initialState()
          Sets the Markov chain to its (deterministic) initial state and initializes the collectors for the performance measure, ready to start a simulation.
abstract  void nextStep(RandomStream stream)
          Simulates one more step of the chain, from its current state, using stream for the randomness.
 void simulRQMC(PointSet p, int m, int numSteps, PointSetRandomization rand, Tally statReps)
          Performs m independent replicates of n simulation runs of the chain using a RQMC point set, each time storing the average of the performance over the n chains.
 void simulRQMC(PointSet p, int m, int numSteps, RandomStream noise, Tally statReps)
          Deprecated. 
 String simulRQMCFormat(PointSet p, int m, int numSteps, RandomStream noise, Tally statReps)
          Same as simulRQMC but also returns the results as a formatted string.
 void simulRuns(int n, int numSteps, RandomStream stream, Tally statRuns)
          Performs n simulation runs of the chain, for numSteps steps per run, using the given stream.
 String simulRunsFormat(int n, int numSteps, RandomStream stream, Tally statRuns)
          Same as simulRuns but also returns the results as a formatted string.
 void simulRunsWithSubstreams(int n, int numSteps, RandomStream stream, Tally statRuns)
          Same as simulRuns, except that the stream is first reset to its initial seed and then reset to the first substream at the beginning and to the next substream after each run.
 String simulRunsWithSubstreamsFormat(int n, int numSteps, RandomStream stream, Tally statRuns)
          Same as simulRunsWithSubstreams but also returns the results as a formatted string.
 void simulSteps(int numSteps, RandomStream stream)
          Starts a new simulation run and simulates numSteps steps of the Markov chain or until the chain stops, using the given stream.
 void simulSteps(RandomStream stream)
          Starts a new simulation run and simulates until the stopping time is reached, using the given stream.
 String testImprovementRQMC(PointSet p, int m, int numSteps, RandomStream noise, double varMC, Tally statReps)
          Similar to simulRQMCFormat, but also gives the variance improvement factor with respect to MC.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MarkovChain

public MarkovChain()
Method Detail

initialState

public abstract void initialState()
Sets the Markov chain to its (deterministic) initial state and initializes the collectors for the performance measure, ready to start a simulation. Must also set variable stopped to false.


nextStep

public abstract void nextStep(RandomStream stream)
Simulates one more step of the chain, from its current state, using stream for the randomness. If the chain stops, this method must set variable stopped to true.


getPerformance

public abstract double getPerformance()
Returns the performance measure (total or average cost or gain) so far, for the current simulation run.


clone

public Object clone()
             throws CloneNotSupportedException
Returns a clone of the chain.

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

hasStopped

public boolean hasStopped()
Tells if the chain has stopped.


simulSteps

public void simulSteps(int numSteps,
                       RandomStream stream)
Starts a new simulation run and simulates numSteps steps of the Markov chain or until the chain stops, using the given stream.


simulSteps

public void simulSteps(RandomStream stream)
Starts a new simulation run and simulates until the stopping time is reached, using the given stream. Same as simulSteps (Integer.MAX_VALUE, stream).


simulRuns

public void simulRuns(int n,
                      int numSteps,
                      RandomStream stream,
                      Tally statRuns)
Performs n simulation runs of the chain, for numSteps steps per run, using the given stream. The statistics on the performance for the n runs are placed in statRuns.


simulRunsWithSubstreams

public void simulRunsWithSubstreams(int n,
                                    int numSteps,
                                    RandomStream stream,
                                    Tally statRuns)
Same as simulRuns, except that the stream is first reset to its initial seed and then reset to the first substream at the beginning and to the next substream after each run.


simulRQMC

public void simulRQMC(PointSet p,
                      int m,
                      int numSteps,
                      PointSetRandomization rand,
                      Tally statReps)
Performs m independent replicates of n simulation runs of the chain using a RQMC point set, each time storing the average of the performance over the n chains. n is the number of points in RQMC point set p. Each run goes for numSteps steps. For each replicate, the point set p is randomized using rand, an iterator is created, and each run uses a different substream of this iterator (i.e., a different point). The statistics on the performance for the m independent replications are placed in statReps.


simulRQMC

@Deprecated
public void simulRQMC(PointSet p,
                                 int m,
                                 int numSteps,
                                 RandomStream noise,
                                 Tally statReps)
Deprecated. 

Use simulRQMC. Simply calls simulRQMC (p, m, numSteps, new RandomShift(noise), statReps), so that the randomization is a random shift.


simulRunsFormat

public String simulRunsFormat(int n,
                              int numSteps,
                              RandomStream stream,
                              Tally statRuns)
Same as simulRuns but also returns the results as a formatted string.


simulRunsWithSubstreamsFormat

public String simulRunsWithSubstreamsFormat(int n,
                                            int numSteps,
                                            RandomStream stream,
                                            Tally statRuns)
Same as simulRunsWithSubstreams but also returns the results as a formatted string.


simulRQMCFormat

public String simulRQMCFormat(PointSet p,
                              int m,
                              int numSteps,
                              RandomStream noise,
                              Tally statReps)
Same as simulRQMC but also returns the results as a formatted string.


testImprovementRQMC

public String testImprovementRQMC(PointSet p,
                                  int m,
                                  int numSteps,
                                  RandomStream noise,
                                  double varMC,
                                  Tally statReps)
Similar to simulRQMCFormat, but also gives the variance improvement factor with respect to MC. Assuming that varMC gives the variance per run for MC.


formatResults

public String formatResults(Tally stat)
Returns a string containing the mean, the variance, and a 90% confidence interval for stat.


formatResultsRQMC

public String formatResultsRQMC(Tally stat,
                                int numPoints)
Returns a string containing the mean, the variance multiplied by numPoints, and a 90% confidence interval for stat.


SSJ
V. labo.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.