|
||||||||||
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.HMMScoringFunction
public class HMMScoringFunction
This scoring function implements a homogeneous Markov model of arbitrary order for any sequence length. The scoring function uses the parameterization of Meila if one uses the free parameters, which yields in a non-concave log conditional likelihood.
Field Summary |
---|
Fields inherited from class de.jstacs.scoringFunctions.AbstractNormalizableScoringFunction |
---|
alphabets, length, r |
Fields inherited from interface de.jstacs.scoringFunctions.ScoringFunction |
---|
UNKNOWN |
Constructor Summary | |
---|---|
HMMScoringFunction(AlphabetContainer alphabets,
int order,
double classEss,
double[] sumOfHyperParams,
boolean plugIn,
boolean optimize,
int starts)
This is the main constructor that creates an instance of a homogeneous Markov model of arbitrary order. |
|
HMMScoringFunction(AlphabetContainer alphabets,
int order,
double classEss,
int length)
This is a convenience constructor for creating an instance of a homogeneous Markov model of arbitrary order. |
|
HMMScoringFunction(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. |
HMMScoringFunction |
clone()
Creates a clone (deep copy) of the current ScoringFunction
instance. |
Sample |
emit(int numberOfSequences,
int... seqLength)
This method returns a Sample object containing artificial
sequence(s). |
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[][][] |
getAllConditionalStationaryDistributions()
This method returns the stationary conditional distributions. |
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 |
getNumberOfRecommendedStarts()
This method returns the number of recommended optimization starts. |
int |
getSizeOfEventSpaceForRandomVariablesOfParameter(int index)
Returns the size of the event space of the random variables that are affected by parameter no. |
static double[] |
getSumOfHyperParameters(int order,
int length,
double ess)
This method returns an array that can be used in the constructor HMMScoringFunction(AlphabetContainer, int, double, double[], boolean, boolean, int)
containing the sums of the specific hyperparameters. |
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. |
boolean |
isNormalized()
This method indicates whether the implemented score is already normalized to 1 or not. |
void |
setParameterOptimization(boolean optimize)
This method allows the user to specify whether the parameters should be optimized or not. |
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, getNumberOfStarts, 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 |
Methods inherited from interface de.jstacs.scoringFunctions.ScoringFunction |
---|
getAlphabetContainer, getLength, getLogScore, getLogScoreAndPartialDerivation |
Constructor Detail |
---|
public HMMScoringFunction(AlphabetContainer alphabets, int order, double classEss, int length)
alphabets
- the AlphabetContainer
order
- the oder of the model (has to be non-negative)classEss
- the equivalent sample size (ess) of the classlength
- the sequence length (only used for computing the hyperparameters)getSumOfHyperParameters(int, int, double)
,
HMMScoringFunction(AlphabetContainer, int, double, double[], boolean, boolean, int)
public HMMScoringFunction(AlphabetContainer alphabets, int order, double classEss, double[] sumOfHyperParams, boolean plugIn, boolean optimize, int starts)
alphabets
- the AlphabetContainer
order
- the oder of the model (has to be non-negative)classEss
- the equivalent sample size (ess) of the classsumOfHyperParams
- the sum of the hyperparameters for each order (length has to
be order
, each entry has to be non-negative)plugIn
- a switch which enables to use the MAP-parameters as plug-in
parametersoptimize
- a switch which enables to optimize or fix the parametersstarts
- the number of recommended startspublic HMMScoringFunction(StringBuffer xml) throws NonParsableException
Storable
. Creates a new
HMMScoringFunction
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 static double[] getSumOfHyperParameters(int order, int length, double ess)
HMMScoringFunction(AlphabetContainer, int, double, double[], boolean, boolean, int)
containing the sums of the specific hyperparameters.
order
- the order of the modellength
- the sequence lengthess
- the class ESS
HMMScoringFunction(AlphabetContainer, int, double, double[], boolean, boolean, int)
public HMMScoringFunction 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 isNormalized()
NormalizableScoringFunction
false
.
isNormalized
in interface NormalizableScoringFunction
isNormalized
in class AbstractNormalizableScoringFunction
true
if the implemented score is already normalized
to 1, false
otherwisepublic 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 int getNumberOfRecommendedStarts()
ScoringFunction
getNumberOfRecommendedStarts
in interface ScoringFunction
getNumberOfRecommendedStarts
in class AbstractNormalizableScoringFunction
public void setParameterOptimization(boolean optimize)
optimize
- indicates if the parameters should be optimized or notpublic double[][][] getAllConditionalStationaryDistributions()
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 Sample emit(int numberOfSequences, int... seqLength) throws Exception
Sample
object containing artificial
sequence(s).
Sample
:
emitSample( int n, int l )
returns a Sample
with
n
sequences of length l
.
emitSample( int n, int[] l )
should return a
Sample
with n
sequences which have a sequence length
corresponding to the entry in the array.
numberOfSequences
- the number of sequences that should be contained in the
returned Sample
seqLength
- the length of the sequences
Sample
containing numberOfSequences
artificial sequence(s)
Exception
- if the emission of the artificial Sample
did not
succeedSample
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 |