public class UniformDiffSM extends UniformDiffSS implements SamplingDifferentiableStatisticalModel
DifferentiableStatisticalModel
does nothing. So it is possible to save
parameters in an optimization.alphabets, length, r
UNKNOWN
Constructor and Description |
---|
UniformDiffSM(AlphabetContainer alphabets,
int length,
double ess)
This is the main constructor that creates an instance of a
UniformDiffSM that models each sequence uniformly. |
UniformDiffSM(StringBuffer xml)
This is the constructor for the interface
Storable . |
Modifier and Type | Method and Description |
---|---|
void |
addGradientOfLogPriorTerm(double[] grad,
int start)
This method computes the gradient of
DifferentiableStatisticalModel.getLogPriorTerm() for each
parameter of this model. |
DataSet |
emitDataSet(int numberOfSequences,
int... seqLength)
This method returns a
DataSet object containing artificial
sequence(s). |
protected void |
extractFurtherInformation(StringBuffer xml)
This method is the opposite of
UniformDiffSS.getFurtherInformation() . |
double |
getESS()
Returns the equivalent sample size (ess) of this model, i.e.
|
protected StringBuffer |
getFurtherInformation()
This method is used to append further information of the instance to the
XML representation.
|
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
|
double |
getLogProbFor(Sequence sequence)
Returns the logarithm of the probability of the given sequence given the
model.
|
double |
getLogProbFor(Sequence sequence,
int startpos)
Returns the logarithm of the probability of (a part of) the given
sequence given the model.
|
double |
getLogProbFor(Sequence sequence,
int startpos,
int endpos)
Returns the logarithm of the probability of (a part of) the given
sequence given the model.
|
double |
getLogScoreAndPartialDerivation(Sequence seq,
int start,
IntList indices,
DoubleList dList)
|
double |
getLogScoreFor(Sequence seq,
int start)
|
byte |
getMaximalMarkovOrder()
This method returns the maximal used Markov order, if possible.
|
int[][] |
getSamplingGroups(int parameterOffset)
Returns groups of indexes of parameters that shall be drawn
together in a sampling procedure
|
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 meila,
DataSet[] data,
double[][] weights)
This method creates the underlying structure of the
DifferentiableSequenceScore . |
boolean |
isNormalized()
This method indicates whether the implemented score is already normalized
to 1 or not.
|
String |
toString(NumberFormat nf)
This method returns a
String representation of the instance. |
fromXML, getCurrentParameterValues, getInstanceName, getNumberOfParameters, initializeFunctionRandomly, isInitialized, setParameters, toXML
clone, getAlphabetContainer, getCharacteristics, getInitialClassParam, getLength, getLogScoreAndPartialDerivation, getLogScoreAndPartialDerivation, getLogScoreFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getNumberOfRecommendedStarts, getNumberOfStarts, getNumericalCharacteristics, toString
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
clone, getCurrentParameterValues, getInitialClassParam, getLogScoreAndPartialDerivation, getLogScoreAndPartialDerivation, getNumberOfParameters, getNumberOfRecommendedStarts, initializeFunctionRandomly, setParameters
getAlphabetContainer, getCharacteristics, getInstanceName, getLength, getLogScoreFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getNumericalCharacteristics, isInitialized
public UniformDiffSM(AlphabetContainer alphabets, int length, double ess)
UniformDiffSM
that models each sequence uniformly.alphabets
- the AlphabetContainer
length
- the length of the modeled sequencesess
- the equivalent sample size (ess) of the classpublic UniformDiffSM(StringBuffer xml) throws NonParsableException
Storable
.
Creates a new UniformDiffSM
out of its XML
representation as returned by UniformDiffSS.fromXML(StringBuffer)
.xml
- the XML representation as StringBuffer
NonParsableException
- if the XML representation could not be parsedpublic double getLogScoreFor(Sequence seq, int start)
SequenceScore
getLogScoreFor
in interface SequenceScore
getLogScoreFor
in class UniformDiffSS
seq
- the Sequence
start
- the start position in the Sequence
Sequence
public double getLogScoreAndPartialDerivation(Sequence seq, int start, IntList indices, DoubleList dList)
DifferentiableSequenceScore
Sequence
beginning at
position start
in the Sequence
and fills lists with
the indices and the partial derivations.getLogScoreAndPartialDerivation
in interface DifferentiableSequenceScore
getLogScoreAndPartialDerivation
in class UniformDiffSS
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
dList
- a DoubleList
of partial derivations, after method
invocation the list should contain the corresponding
Sequence
protected StringBuffer getFurtherInformation()
UniformDiffSS
getFurtherInformation
in class UniformDiffSS
StringBuffer
UniformDiffSS.extractFurtherInformation(StringBuffer)
protected void extractFurtherInformation(StringBuffer xml) throws NonParsableException
UniformDiffSS
UniformDiffSS.getFurtherInformation()
. It
extracts further information of the instance from a XML representation.extractFurtherInformation
in class UniformDiffSS
xml
- the StringBuffer
containing the information to be
extracted as XML codeNonParsableException
- if the StringBuffer
could not be parsedUniformDiffSS.getFurtherInformation()
public double getLogNormalizationConstant()
DifferentiableStatisticalModel
getLogNormalizationConstant
in interface DifferentiableStatisticalModel
public void initializeFunction(int index, boolean meila, DataSet[] data, double[][] weights)
DifferentiableSequenceScore
DifferentiableSequenceScore
.initializeFunction
in interface DifferentiableSequenceScore
initializeFunction
in class UniformDiffSS
index
- the index of the class the DifferentiableSequenceScore
modelsmeila
- indicates whether the (reduced) parameterization is useddata
- the data setsweights
- the weights of the sequences in the data setspublic int getSizeOfEventSpaceForRandomVariablesOfParameter(int index)
DifferentiableStatisticalModel
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, ...getSizeOfEventSpaceForRandomVariablesOfParameter
in interface DifferentiableStatisticalModel
index
- the index of the parameterpublic double getLogPartialNormalizationConstant(int parameterIndex) throws Exception
DifferentiableStatisticalModel
parameterIndex
. This is the logarithm of the partial derivation of the
normalization constant for the parameter with index
parameterIndex
,
getLogPartialNormalizationConstant
in interface DifferentiableStatisticalModel
parameterIndex
- the index of the parameterException
- if something went wrong with the normalizationDifferentiableStatisticalModel.getLogNormalizationConstant()
public double getESS()
DifferentiableStatisticalModel
getESS
in interface DifferentiableStatisticalModel
public String toString(NumberFormat nf)
SequenceScore
String
representation of the instance.toString
in interface SequenceScore
toString
in class UniformDiffSS
nf
- the NumberFormat
for the String
representation of parameters or probabilitiesString
representation of the instancepublic double getLogPriorTerm()
DifferentiableStatisticalModel
DifferentiableStatisticalModel.getESS()
* DifferentiableStatisticalModel.getLogNormalizationConstant()
+ Math.log( prior )
prior
is the prior for the parameters of this model.getLogPriorTerm
in interface DifferentiableStatisticalModel
getLogPriorTerm
in interface StatisticalModel
DifferentiableStatisticalModel.getESS()
* DifferentiableStatisticalModel.getLogNormalizationConstant()
+ Math.log( prior ).
DifferentiableStatisticalModel.getESS()
,
DifferentiableStatisticalModel.getLogNormalizationConstant()
public void addGradientOfLogPriorTerm(double[] grad, int start)
DifferentiableStatisticalModel
DifferentiableStatisticalModel.getLogPriorTerm()
for each
parameter of this model. The results are added to the array
grad
beginning at index start
.addGradientOfLogPriorTerm
in interface DifferentiableStatisticalModel
grad
- the array of gradientsstart
- the start index in the grad
array, where the
partial derivations for the parameters of this models shall be
enteredDifferentiableStatisticalModel.getLogPriorTerm()
public boolean isNormalized()
DifferentiableStatisticalModel
false
.isNormalized
in interface DifferentiableStatisticalModel
true
if the implemented score is already normalized
to 1, false
otherwisepublic int[][] getSamplingGroups(int parameterOffset)
SamplingDifferentiableStatisticalModel
getSamplingGroups
in interface SamplingDifferentiableStatisticalModel
parameterOffset
- a global offset on the parameter indexesparameterOffset
.public double getLogProbFor(Sequence sequence, int startpos) throws Exception
StatisticalModel
startpos
. E.g. the fixed length is 12. The length
of the given sequence is 30 and the startpos
=15 the logarithm
of the probability of the part from position 15 to 26 (inclusive) given
the model should be returned.
length
and the alphabets
define the type of
data that can be modeled and therefore both has to be checked.getLogProbFor
in interface StatisticalModel
sequence
- the given sequencestartpos
- the start position within the given sequenceException
- if the sequence could not be handled by the modelNotTrainedException
- if the model is not trained yetStatisticalModel.getLogProbFor(Sequence, int, int)
public double getLogProbFor(Sequence sequence) throws Exception
StatisticalModel
length
and the alphabets
define the type of
data that can be modeled and therefore both has to be checked.getLogProbFor
in interface StatisticalModel
sequence
- the given sequence for which the logarithm of the
probability/the value of the density function should be
returnedException
- if the sequence could not be handled by the modelNotTrainedException
- if the model is not trained yetStatisticalModel.getLogProbFor(Sequence, int, int)
public double getLogProbFor(Sequence sequence, int startpos, int endpos) throws Exception
StatisticalModel
StatisticalModel.getLogProbFor(Sequence, int)
by the fact, that the model could be
e.g. homogeneous and therefore the length of the sequences, whose
probability should be returned, is not fixed. Additionally, the end
position of the part of the given sequence is given and the probability
of the part from position startpos
to endpos
(inclusive) should be returned.
length
and the alphabets
define the type of
data that can be modeled and therefore both has to be checked.getLogProbFor
in interface StatisticalModel
sequence
- the given sequencestartpos
- the start position within the given sequenceendpos
- the last position to be taken into accountException
- if the sequence could not be handled (e.g.
startpos >
, endpos
> sequence.length
, ...) by the modelNotTrainedException
- if the model is not trained yetpublic DataSet emitDataSet(int numberOfSequences, int... seqLength) throws NotTrainedException, Exception
StatisticalModel
DataSet
object containing artificial
sequence(s).
emitDataSet( int n, int l )
should return a data set with
n
sequences of length l
.
emitDataSet( int n, int[] l )
should return a data set with
n
sequences which have a sequence length corresponding to
the entry in the given array l
.
emitDataSet( int n )
and
emitDataSet( int n, null )
should return a data set with
n
sequences of length of the model (
SequenceScore.getLength()
).
Exception
.emitDataSet
in interface StatisticalModel
numberOfSequences
- the number of sequences that should be contained in the
returned data setseqLength
- the length of the sequences for a homogeneous model; for an
inhomogeneous model this parameter should be null
or an array of size 0.DataSet
containing the artificial sequence(s)NotTrainedException
- if the model is not trained yetException
- if the emission did not succeedDataSet
public byte getMaximalMarkovOrder() throws UnsupportedOperationException
StatisticalModel
getMaximalMarkovOrder
in interface StatisticalModel
UnsupportedOperationException
- if the model can't give a proper answer