|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
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 AlphabetContainer
length
- 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 AlphabetContainer
length
- 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 parsedMethod Detail |
---|
protected void fromXML(StringBuffer representation) throws NonParsableException
AbstractNormalizableScoringFunction
Storable
interface to create a scoring function from a StringBuffer
.
fromXML
in class AbstractNormalizableScoringFunction
representation
- the XML representation as StringBuffer
NonParsableException
- if the StringBuffer
could not be parsedAbstractNormalizableScoringFunction.AbstractNormalizableScoringFunction(StringBuffer)
public MRFScoringFunction clone() throws CloneNotSupportedException
ScoringFunction
ScoringFunction
instance.
clone
in interface ScoringFunction
clone
in class AbstractNormalizableScoringFunction
ScoringFunction
CloneNotSupportedException
- if something went wrong while cloning the
ScoringFunction
public double getLogScore(Sequence seq, int start)
ScoringFunction
Sequence
seq
beginning at position start
in the Sequence
.
seq
- the Sequence
start
- the start position in the Sequence
Sequence
public double getLogScoreAndPartialDerivation(Sequence seq, int start, IntList indices, DoubleList partialDer)
ScoringFunction
Sequence
beginning at
position start
in the Sequence
and fills lists with
the indices and the partial derivations.
seq
- the Sequence
start
- the start position in the Sequence
indices
- an IntList
of indices, after method invocation the
list should contain the indices i where
partialDer
- a DoubleList
of partial derivations, after method
invocation the list should contain the corresponding
Sequence
public int getNumberOfParameters()
ScoringFunction
ScoringFunction
. If the
number of parameters is not known yet, the method returns
ScoringFunction.UNKNOWN
.
ScoringFunction
ScoringFunction.UNKNOWN
public String getInstanceName()
ScoringFunction
public void setParameters(double[] params, int start)
ScoringFunction
params
between start
and
start + ScoringFunction.getNumberOfParameters()
- 1
params
- the new parametersstart
- the start index in params
public String toString()
toString
in class Object
public StringBuffer toXML()
Storable
StringBuffer
of an
instance of the implementing class.
public void initializeFunction(int index, boolean freeParams, Sample[] data, double[][] weights) throws Exception
ScoringFunction
ScoringFunction
.
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 wrongpublic void initializeFunctionRandomly(boolean freeParams) throws Exception
ScoringFunction
ScoringFunction
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
NormalizableScoringFunction
parameterIndex
. This is the logarithm of the partial derivation of the
normalization constant for the parameter with index
parameterIndex
,
parameterIndex
- the index of the parameter
Exception
- if something went wrong with the normalizationNormalizableScoringFunction.getLogNormalizationConstant()
public double getEss()
NormalizableScoringFunction
public int getSizeOfEventSpaceForRandomVariablesOfParameter(int index)
NormalizableScoringFunction
index
, 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)
NormalizableScoringFunction
NormalizableScoringFunction.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
ScoringFunction
double
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()
ScoringFunction
ScoringFunction.initializeFunction(int, boolean, Sample[], double[][])
.
true
if the model is initialized, false
otherwise
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |