de.jstacs.sequenceScores.statisticalModels.trainable.hmm.states
Class SimpleSamplingState

java.lang.Object
  extended by de.jstacs.sequenceScores.statisticalModels.trainable.hmm.states.SimpleState
      extended by de.jstacs.sequenceScores.statisticalModels.trainable.hmm.states.SimpleSamplingState
All Implemented Interfaces:
SamplingComponent, SamplingFromStatistic, SamplingState, State, TrainableState

public class SimpleSamplingState
extends SimpleState
implements SamplingState

This class implements a state that can be used for a HMM that obtains its parameters from sampling.

Author:
Jens Keilwagen

Field Summary
 
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.states.SimpleState
e, forward, name
 
Constructor Summary
SimpleSamplingState(SamplingEmission e, String name, boolean forward)
          This constructor creates a state that can be used in a HMM that obtains its parameters from sampling.
 
Method Summary
 void acceptParameters()
          This methods accepts the drawn parameters.
 void drawParametersFromStatistic()
          This method draws the parameters using a sufficient statistic representing a posteriori density.
 void extendSampling(int sampling, boolean append)
          This method allows to extend a sampling.
 double getLogGammaScoreForCurrentStatistic()
          This method calculates a score for the current statistics, which is independent from the current parameters In general the gamma-score is a product of gamma-functions parameterized with the current statistics
 double getLogPosteriorFromStatistic()
          This method calculates the a-posteriori probability for the current statistics
 void initForSampling(int starts)
          This method initializes the instance for the sampling.
 boolean isInSamplingMode()
          This method returns true if the object is currently used in a sampling, otherwise false.
 boolean parseNextParameterSet()
          This method allows the user to parse the next set of parameters (from a file).
 boolean parseParameterSet(int sampling, int n)
          This method allows the user to parse the set of parameters with index n of a certain sampling (from a file).
 void samplingStopped()
          This method is the opposite of the method SamplingComponent.extendSampling(int, boolean).
 
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.hmm.states.SimpleState
addToStatistic, getGraphvizNodeOptions, getLogScoreFor, isSilent, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.jstacs.sequenceScores.statisticalModels.trainable.hmm.states.TrainableState
addToStatistic
 
Methods inherited from interface de.jstacs.sequenceScores.statisticalModels.trainable.hmm.states.State
getGraphvizNodeOptions, getLogScoreFor, isSilent, toString
 

Constructor Detail

SimpleSamplingState

public SimpleSamplingState(SamplingEmission e,
                           String name,
                           boolean forward)
This constructor creates a state that can be used in a HMM that obtains its parameters from sampling.

Parameters:
e - the emission
name - the name of the emission (e.g. for the Graphviz representation)
forward - a switch whether to use the forward or the reverse strand
Method Detail

drawParametersFromStatistic

public void drawParametersFromStatistic()
                                 throws Exception
Description copied from interface: SamplingFromStatistic
This method draws the parameters using a sufficient statistic representing a posteriori density. It is recommended to write the parameters to a specific file using SamplingComponent.acceptParameters() so that they can later be parsed using the methods of the interface.

Before using this method the method SamplingComponent.initForSampling(int) should be called.

Specified by:
drawParametersFromStatistic in interface SamplingFromStatistic
Throws:
Exception - if there is a problem with drawing the parameters, the initialization, ...
See Also:
SamplingComponent.initForSampling(int), SamplingComponent.acceptParameters()

extendSampling

public void extendSampling(int sampling,
                           boolean append)
                    throws IOException
Description copied from interface: SamplingComponent
This method allows to extend a sampling.

Specified by:
extendSampling in interface SamplingComponent
Parameters:
sampling - the index of the sampling
append - whether to append the sampled parameters to an existing file or to overwrite the file
Throws:
IOException - if the file could not be handled correctly

initForSampling

public void initForSampling(int starts)
                     throws IOException
Description copied from interface: SamplingComponent
This method initializes the instance for the sampling. For instance this method can be used to create new files where all parameter sets are stored.

Specified by:
initForSampling in interface SamplingComponent
Parameters:
starts - the number of different sampling starts that will be done
Throws:
IOException - if something went wrong
See Also:
File.createTempFile(String, String, java.io.File )

isInSamplingMode

public boolean isInSamplingMode()
Description copied from interface: SamplingComponent
This method returns true if the object is currently used in a sampling, otherwise false.

Specified by:
isInSamplingMode in interface SamplingComponent
Returns:
true if the object is currently used in a sampling, otherwise false

parseNextParameterSet

public boolean parseNextParameterSet()
Description copied from interface: SamplingComponent
This method allows the user to parse the next set of parameters (from a file).

Specified by:
parseNextParameterSet in interface SamplingComponent
Returns:
true if the parameters could be parsed, otherwise false
See Also:
SamplingComponent.parseParameterSet(int, int)

parseParameterSet

public boolean parseParameterSet(int sampling,
                                 int n)
                          throws Exception
Description copied from interface: SamplingComponent
This method allows the user to parse the set of parameters with index n of a certain sampling (from a file). The internal numbering should start with 0. The parameter set with index 0 is the initial (random) parameter set. It is recommended that a series of parameter sets is accessed by the following lines:

for( sampling = 0; sampling < numSampling; sampling++ )
{

boolean b = parseParameterSet( sampling, n );
while( b )
{
//do something
b = parseNextParameterSet();
}
}

Specified by:
parseParameterSet in interface SamplingComponent
Parameters:
sampling - the index of the sampling
n - the index of the parameter set
Returns:
true if the parameter set could be parsed
Throws:
Exception - if there is a problem with parsing the parameters
See Also:
SamplingComponent.parseNextParameterSet()

samplingStopped

public void samplingStopped()
                     throws IOException
Description copied from interface: SamplingComponent
This method is the opposite of the method SamplingComponent.extendSampling(int, boolean). It can be used for closing any streams of writer, ...

Specified by:
samplingStopped in interface SamplingComponent
Throws:
IOException - if something went wrong
See Also:
SamplingComponent.extendSampling(int, boolean)

acceptParameters

public void acceptParameters()
                      throws IOException
Description copied from interface: SamplingComponent
This methods accepts the drawn parameters. Internally the drawn parameters should be saved (to a file).

Specified by:
acceptParameters in interface SamplingComponent
Throws:
IOException - if the file could not be handled correctly

getLogGammaScoreForCurrentStatistic

public double getLogGammaScoreForCurrentStatistic()
Description copied from interface: SamplingState
This method calculates a score for the current statistics, which is independent from the current parameters In general the gamma-score is a product of gamma-functions parameterized with the current statistics

Specified by:
getLogGammaScoreForCurrentStatistic in interface SamplingState
Returns:
the logarithm of the gamma-score for the current statistics

getLogPosteriorFromStatistic

public double getLogPosteriorFromStatistic()
Description copied from interface: SamplingFromStatistic
This method calculates the a-posteriori probability for the current statistics

Specified by:
getLogPosteriorFromStatistic in interface SamplingFromStatistic
Returns:
the logarithm of the a-posteriori probability