|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectde.jstacs.scoringFunctions.AbstractNormalizableScoringFunction
de.jstacs.scoringFunctions.MRFScoringFunction
public final class MRFScoringFunction
This class implements the scoring function for any MRF (Markov Random Field).
| Field Summary |
|---|
| Fields inherited from class de.jstacs.scoringFunctions.AbstractNormalizableScoringFunction |
|---|
alphabets, length, r |
| Fields inherited from interface de.jstacs.scoringFunctions.ScoringFunction |
|---|
UNKNOWN |
| Constructor Summary | |
|---|---|
MRFScoringFunction(AlphabetContainer alphabets,
int length,
double ess,
String constr)
This is the main constructor that creates an instance of a MRFScoringFunction. |
|
MRFScoringFunction(AlphabetContainer alphabets,
int length,
String constr)
This constructor creates an instance of a MRFScoringFunction with
equivalent sample size (ess) 0. |
|
MRFScoringFunction(StringBuffer source)
This is the constructor for the interface Storable. |
|
| Method Summary | |
|---|---|
void |
addGradientOfLogPriorTerm(double[] grad,
int start)
This method computes the gradient of NormalizableScoringFunction.getLogPriorTerm() for each
parameter of this model. |
MRFScoringFunction |
clone()
Creates a clone (deep copy) of the current ScoringFunction
instance. |
protected void |
fromXML(StringBuffer representation)
This method is called in the constructor for the Storable
interface to create a scoring function from a StringBuffer. |
double[] |
getCurrentParameterValues()
Returns a double array of dimension
ScoringFunction.getNumberOfParameters() containing the current parameter values. |
double |
getEss()
Returns the equivalent sample size (ess) of this model, i.e. the equivalent sample size for the class or component that is represented by this model. |
String |
getInstanceName()
Returns a short instance name. |
double |
getLogNormalizationConstant()
Returns the logarithm of the sum of the scores over all sequences of the event space. |
double |
getLogPartialNormalizationConstant(int parameterIndex)
Returns the logarithm of the partial normalization constant for the parameter with index parameterIndex. |
double |
getLogPriorTerm()
This method computes a value that is proportional to
where prior is the prior for the parameters of this model. |
double |
getLogScore(Sequence seq,
int start)
Returns the logarithmic score for the Sequence seq
beginning at position start in the Sequence. |
double |
getLogScoreAndPartialDerivation(Sequence seq,
int start,
IntList indices,
DoubleList partialDer)
Returns the logarithmic score for a Sequence beginning at
position start in the Sequence and fills lists with
the indices and the partial derivations. |
int |
getNumberOfParameters()
Returns the number of parameters in this ScoringFunction. |
int |
getSizeOfEventSpaceForRandomVariablesOfParameter(int index)
Returns the size of the event space of the random variables that are affected by parameter no. |
void |
initializeFunction(int index,
boolean freeParams,
Sample[] data,
double[][] weights)
This method creates the underlying structure of the ScoringFunction. |
void |
initializeFunctionRandomly(boolean freeParams)
This method initializes the ScoringFunction randomly. |
boolean |
isInitialized()
This method can be used to determine whether the model is initialized. |
void |
setParameters(double[] params,
int start)
This method sets the internal parameters to the values of params between start and
start + |
String |
toString()
|
StringBuffer |
toXML()
This method returns an XML representation as StringBuffer of an
instance of the implementing class. |
| Methods inherited from class de.jstacs.scoringFunctions.AbstractNormalizableScoringFunction |
|---|
getAlphabetContainer, getInitialClassParam, getLength, getLogScore, getLogScoreAndPartialDerivation, getNumberOfRecommendedStarts, getNumberOfStarts, isNormalized, isNormalized |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public MRFScoringFunction(AlphabetContainer alphabets,
int length,
String constr)
MRFScoringFunction with
equivalent sample size (ess) 0.
alphabets - the AlphabetContainerlength - the length of the sequences and accordingly the modelconstr - the constraints that are used for the model, see
ConstraintManager.extract(int, String)MRFScoringFunction(AlphabetContainer, int,
double, String)
public MRFScoringFunction(AlphabetContainer alphabets,
int length,
double ess,
String constr)
MRFScoringFunction.
alphabets - the AlphabetContainerlength - the length of the sequences and accordingly the modeless - the equivalent sample size (ess)constr - the constraints that are used for the model, see
ConstraintManager.extract(int, String)
public MRFScoringFunction(StringBuffer source)
throws NonParsableException
Storable.
Creates a new MRFScoringFunction out of a StringBuffer as
returned by toXML().
source - the XML representation as StringBuffer
NonParsableException - if the XML representation could not be parsed| Method Detail |
|---|
protected void fromXML(StringBuffer representation)
throws NonParsableException
AbstractNormalizableScoringFunctionStorable
interface to create a scoring function from a StringBuffer.
fromXML in class AbstractNormalizableScoringFunctionrepresentation - the XML representation as StringBuffer
NonParsableException - if the StringBuffer could not be parsedAbstractNormalizableScoringFunction.AbstractNormalizableScoringFunction(StringBuffer)
public MRFScoringFunction clone()
throws CloneNotSupportedException
ScoringFunctionScoringFunction
instance.
clone in interface ScoringFunctionclone in class AbstractNormalizableScoringFunctionScoringFunction
CloneNotSupportedException - if something went wrong while cloning the
ScoringFunction
public double getLogScore(Sequence seq,
int start)
ScoringFunctionSequence seq
beginning at position start in the Sequence.
seq - the Sequencestart - the start position in the Sequence
Sequence
public double getLogScoreAndPartialDerivation(Sequence seq,
int start,
IntList indices,
DoubleList partialDer)
ScoringFunctionSequence beginning at
position start in the Sequence and fills lists with
the indices and the partial derivations.
seq - the Sequencestart - the start position in the Sequenceindices - an IntList of indices, after method invocation the
list should contain the indices i where
is not zeropartialDer - a DoubleList of partial derivations, after method
invocation the list should contain the corresponding
that are not zero
Sequencepublic int getNumberOfParameters()
ScoringFunctionScoringFunction. If the
number of parameters is not known yet, the method returns
ScoringFunction.UNKNOWN.
ScoringFunctionScoringFunction.UNKNOWNpublic String getInstanceName()
ScoringFunction
public void setParameters(double[] params,
int start)
ScoringFunctionparams between start and
start + ScoringFunction.getNumberOfParameters() - 1
params - the new parametersstart - the start index in paramspublic String toString()
toString in class Objectpublic StringBuffer toXML()
StorableStringBuffer of an
instance of the implementing class.
public void initializeFunction(int index,
boolean freeParams,
Sample[] data,
double[][] weights)
throws Exception
ScoringFunctionScoringFunction.
index - the index of the class the ScoringFunction modelsfreeParams - indicates whether the (reduced) parameterization is useddata - the samplesweights - the weights of the sequences in the samples
Exception - if something went wrong
public void initializeFunctionRandomly(boolean freeParams)
throws Exception
ScoringFunctionScoringFunction randomly. It has to
create the underlying structure of the ScoringFunction.
freeParams - indicates whether the (reduced) parameterization is used
Exception - if something went wrongpublic double getLogNormalizationConstant()
NormalizableScoringFunction
public double getLogPartialNormalizationConstant(int parameterIndex)
throws Exception
NormalizableScoringFunctionparameterIndex. This is the logarithm of the partial derivation of the
normalization constant for the parameter with index
parameterIndex,
![\[\log \frac{\partial Z(\underline{\lambda})}{\partial \lambda_{parameterindex}}\]](images/NormalizableScoringFunction_LaTeXilb8_1.png)
parameterIndex - the index of the parameter
Exception - if something went wrong with the normalizationNormalizableScoringFunction.getLogNormalizationConstant()public double getEss()
NormalizableScoringFunction
public int getSizeOfEventSpaceForRandomVariablesOfParameter(int index)
NormalizableScoringFunctionindex, i.e. the product of the
sizes of the alphabets at the position of each random variable affected
by parameter index. For DNA alphabets this corresponds to 4
for a PWM, 16 for a WAM except position 0, ...
index - the index of the parameter
public double getLogPriorTerm()
NormalizableScoringFunction
NormalizableScoringFunction.getEss() * NormalizableScoringFunction.getLogNormalizationConstant() + Math.log( prior )
prior is the prior for the parameters of this model.
NormalizableScoringFunction.getEss() * NormalizableScoringFunction.getLogNormalizationConstant() + Math.log( prior ).NormalizableScoringFunction.getEss(),
NormalizableScoringFunction.getLogNormalizationConstant()
public void addGradientOfLogPriorTerm(double[] grad,
int start)
NormalizableScoringFunctionNormalizableScoringFunction.getLogPriorTerm() for each
parameter of this model. The results are added to the array
grad beginning at index start.
grad - the array of gradientsstart - the start index in the grad array, where the
partial derivations for the parameters of this models shall be
enteredNormalizableScoringFunction.getLogPriorTerm()
public double[] getCurrentParameterValues()
throws Exception
ScoringFunctiondouble array of dimension
ScoringFunction.getNumberOfParameters() containing the current parameter values.
If one likes to use these parameters to start an optimization it is
highly recommended to invoke
ScoringFunction.initializeFunction(int, boolean, Sample[], double[][]) before.
After an optimization this method can be used to get the current
parameter values.
Exception - if no parameters exist (yet)public boolean isInitialized()
ScoringFunctionScoringFunction.initializeFunction(int, boolean, Sample[], double[][]).
true if the model is initialized, false
otherwise
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||