de.jstacs.scoringFunctions.directedGraphicalModels
Class Parameter

java.lang.Object
  extended by de.jstacs.scoringFunctions.directedGraphicalModels.Parameter
All Implemented Interfaces:
Storable, Cloneable

public class Parameter
extends Object
implements Storable, Cloneable

Class for the parameters of a BayesianNetworkScoringFunction. Each parameter holds its current value, the symbol and position it is responsible for, the context of the current symbol. A parameter can either be free or determined by other parameters (on the same simplex).

Author:
Jan Grau

Field Summary
protected  int[][] context
          The context of this parameter.
protected  double count
          The counts for this parameter.
protected  int position
          The position of symbol this parameter is responsible for.
protected  double pseudoCount
          The pseudo count for this parameter.
protected  byte symbol
          The symbol (out of some Alphabet) this parameter is responsible for.
 
Constructor Summary
Parameter(int index, byte symbol, int position, double pseudoCount, boolean free)
          Creates a new parameter, that is parameter no index in the list of parameters of the BayesianNetworkScoringFunction and responsible for symbol at position position and pseudo count pseudoCount.
Parameter(int index, byte symbol, int position, int[][] context, double pseudoCount, boolean free)
          Creates a new parameter, that is parameter no index in the list of parameters of the BayesianNetworkScoringFunction and responsible for symbol at position position having context context and pseudo count pseudoCount.
Parameter(StringBuffer representation)
          Re-creates a parameter from its XML-representation as returned by the toXML()} method.
 
Method Summary
 void addCount(double count2)
          Adds count2 the the counts of this parameter.
 Parameter clone()
           
 double doesApplyFor(Sequence seq)
          Returns true if seq fulfills all requirements defined in the context (context}).
 double getCounts()
          Returns the current counts for this parameter.
 int getDepth()
          Returns the depth of the tree, i.e. the number of parents of this parameter.
 double getExpValue()
          Returns Math.exp(getValue()), which is pre-computed.
 int getIndex()
          Returns the index of this parameter as defined in the constructor.
 double getPartialNormalizer()
          Returns the partial derivative of the normalization constant with respect to this parameter.
 int getPosition()
          Returns the position of this parameter as defined in the constructor.
 double getPseudoCount()
          Returns the pseudo count as given in the constructor.
 double getValue()
          Returns the current value of this parameter.
 double getZ()
          Returns the part of the normalization constant of parameters after this parameter in the structure of the network.
 void invalidateNormalizers()
          Resets all internal normalization constants
 boolean isFree()
          Indicates if this parameter is free.
 void print()
          Prints the counts and the value of this parameter to System.out.
 void reset()
          Resets the counts to the pseudo counts and the value to 0.
 void setValue(double value)
          Sets the current value of this parameter.
 StringBuffer toXML()
          This method returns an XML-representation of an instance of the implementing class.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

symbol

protected byte symbol
The symbol (out of some Alphabet) this parameter is responsible for.


position

protected int position
The position of symbol this parameter is responsible for.


context

protected int[][] context
The context of this parameter. The length context.length is equal to the number of parents, context[i] holds the information for parent no i, context[i][0] holds the position of parent i, context[i][1],... hold the possible configurations of parent i in the context. Normally, only context[i][1] exists, i.e. only one configuration is allowed in the context.


count

protected double count
The counts for this parameter. Used for determination of plug-in parameters.


pseudoCount

protected double pseudoCount
The pseudo count for this parameter. Used for determination of plug-in parameters.

Constructor Detail

Parameter

public Parameter(int index,
                 byte symbol,
                 int position,
                 double pseudoCount,
                 boolean free)
Creates a new parameter, that is parameter no index in the list of parameters of the BayesianNetworkScoringFunction and responsible for symbol at position position and pseudo count pseudoCount.

Parameters:
index - the index in the list of all parameters
symbol - the symbol this parameter is responsible for
position - the position of the symbol
pseudoCount - the pseudo count
free - indicates if this parameter is a free parameter

Parameter

public Parameter(int index,
                 byte symbol,
                 int position,
                 int[][] context,
                 double pseudoCount,
                 boolean free)
Creates a new parameter, that is parameter no index in the list of parameters of the BayesianNetworkScoringFunction and responsible for symbol at position position having context context and pseudo count pseudoCount.

Parameters:
index - the index in the list of all parameters
symbol - the symbol this parameter is responsible for
position - the position of the symbol
context - the context of this parameter
pseudoCount - the pseudo count
free - indicates if this parameter is a free parameter
See Also:
context

Parameter

public Parameter(StringBuffer representation)
          throws NonParsableException
Re-creates a parameter from its XML-representation as returned by the toXML()} method.

Parameters:
representation - the XML-code
Throws:
NonParsableException - is thrown if the representation could not be parsed
Method Detail

clone

public Parameter clone()
                throws CloneNotSupportedException
Overrides:
clone in class Object
Throws:
CloneNotSupportedException

getPseudoCount

public double getPseudoCount()
Returns the pseudo count as given in the constructor.

Returns:
the pseudo count
See Also:
Parameter(int, byte, int, double, boolean), Parameter(int, byte, int, int[][], double, boolean)

reset

public void reset()
Resets the counts to the pseudo counts and the value to 0.


getDepth

public int getDepth()
Returns the depth of the tree, i.e. the number of parents of this parameter.

Returns:
the depth of the tree

print

public void print()
Prints the counts and the value of this parameter to System.out.


doesApplyFor

public double doesApplyFor(Sequence seq)
Returns true if seq fulfills all requirements defined in the context (context}).

Parameters:
seq - the sequence
Returns:
if this parameter is responsible for seq

getValue

public double getValue()
Returns the current value of this parameter.

Returns:
the value

setValue

public void setValue(double value)
Sets the current value of this parameter.

Parameters:
value - the new value

getExpValue

public double getExpValue()
Returns Math.exp(getValue()), which is pre-computed.

Returns:
the exp-value

toXML

public StringBuffer toXML()
Description copied from interface: Storable
This method returns an XML-representation of an instance of the implementing class.

Specified by:
toXML in interface Storable
Returns:
the XML-representation

invalidateNormalizers

public void invalidateNormalizers()
Resets all internal normalization constants


getPartialNormalizer

public double getPartialNormalizer()
                            throws Exception
Returns the partial derivative of the normalization constant with respect to this parameter.

Returns:
the partial derivative
Throws:
Exception - thrown if no normalization constants have been pre-computed

getCounts

public double getCounts()
Returns the current counts for this parameter.

Returns:
the counts

addCount

public void addCount(double count2)
Adds count2 the the counts of this parameter.

Parameters:
count2 - the additional counts

isFree

public boolean isFree()
Indicates if this parameter is free.

Returns:
if the parameter is free

getPosition

public int getPosition()
Returns the position of this parameter as defined in the constructor.

Returns:
the position
See Also:
Parameter(int, byte, int, double, boolean), Parameter(int, byte, int, int[][], double, boolean)

getIndex

public int getIndex()
Returns the index of this parameter as defined in the constructor.

Returns:
the position
See Also:
Parameter(int, byte, int, double, boolean), Parameter(int, byte, int, int[][], double, boolean)

getZ

public double getZ()
Returns the part of the normalization constant of parameters after this parameter in the structure of the network.

Returns:
the normalization constant