|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.jstacs.sequenceScores.differentiable.AbstractDifferentiableSequenceScore de.jstacs.sequenceScores.statisticalModels.differentiable.AbstractDifferentiableStatisticalModel de.jstacs.sequenceScores.statisticalModels.differentiable.mixture.AbstractMixtureDiffSM
public abstract class AbstractMixtureDiffSM
This main abstract class for any mixture scoring function (e.g.
"real" mixture, strand mixture, hidden motif mixture, ...). The
potential for the hidden variables is parameterized depending on the
parameterization of the given DifferentiableStatisticalModel
s. If these
are already normalized (see
DifferentiableStatisticalModel.isNormalized()
) the potential is
parameterized using the Meila-parameterization, otherwise it is parameterized
using the unnormalized MRF(Markov Random Fields)-parameterization.
Field Summary | |
---|---|
protected double[] |
componentScore
This array is used while computing the score. |
protected DoubleList[] |
dList
This array contains some DoubleList s that are used while
computing the partial derivation. |
protected boolean |
freeParams
This boolean indicates whether free parameterization or all
parameters are used. |
protected DifferentiableStatisticalModel[] |
function
This array contains the internal DifferentiableStatisticalModel s that are used to
determine the score. |
protected double[] |
hiddenParameter
This array contains the hidden parameters of the instance. |
protected double[] |
hiddenPotential
This array contains the hidden potentials of the instance. |
protected IntList[] |
iList
This array contains some IntList s that are used while computing
the partial derivation. |
protected double |
logGammaSum
This double contains the sum of the logarithm of the gamma
functions used in the prior. |
protected double |
logHiddenNorm
This double contains the logarithm of the normalization
constant of hidden parameters of the instance. |
protected double[] |
logHiddenPotential
This array contains the logarithm of the hidden potentials of the instance. |
protected double |
norm
This double contains the normalization constant of the
instance. |
protected boolean |
optimizeHidden
This boolean indicates whether to optimize the hidden
variables of this instance. |
protected int[] |
paramRef
This array contains the references/indices for the parameters. |
protected double[] |
partNorm
This array contains the partial normalization constants, i.e. |
Fields inherited from class de.jstacs.sequenceScores.differentiable.AbstractDifferentiableSequenceScore |
---|
alphabets, length, r |
Fields inherited from interface de.jstacs.sequenceScores.differentiable.DifferentiableSequenceScore |
---|
UNKNOWN |
Constructor Summary | |
---|---|
protected |
AbstractMixtureDiffSM(int length,
int starts,
int dimension,
boolean optimizeHidden,
boolean plugIn,
DifferentiableStatisticalModel... function)
This constructor creates a new AbstractMixtureDiffSM . |
protected |
AbstractMixtureDiffSM(StringBuffer xml)
This is the constructor for the interface Storable . |
Method Summary | |
---|---|
void |
addGradientOfLogPriorTerm(double[] grad,
int start)
This method computes the gradient of DifferentiableStatisticalModel.getLogPriorTerm() for each
parameter of this model. |
AbstractMixtureDiffSM |
clone()
Creates a clone (deep copy) of the current DifferentiableSequenceScore
instance. |
protected void |
cloneFunctions(DifferentiableStatisticalModel[] originalFunctions)
This method clones the given array of functions and enables the user to do some post-processing. |
protected void |
computeHiddenParameter(double[] statistic,
boolean add)
This method has to be invoked during an initialization. |
protected void |
computeLogGammaSum()
This method is used to pre-compute the sum of the logarithm of the gamma functions that is used in the prior. |
protected boolean |
determineIsNormalized()
This method is used to determine the value that is returned by the method isNormalized() . |
protected void |
extractFurtherInformation(StringBuffer xml)
This method is the opposite of getFurtherInformation() . |
protected abstract void |
fillComponentScores(Sequence seq,
int start)
Fills the internal array componentScore with the logarithmic
scores of the components given a Sequence . |
protected void |
fromXML(StringBuffer b)
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
DifferentiableSequenceScore.getNumberOfParameters() containing the current parameter values. |
DifferentiableStatisticalModel[] |
getDifferentiableStatisticalModels()
Returns a deep copy of all internal used DifferentiableStatisticalModel s. |
DifferentiableStatisticalModel |
getFunction(int index)
This method returns a specific internal function. |
DifferentiableStatisticalModel[] |
getFunctions()
This method returns an array of clones of the internal used functions. |
protected StringBuffer |
getFurtherInformation()
This method is used to append further information of the instance to the XML representation. |
abstract double |
getHyperparameterForHiddenParameter(int index)
This method returns the hyperparameter for the hidden parameter with index index . |
int |
getIndexOfMaximalComponentFor(Sequence seq,
int start)
Returns the index of the component that has the greatest impact on the complete score for a Sequence . |
protected int[] |
getIndices(int index)
This array is used to compute the relative indices of a parameter index. |
double |
getLogNormalizationConstant()
Returns the logarithm of the sum of the scores over all sequences of the event space. |
protected abstract double |
getLogNormalizationConstantForComponent(int i)
Computes the logarithm of the normalization constant for the component i . |
double |
getLogPriorTerm()
This method computes a value that is proportional to |
double |
getLogScoreFor(Sequence seq,
int start)
Returns the logarithmic score for the Sequence seq
beginning at position start in the Sequence . |
int |
getNumberOfComponents()
Returns the number of different components of this AbstractMixtureDiffSM . |
int |
getNumberOfParameters()
Returns the number of parameters in this DifferentiableSequenceScore . |
int |
getNumberOfRecommendedStarts()
This method returns the number of recommended optimization starts. |
double[] |
getProbsForComponent(Sequence seq)
Returns the probabilities for each component given a Sequence . |
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. |
protected String |
getXMLTag()
This method returns the XML tag of the instance that is used to build a XML representation. |
protected void |
init(boolean freeParams)
This method creates the underlying structure for the parameters. |
void |
initializeFunction(int index,
boolean freeParams,
DataSet[] data,
double[][] weights)
This method creates the underlying structure of the DifferentiableSequenceScore . |
void |
initializeFunctionRandomly(boolean freeParams)
This method initializes the DifferentiableSequenceScore randomly. |
protected void |
initializeHiddenPotentialRandomly()
This method initializes the hidden potential (and the corresponding parameters) randomly. |
void |
initializeHiddenUniformly()
This method initializes the hidden parameters of the instance uniformly. |
protected abstract void |
initializeUsingPlugIn(int index,
boolean freeParams,
DataSet[] data,
double[][] weights)
This method initializes the functions using the data in some way. |
protected void |
initWithLength(boolean freeParams,
int len)
This method is used to create the underlying structure, e.g. |
boolean |
isInitialized()
This method can be used to determine whether the instance is initialized. |
boolean |
isNormalized()
This method indicates whether the implemented score is already normalized to 1 or not. |
protected void |
precomputeNorm()
Pre-computes the normalization constant. |
protected void |
setHiddenParameters(double[] params,
int start)
This method sets the hidden parameters of the model. |
void |
setParameters(double[] params,
int start)
This method sets the internal parameters to the values of params between start and
start + |
protected void |
setParametersForFunction(int index,
double[] params,
int start)
This method allows to set the parameters for specific functions. |
StringBuffer |
toXML()
This method returns an XML representation as StringBuffer of an
instance of the implementing class. |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.differentiable.AbstractDifferentiableStatisticalModel |
---|
emitDataSet, getInitialClassParam, getLogProbFor, getLogProbFor, getLogProbFor, getLogScoreFor, getLogScoreFor, getMaximalMarkovOrder, isNormalized |
Methods inherited from class de.jstacs.sequenceScores.differentiable.AbstractDifferentiableSequenceScore |
---|
getAlphabetContainer, getCharacteristics, getLength, getLogScoreAndPartialDerivation, getLogScoreAndPartialDerivation, getLogScoreFor, getLogScoreFor, getNumberOfStarts, getNumericalCharacteristics |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface de.jstacs.sequenceScores.statisticalModels.differentiable.DifferentiableStatisticalModel |
---|
getESS, getLogPartialNormalizationConstant |
Methods inherited from interface de.jstacs.sequenceScores.differentiable.DifferentiableSequenceScore |
---|
getInitialClassParam, getLogScoreAndPartialDerivation, getLogScoreAndPartialDerivation, getLogScoreAndPartialDerivation |
Methods inherited from interface de.jstacs.sequenceScores.statisticalModels.StatisticalModel |
---|
emitDataSet, getLogProbFor, getLogProbFor, getLogProbFor, getMaximalMarkovOrder |
Methods inherited from interface de.jstacs.sequenceScores.SequenceScore |
---|
getAlphabetContainer, getCharacteristics, getInstanceName, getLength, getLogScoreFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getNumericalCharacteristics, toString |
Field Detail |
---|
protected int[] paramRef
protected boolean optimizeHidden
boolean
indicates whether to optimize the hidden
variables of this instance. (It is not used recursive.)
protected boolean freeParams
boolean
indicates whether free parameterization or all
parameters are used.
protected DifferentiableStatisticalModel[] function
DifferentiableStatisticalModel
s that are used to
determine the score.
protected double[] hiddenParameter
protected double[] logHiddenPotential
protected double[] hiddenPotential
protected double[] componentScore
protected double[] partNorm
protected double norm
double
contains the normalization constant of the
instance.
protected double logHiddenNorm
double
contains the logarithm of the normalization
constant of hidden parameters of the instance.
protected double logGammaSum
double
contains the sum of the logarithm of the gamma
functions used in the prior.
computeLogGammaSum()
protected DoubleList[] dList
DoubleList
s that are used while
computing the partial derivation.
protected IntList[] iList
IntList
s that are used while computing
the partial derivation.
Constructor Detail |
---|
protected AbstractMixtureDiffSM(int length, int starts, int dimension, boolean optimizeHidden, boolean plugIn, DifferentiableStatisticalModel... function) throws CloneNotSupportedException
AbstractMixtureDiffSM
.
length
- the sequence length that should be modeledstarts
- the number of starts that should be done in an optimizationdimension
- the number of different mixture componentsoptimizeHidden
- indicates whether the parameters for the hidden variables
should be optimized or notplugIn
- indicates whether the initial parameters for an optimization
should be related to the data or randomly drawnfunction
- the DifferentiableStatisticalModel
s
CloneNotSupportedException
- if an element of function
could not be clonedprotected AbstractMixtureDiffSM(StringBuffer xml) throws NonParsableException
Storable
.
Creates a new AbstractMixtureDiffSM
out of a
StringBuffer
as returned by toXML()
.
xml
- the XML representation as StringBuffer
NonParsableException
- if the representation could not be parsedMethod Detail |
---|
protected void computeLogGammaSum()
public AbstractMixtureDiffSM clone() throws CloneNotSupportedException
DifferentiableSequenceScore
DifferentiableSequenceScore
instance.
clone
in interface DifferentiableSequenceScore
clone
in interface SequenceScore
clone
in class AbstractDifferentiableStatisticalModel
DifferentiableSequenceScore
CloneNotSupportedException
- if something went wrong while cloning the
DifferentiableSequenceScore
protected void cloneFunctions(DifferentiableStatisticalModel[] originalFunctions) throws CloneNotSupportedException
clone()
.
originalFunctions
- the array of functions to be cloned
CloneNotSupportedException
- if an element of originalFunctions
could not be
clonedpublic abstract double getHyperparameterForHiddenParameter(int index)
index
.
index
- the index of the hidden parameter
public 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) throws Exception
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
entered
Exception
- if something went wrong with the computing of the gradientsDifferentiableStatisticalModel.getLogPriorTerm()
public int getIndexOfMaximalComponentFor(Sequence seq, int start)
Sequence
.
seq
- the sequencestart
- the start position
public double[] getCurrentParameterValues() throws Exception
DifferentiableSequenceScore
double
array of dimension
DifferentiableSequenceScore.getNumberOfParameters()
containing the current parameter values.
If one likes to use these parameters to start an optimization it is
highly recommended to invoke
DifferentiableSequenceScore.initializeFunction(int, boolean, DataSet[], double[][])
before.
After an optimization this method can be used to get the current
parameter values.
getCurrentParameterValues
in interface DifferentiableSequenceScore
Exception
- if no parameters exist (yet)public double getLogScoreFor(Sequence seq, int start)
SequenceScore
Sequence
seq
beginning at position start
in the Sequence
.
getLogScoreFor
in interface SequenceScore
seq
- the Sequence
start
- the start position in the Sequence
Sequence
public final double getLogNormalizationConstant()
DifferentiableStatisticalModel
getLogNormalizationConstant
in interface DifferentiableStatisticalModel
public final int getNumberOfComponents()
AbstractMixtureDiffSM
.
public final int getNumberOfParameters()
DifferentiableSequenceScore
DifferentiableSequenceScore
. If the
number of parameters is not known yet, the method returns
DifferentiableSequenceScore.UNKNOWN
.
getNumberOfParameters
in interface DifferentiableSequenceScore
DifferentiableSequenceScore
DifferentiableSequenceScore.UNKNOWN
public final int getNumberOfRecommendedStarts()
DifferentiableSequenceScore
getNumberOfRecommendedStarts
in interface DifferentiableSequenceScore
getNumberOfRecommendedStarts
in class AbstractDifferentiableSequenceScore
public double[] getProbsForComponent(Sequence seq)
Sequence
.
seq
- the Sequence
i
(=p(i|class,seq)
) in entry i
public DifferentiableStatisticalModel[] getDifferentiableStatisticalModels() throws CloneNotSupportedException
DifferentiableStatisticalModel
s.
DifferentiableStatisticalModel
s
CloneNotSupportedException
- if one element of the internal used
DifferentiableStatisticalModel
s could not
be clonedpublic 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 parameter
public void initializeFunction(int index, boolean freeParams, DataSet[] data, double[][] weights) throws Exception
DifferentiableSequenceScore
DifferentiableSequenceScore
.
initializeFunction
in interface DifferentiableSequenceScore
index
- the index of the class the DifferentiableSequenceScore
modelsfreeParams
- indicates whether the (reduced) parameterization is useddata
- the data setsweights
- the weights of the sequences in the data sets
Exception
- if something went wrongprotected abstract void initializeUsingPlugIn(int index, boolean freeParams, DataSet[] data, double[][] weights) throws Exception
index
- the class indexfreeParams
- if true, the (reduced) parameterization is useddata
- the dataweights
- the weights for the data
- Throws:
Exception
- if the initialization could not be done- See Also:
DifferentiableSequenceScore.initializeFunction(int,
boolean, DataSet[], double[][])
public void initializeFunctionRandomly(boolean freeParams) throws Exception
DifferentiableSequenceScore
DifferentiableSequenceScore
randomly. It has to
create the underlying structure of the DifferentiableSequenceScore
.
initializeFunctionRandomly
in interface DifferentiableSequenceScore
freeParams
- indicates whether the (reduced) parameterization is used
Exception
- if something went wrongprotected void initializeHiddenPotentialRandomly()
public boolean isInitialized()
SequenceScore
SequenceScore.getLogScoreFor(Sequence)
.
isInitialized
in interface SequenceScore
true
if the instance is initialized, false
otherwisepublic void setParameters(double[] params, int start)
DifferentiableSequenceScore
params
between start
and
start + DifferentiableSequenceScore.getNumberOfParameters()
- 1
setParameters
in interface DifferentiableSequenceScore
params
- the new parametersstart
- the start index in params
protected boolean determineIsNormalized()
isNormalized()
.
isNormalized()
public void initializeHiddenUniformly()
protected void setHiddenParameters(double[] params, int start)
params
- the parameter vectorstart
- the start index in params
protected void setParametersForFunction(int index, double[] params, int start)
index
- the function indexparams
- the parameter vectorstart
- the start index in params
public final StringBuffer toXML()
Storable
StringBuffer
of an
instance of the implementing class.
toXML
in interface Storable
protected final void fromXML(StringBuffer b) throws NonParsableException
AbstractDifferentiableSequenceScore
Storable
interface to create a scoring function from a StringBuffer
.
fromXML
in class AbstractDifferentiableSequenceScore
b
- the XML representation as StringBuffer
NonParsableException
- if the StringBuffer
could not be parsedAbstractDifferentiableSequenceScore.AbstractDifferentiableSequenceScore(StringBuffer)
protected StringBuffer getFurtherInformation()
StringBuffer
extractFurtherInformation(StringBuffer)
protected void extractFurtherInformation(StringBuffer xml) throws NonParsableException
getFurtherInformation()
. It
extracts further information of the instance from a XML representation.
xml
- the StringBuffer
containing the information to be
extracted as XML code
NonParsableException
- if the StringBuffer
could not be parsedgetFurtherInformation()
protected int[] getIndices(int index)
index
- the parameter index
paramRef
protected String getXMLTag()
Class.getSimpleName()
protected void init(boolean freeParams)
freeParams
- indicates whether to use only free parameters or all
parametersprotected final void initWithLength(boolean freeParams, int len)
paramRef
.
freeParams
- indicates whether to use free parameters or alllen
- the length of the array paramRef
protected void computeHiddenParameter(double[] statistic, boolean add)
statistic
- a statistic for the initialization of the hidden parametersadd
- a switch for adding hyperparameters to the statisticDifferentiableSequenceScore.initializeFunction(int,
boolean, DataSet[], double[][])
protected void precomputeNorm()
protected abstract double getLogNormalizationConstantForComponent(int i)
i
.
i
- the index of the component
protected abstract void fillComponentScores(Sequence seq, int start)
componentScore
with the logarithmic
scores of the components given a Sequence
.
seq
- the sequencestart
- the start position in seq
public final boolean isNormalized()
DifferentiableStatisticalModel
false
.
isNormalized
in interface DifferentiableStatisticalModel
isNormalized
in class AbstractDifferentiableStatisticalModel
true
if the implemented score is already normalized
to 1, false
otherwisepublic DifferentiableStatisticalModel getFunction(int index) throws CloneNotSupportedException
index
- the index of the specific function
CloneNotSupportedException
- if the function could not be clonedpublic DifferentiableStatisticalModel[] getFunctions() throws CloneNotSupportedException
CloneNotSupportedException
- if at least one function could not be clonedpublic int[][] getSamplingGroups(int parameterOffset)
SamplingDifferentiableStatisticalModel
getSamplingGroups
in interface SamplingDifferentiableStatisticalModel
parameterOffset
- a global offset on the parameter indexes
parameterOffset
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |