|
||||||||||
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.AbstractVariableLengthScoringFunction
de.jstacs.scoringFunctions.homogeneous.HomogeneousScoringFunction
de.jstacs.scoringFunctions.homogeneous.HMM0ScoringFunction
public class HMM0ScoringFunction
This scoring function implements a homogeneous Markov model of order zero (hMM(0)) for a fixed sequence length.
Field Summary |
---|
Fields inherited from class de.jstacs.scoringFunctions.AbstractNormalizableScoringFunction |
---|
alphabets, length, r |
Fields inherited from interface de.jstacs.scoringFunctions.ScoringFunction |
---|
UNKNOWN |
Constructor Summary | |
---|---|
HMM0ScoringFunction(AlphabetContainer alphabets,
int length,
double ess,
boolean plugIn,
boolean optimize)
The main constructor that creates an instance of a homogeneous Markov model of order 0. |
|
HMM0ScoringFunction(StringBuffer xml)
This is the constructor for Storable . |
Method Summary | |
---|---|
void |
addGradientOfLogPriorTerm(double[] grad,
int start)
This method computes the gradient of NormalizableScoringFunction.getLogPriorTerm() for each
parameter of this model. |
HMM0ScoringFunction |
clone()
Creates a clone (deep copy) of the current ScoringFunction
instance. |
protected void |
fromXML(StringBuffer xml)
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(int length)
This method returns the logarithm of the normalization constant for a given sequence length. |
double |
getLogPartialNormalizationConstant(int parameterIndex,
int length)
This method returns the logarithm of the partial normalization constant for a given parameter index and a sequence length. |
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,
int length)
This method computes the logarithm of the score for a given subsequence. |
double |
getLogScoreAndPartialDerivation(Sequence seq,
int start,
int length,
IntList indices,
DoubleList dList)
This method computes the logarithm of the score and the partial derivations for a given subsequence. |
int |
getMaximalMarkovOrder()
Returns the maximal used markov oder. |
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. |
void |
initializeUniformly(boolean freeParams)
This method allows to initialize the instance with an uniform distribution. |
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 + |
void |
setStatisticForHyperparameters(int[] length,
double[] weight)
This method sets the hyperparameters for the model parameters by evaluating the given statistic. |
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.AbstractVariableLengthScoringFunction |
---|
getLogNormalizationConstant, getLogPartialNormalizationConstant, getLogScore, getLogScoreAndPartialDerivation |
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 |
Methods inherited from interface de.jstacs.scoringFunctions.NormalizableScoringFunction |
---|
getInitialClassParam, isNormalized |
Methods inherited from interface de.jstacs.scoringFunctions.ScoringFunction |
---|
getAlphabetContainer, getLength, getLogScore, getLogScoreAndPartialDerivation, getNumberOfRecommendedStarts |
Constructor Detail |
---|
public HMM0ScoringFunction(AlphabetContainer alphabets, int length, double ess, boolean plugIn, boolean optimize)
alphabets
- the AlphabetContainer
of the modellength
- the length of sequences the model can handleess
- the equivalent sample size (ess)plugIn
- indicates if a plug-in strategy to initialize the parameters
should be usedoptimize
- indicates if the parameters should be optimized or not after
they have been initializedpublic HMM0ScoringFunction(StringBuffer xml) throws NonParsableException
Storable
. Creates a new
HMM0ScoringFunction
out of its XML representation as returned by
fromXML(StringBuffer)
.
xml
- the XML representation as StringBuffer
NonParsableException
- if the StringBuffer
representation
could
not be parsedMethod Detail |
---|
public HMM0ScoringFunction 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 String getInstanceName()
ScoringFunction
public double getLogScore(Sequence seq, int start, int length)
VariableLengthScoringFunction
seq
- the Sequence
start
- the start index in the Sequence
length
- the length of the Sequence
beginning at start
ScoringFunction.getLogScore(Sequence,
int)
public double getLogScoreAndPartialDerivation(Sequence seq, int start, int length, IntList indices, DoubleList dList)
VariableLengthScoringFunction
seq
- the Sequence
start
- the start index in the Sequence
length
- the end index in the Sequence
indices
- an IntList
of indices, after method invocation the
list should contain the indices i where
dList
- a DoubleList
of partial derivations, after method
invocation the list should contain the corresponding
ScoringFunction.getLogScoreAndPartialDerivation(Sequence, int,
IntList, DoubleList)
public int getNumberOfParameters()
ScoringFunction
ScoringFunction
. If the
number of parameters is not known yet, the method returns
ScoringFunction.UNKNOWN
.
ScoringFunction
ScoringFunction.UNKNOWN
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 StringBuffer toXML()
Storable
StringBuffer
of an
instance of the implementing class.
public double[] getCurrentParameterValues()
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.
public void initializeFunction(int index, boolean freeParams, Sample[] data, double[][] weights)
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 samplespublic void initializeFunctionRandomly(boolean freeParams)
ScoringFunction
ScoringFunction
randomly. It has to
create the underlying structure of the ScoringFunction
.
freeParams
- indicates whether the (reduced) parameterization is usedprotected void fromXML(StringBuffer xml) throws NonParsableException
AbstractNormalizableScoringFunction
Storable
interface to create a scoring function from a StringBuffer
.
fromXML
in class AbstractNormalizableScoringFunction
xml
- the XML representation as StringBuffer
NonParsableException
- if the StringBuffer
could not be parsedAbstractNormalizableScoringFunction.AbstractNormalizableScoringFunction(StringBuffer)
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 getLogNormalizationConstant(int length)
VariableLengthScoringFunction
length
- the sequence length
NormalizableScoringFunction.getLogNormalizationConstant()
public double getLogPartialNormalizationConstant(int parameterIndex, int length) throws Exception
VariableLengthScoringFunction
parameterIndex
- the index of the parameterlength
- the sequence length
Exception
- if something went wrongNormalizableScoringFunction.getLogPartialNormalizationConstant(int)
public double getEss()
NormalizableScoringFunction
public String toString()
toString
in class Object
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 boolean isInitialized()
ScoringFunction
ScoringFunction.initializeFunction(int, boolean, Sample[], double[][])
.
true
if the model is initialized, false
otherwisepublic int getMaximalMarkovOrder()
HomogeneousScoringFunction
getMaximalMarkovOrder
in class HomogeneousScoringFunction
public void setStatisticForHyperparameters(int[] length, double[] weight) throws Exception
VariableLengthScoringFunction
length
) and how often (
weight
) they have been seen.
length
- the non-negative lengths of the sequencesweight
- the non-negative weight for the corresponding sequence
Exception
- if something went wrongMutable
public void initializeUniformly(boolean freeParams)
HomogeneousScoringFunction
initializeUniformly
in class HomogeneousScoringFunction
freeParams
- a switch whether to take only free parameters or to take all
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |