de.jstacs.scoringFunctions
Class AbstractNormalizableScoringFunction

java.lang.Object
  extended by de.jstacs.scoringFunctions.AbstractNormalizableScoringFunction
All Implemented Interfaces:
NormalizableScoringFunction, ScoringFunction, Storable, Cloneable
Direct Known Subclasses:
AbstractMixtureScoringFunction, BayesianNetworkScoringFunction, IndependentProductScoringFunction, MRFScoringFunction, UniformScoringFunction, VariableLengthScoringFunction

public abstract class AbstractNormalizableScoringFunction
extends Object
implements NormalizableScoringFunction

This class is the main part of any ScoreClassifier. It implements many methods of the interface NormalizableScoringFunction.

Author:
Jens Keilwagen, Jan Grau

Field Summary
protected  AlphabetContainer alphabets
          The AlphabetContainer of this NormalizableScoringFunction
protected  int length
          The length of the modeled sequences.
protected static Random r
          This object can be used for drawing initial parameters.
 
Fields inherited from interface de.jstacs.scoringFunctions.ScoringFunction
UNKNOWN
 
Constructor Summary
AbstractNormalizableScoringFunction(AlphabetContainer alphabets, int length)
          The main constructor.
AbstractNormalizableScoringFunction(StringBuffer xml)
          This is the constructor for Storable.
 
Method Summary
 AbstractNormalizableScoringFunction clone()
          Creates a clone (deep copy) of the current ScoringFunction instance.
protected abstract  void fromXML(StringBuffer xml)
          This method is called in the constructor to create a scoring function from a StringBuffer
 AlphabetContainer getAlphabetContainer()
          Returns the AlphabetContainer for this ScoringFunction.
 double getInitialClassParam(double classProb)
          Returns the initial class parameter for the class this ScoringFunction is responsible for, based on the probability classProb.
 int getLength()
          Returns the length of this ScoringFunction. i.e. the length of the Sequences this ScoringFunction can handle.
 double getLogScore(Sequence seq)
          Returns the log score for the sequence
 double getLogScoreAndPartialDerivation(Sequence seq, IntList indices, DoubleList partialDer)
          Returns the log score for the sequence and fills the list with the indices and the partial derivations.
 int getNumberOfRecommendedStarts()
          This method return the number of recommended optimization starts.
 boolean isNormalized()
          This method returns whether the implemented score is already normalized to 1.
static boolean isNormalized(NormalizableScoringFunction... function)
          This method checks whether all given NormalizableScoringFunctions are normalized.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.jstacs.scoringFunctions.NormalizableScoringFunction
addGradientOfLogPriorTerm, getEss, getLogPriorTerm, getNormalizationConstant, getPartialNormalizationConstant, getSizeOfEventSpaceForRandomVariablesOfParameter
 
Methods inherited from interface de.jstacs.scoringFunctions.ScoringFunction
getCurrentParameterValues, getInstanceName, getLogScore, getLogScoreAndPartialDerivation, getNumberOfParameters, initializeFunction, initializeFunctionRandomly, isInitialized, setParameters
 
Methods inherited from interface de.jstacs.Storable
toXML
 

Field Detail

r

protected static final Random r
This object can be used for drawing initial parameters.

See Also:
ScoringFunction.getCurrentParameterValues()

alphabets

protected AlphabetContainer alphabets
The AlphabetContainer of this NormalizableScoringFunction


length

protected int length
The length of the modeled sequences.

Constructor Detail

AbstractNormalizableScoringFunction

public AbstractNormalizableScoringFunction(AlphabetContainer alphabets,
                                           int length)
The main constructor.

Parameters:
alphabets - the AlphabetContainer of this ScoringFunction
length - the length of this ScoringFunction

AbstractNormalizableScoringFunction

public AbstractNormalizableScoringFunction(StringBuffer xml)
                                    throws NonParsableException
This is the constructor for Storable.

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

clone

public AbstractNormalizableScoringFunction clone()
                                          throws CloneNotSupportedException
Description copied from interface: ScoringFunction
Creates a clone (deep copy) of the current ScoringFunction instance.

Specified by:
clone in interface ScoringFunction
Overrides:
clone in class Object
Returns:
the cloned instance
Throws:
CloneNotSupportedException

fromXML

protected abstract void fromXML(StringBuffer xml)
                         throws NonParsableException
This method is called in the constructor to create a scoring function from a StringBuffer

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

getAlphabetContainer

public final AlphabetContainer getAlphabetContainer()
Description copied from interface: ScoringFunction
Returns the AlphabetContainer for this ScoringFunction. Only Sequences with a comparable AlphabetContainer can be modeled.

Specified by:
getAlphabetContainer in interface ScoringFunction
Returns:
the alphabet

getLength

public int getLength()
Description copied from interface: ScoringFunction
Returns the length of this ScoringFunction. i.e. the length of the Sequences this ScoringFunction can handle. For homogeneous ScoringFunction, i.e. ScoringFunctions that support Sequences of different lengths, should return 0.

Specified by:
getLength in interface ScoringFunction
Returns:
the length

getLogScore

public final double getLogScore(Sequence seq)
Returns the log score for the sequence

Specified by:
getLogScore in interface ScoringFunction
Parameters:
seq - the sequence
Returns:
the log score for the sequence

getLogScoreAndPartialDerivation

public final double getLogScoreAndPartialDerivation(Sequence seq,
                                                    IntList indices,
                                                    DoubleList partialDer)
Description copied from interface: ScoringFunction
Returns the log score for the sequence and fills the list with the indices and the partial derivations.

Specified by:
getLogScoreAndPartialDerivation in interface ScoringFunction
Parameters:
seq - the sequence
indices - after method invocation the list should contain the indices i where \frac{\partial \log score(seq)}{\partial \lambda_i} is not zero
partialDer - after method invocation the list should contain the corresponding \frac{\partial \log score(seq)}{\partial \lambda_i}
Returns:
the log score

getNumberOfRecommendedStarts

public int getNumberOfRecommendedStarts()
Description copied from interface: ScoringFunction
This method return the number of recommended optimization starts. The standard implementation returns 1.

Specified by:
getNumberOfRecommendedStarts in interface ScoringFunction
Returns:
the number of recommended optimization starts

isNormalized

public boolean isNormalized()
Description copied from interface: NormalizableScoringFunction
This method returns whether the implemented score is already normalized to 1. The standard implementation returns false.

Specified by:
isNormalized in interface NormalizableScoringFunction
Returns:
whether the implemented score is already normalized to 1

isNormalized

public static boolean isNormalized(NormalizableScoringFunction... function)
This method checks whether all given NormalizableScoringFunctions are normalized.

Parameters:
function - the NormalizableScoringFunctions to be checked
Returns:
true if all NormalizableScoringFunctions are already normalized, otherwise false
See Also:
NormalizableScoringFunction.isNormalized()

getInitialClassParam

public double getInitialClassParam(double classProb)
Description copied from interface: ScoringFunction
Returns the initial class parameter for the class this ScoringFunction is responsible for, based on the probability classProb.

Specified by:
getInitialClassParam in interface NormalizableScoringFunction
Specified by:
getInitialClassParam in interface ScoringFunction
Parameters:
classProb - the class probability
Returns:
the class parameter