unbbayes.simulation.montecarlo.sampling
Class MapMonteCarloSampling

java.lang.Object
  extended by unbbayes.simulation.montecarlo.sampling.AMonteCarloSampling
      extended by unbbayes.simulation.montecarlo.sampling.MapMonteCarloSampling
All Implemented Interfaces:
IMonteCarloSampling, ILongTaskProgressObservable

public class MapMonteCarloSampling
extends AMonteCarloSampling

Class that implements the Monte Carlo simulation. It uses forward sampling to calculate a RV's probability mass function. Based on its pmf, it then calculates the cumulative density function. Finally, a random number between 0 and 1 is generated and the sampled state is defined by the state the random number relates based on its cdf.

Author:
Danilo Custodio, Rommel Carvalho

Field Summary
 
Fields inherited from class unbbayes.simulation.montecarlo.sampling.AMonteCarloSampling
currentProgress, currentProgressStatus, factors, maxProgress, nTrials, pn, sampledStatesMap, sampledStatesMatrix, samplingNodeOrderQueue, timesSampled
 
Constructor Summary
MapMonteCarloSampling()
           
 
Method Summary
 byte[][] getSampledStatesCompactMatrix()
          Returns the generated compact sample matrix.
 Map<Integer,Integer> getSampledStatesMap()
          Returns the generated sample map, with key = linear coord (representing the sates sampled) and value = number of times this key was sampled.
 byte[][] getSampledStatesMatrix()
          Returns the generated sample matrix.
 int[] getStatesSetTimesSampled()
          The number of times the ith set of states was sampled.
protected  int[] simulate()
          Responsible for simulating MC for sampling.
 void start(ProbabilisticNetwork pn, int nTrials)
          Generates the MC sample with the given size for the given probabilistic network.
 
Methods inherited from class unbbayes.simulation.montecarlo.sampling.AMonteCarloSampling
addToSamplingOrderQueue, computeFactors, createSamplingOrderQueue, getCumulativeDistributionFunction, getCurrentProgress, getCurrentProgressStatus, getIndexInQueue, getLinearCoord, getMaxProgress, getMultidimensionalCoord, getParentsIndexesInQueue, getPercentageDone, getProbabilityMassFunction, getSamplingNodeOrderQueue, getState, initSamplingOrderQueue, notityObservers, registerObserver, removeObserver, updateProgress, updateProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapMonteCarloSampling

public MapMonteCarloSampling()
Method Detail

getSampledStatesMatrix

public byte[][] getSampledStatesMatrix()
Returns the generated sample matrix. The row represents the ith trial and the column represents the jth node from the samplingNodeOrderQueue. The value matrix[i][j] represents the sampled state index (respecting the node's states order) for the jth node in the ith trial.

Specified by:
getSampledStatesMatrix in interface IMonteCarloSampling
Specified by:
getSampledStatesMatrix in class AMonteCarloSampling
Returns:
The generated sample matrix.

getSampledStatesCompactMatrix

public byte[][] getSampledStatesCompactMatrix()
Returns the generated compact sample matrix. The row represents the ith sampled state set and the column represents the jth node from the samplingNodeOrderQueue. The value matrix[i][j] represents the sampled state index (respecting the node's states order) for the jth node in the ith sampled state set. To get the number of times the ith set of states was sampled use getStatesSetTimesSampled().

Specified by:
getSampledStatesCompactMatrix in interface IMonteCarloSampling
Specified by:
getSampledStatesCompactMatrix in class AMonteCarloSampling
Returns:
The generated compact sample matrix.

getStatesSetTimesSampled

public int[] getStatesSetTimesSampled()
The number of times the ith set of states was sampled.

Specified by:
getStatesSetTimesSampled in interface IMonteCarloSampling
Specified by:
getStatesSetTimesSampled in class AMonteCarloSampling
Returns:
The number of times the ith set of states was sampled.

getSampledStatesMap

public Map<Integer,Integer> getSampledStatesMap()
Returns the generated sample map, with key = linear coord (representing the sates sampled) and value = number of times this key was sampled.

Specified by:
getSampledStatesMap in interface IMonteCarloSampling
Specified by:
getSampledStatesMap in class AMonteCarloSampling
Returns:
The generated sample map.

start

public void start(ProbabilisticNetwork pn,
                  int nTrials)
Generates the MC sample with the given size for the given probabilistic network.

Specified by:
start in interface IMonteCarloSampling
Specified by:
start in class AMonteCarloSampling
Parameters:
pn - Probabilistic network that will be used for sampling.
nTrials - Number of trials to generate.

simulate

protected int[] simulate()
Responsible for simulating MC for sampling.

Parameters:
sampledStatesMatrix - The matrix containing the sampled states for every trial.
nTrial - The trial number to simulate.


Copyright © 2001-2010 University of Brasilia - UnB. All Rights Reserved.