de.jstacs.models.discrete.inhomogeneous
Class InhCondProb

java.lang.Object
  extended by de.jstacs.models.discrete.Constraint
      extended by de.jstacs.models.discrete.inhomogeneous.InhConstraint
          extended by de.jstacs.models.discrete.inhomogeneous.InhCondProb
All Implemented Interfaces:
Storable, Cloneable

public class InhCondProb
extends InhConstraint

This class handles the (conditional) probabilities.

Author:
Jens Keilwagen

Field Summary
 
Fields inherited from class de.jstacs.models.discrete.inhomogeneous.InhConstraint
offset
 
Fields inherited from class de.jstacs.models.discrete.Constraint
counts, freq, usedPositions
 
Constructor Summary
InhCondProb(int[] pos, int[] alphabetLength, boolean cond)
           
InhCondProb(int pos, int... alphabetLength)
           
InhCondProb(StringBuffer xml)
          The constructor for saved objects.
 
Method Summary
protected  void appendAdditionalInfo(StringBuffer xml)
          This method appends additional information that are not stored in the base class to the StringBuffer.
 InhCondProb clone()
           
 void drawParameters(double ess)
          Draws the parameters using the counts and the given ESS as hyperparameters.
protected  void drawUnConditional(int start, int end, double pc)
          This method draws the parameters for a part of this constraint.
 void estimate(double ess)
          Estimates the (smoothed) relative frequencies using the ess.
 void estimateUnConditional(double ess, double all)
          Estimates the unconditional frequencies using the ess.
protected  void estimateUnConditional(int start, int end, double pc, boolean exceptionWhenNoData)
          Estimates unconditionally.
protected  void extractAdditionalInfo(StringBuffer xml)
          This method parses additional information from the StringBuffer that are not parsed in the base class.
 double getLnFreq(int index)
          Returns the logarithmic frequency.
 double getLnFreq(Sequence s, int start)
          Returns the logarithmic frequency.
 void getOutput(byte[] content, double p)
          This method is used to create random sequences.
protected  String getXMLTag()
          Returns the XML-tag that is used for the class to en- or decode.
 void setFreqs(String[] array, int start)
          This method is used to restore the values of a Gibbs Sampling run.
 String toString()
           
 
Methods inherited from class de.jstacs.models.discrete.inhomogeneous.InhConstraint
satisfiesSpecificConstraint
 
Methods inherited from class de.jstacs.models.discrete.Constraint
add, add, getCount, getFreq, getFreq, getMarginalOrder, getNumberOfSpecificConstraints, getPosition, getPositions, reset, toXML
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InhCondProb

public InhCondProb(int pos,
                   int... alphabetLength)
Parameters:
pos - the positions
alphabetLength - the length of each alphabet (not only the used positions)

InhCondProb

public InhCondProb(int[] pos,
                   int[] alphabetLength,
                   boolean cond)
Parameters:
pos - the positions
alphabetLength - the length of each alphabet (not only the used positions)
cond - true if the probabilties

InhCondProb

public InhCondProb(StringBuffer xml)
            throws NonParsableException
The constructor for saved objects.

Parameters:
xml - the representation
Throws:
NonParsableException - if the StringBuffer could not be parsed.
Method Detail

clone

public InhCondProb clone()
                  throws CloneNotSupportedException
Overrides:
clone in class InhConstraint
Throws:
CloneNotSupportedException

drawParameters

public void drawParameters(double ess)
Draws the parameters using the counts and the given ESS as hyperparameters.

Parameters:
ess - the given equivalent sample size

estimate

public void estimate(double ess)
Description copied from class: Constraint
Estimates the (smoothed) relative frequencies using the ess.

Specified by:
estimate in class Constraint
Parameters:
ess - the ESS

estimateUnConditional

public void estimateUnConditional(double ess,
                                  double all)
Estimates the unconditional frequencies using the ess.

Parameters:
ess - the ESS
all - the sum of all weights used to fill the counts

getLnFreq

public double getLnFreq(int index)
Returns the logarithmic frequency.

Parameters:
index - the index
Returns:
the logarithmic frequency

getLnFreq

public double getLnFreq(Sequence s,
                        int start)
Returns the logarithmic frequency.

Parameters:
s - the sequence
start - the index of the start position
Returns:
the logarithm of the frequency

getOutput

public void getOutput(byte[] content,
                      double p)
               throws OperationNotSupportedException
This method is used to create random sequences.

Parameters:
content - the content of the random sequence as far as it is known
p - the random number in (0,1)
Throws:
OperationNotSupportedException
See Also:
Model.emitSample(int, int...)

toString

public String toString()
Specified by:
toString in class Constraint

drawUnConditional

protected void drawUnConditional(int start,
                                 int end,
                                 double pc)
This method draws the parameters for a part of this constraint. It is used to draw a distribution with fixed context.

Parameters:
start - the start index
end - the end index
pc - the pseudo count respectively the hyperparameter

estimateUnConditional

protected void estimateUnConditional(int start,
                                     int end,
                                     double pc,
                                     boolean exceptionWhenNoData)
Description copied from class: Constraint
Estimates unconditionally.

Overrides:
estimateUnConditional in class Constraint
Parameters:
start - the start index
end - the end index
pc - the pseudocount for each parameter
exceptionWhenNoData - if true an (runtime) exception is thrown if no data was available to estimate the parameters

appendAdditionalInfo

protected void appendAdditionalInfo(StringBuffer xml)
Description copied from class: Constraint
This method appends additional information that are not stored in the base class to the StringBuffer.

Overrides:
appendAdditionalInfo in class InhConstraint
Parameters:
xml - the StringBuffer that is used for appending additional information

getXMLTag

protected String getXMLTag()
Description copied from class: Constraint
Returns the XML-tag that is used for the class to en- or decode.

Specified by:
getXMLTag in class Constraint
Returns:
the XML-tag that is used for the class to en- or decode

extractAdditionalInfo

protected void extractAdditionalInfo(StringBuffer xml)
                              throws NonParsableException
Description copied from class: Constraint
This method parses additional information from the StringBuffer that are not parsed in the base class.

Overrides:
extractAdditionalInfo in class InhConstraint
Parameters:
xml - the StringBuffer to parse
Throws:
NonParsableException - if something with the parsing went wrong

setFreqs

public void setFreqs(String[] array,
                     int start)
              throws IllegalArgumentException
This method is used to restore the values of a Gibbs Sampling run. The parameters are encoded in Strings. Each String is one frequency. The start index is used to begin at a specific position in the array.

Parameters:
array - the array of String chunks to be parsed
start - the start index
Throws:
IllegalArgumentException - if something with the frequencies is not okay