|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.scoringFunctions.AbstractNormalizableScoringFunction
de.jstacs.scoringFunctions.mix.AbstractMixtureScoringFunction
public abstract class AbstractMixtureScoringFunction
This main abstract class for any mixture (e.g. "real" mixture, strand mixture, hidden motif, ...).
The potential for the hidden variables is parameterized depending on the parameterization of the given NormalizableScoringFunctions.
If these are already normalized (see NormalizableScoringFunction.isNormalized()
) the
potential is parameterized using the Meila-parameterization, otherwise it is parameterized using the unnormalized MRF-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 NormalizableScoringFunction[] |
function
This array contains the internal functions 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 boolean |
isNormalized
This boolean indicates whether this instance is a normalized one or not. |
protected double |
logGammaSum
This double contains sum of the logarithm of the gamma functions used in the prior. |
protected double |
logHiddenNorm
This double contains 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 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. the normalization constant for each component. |
protected boolean |
plugIn
This boolean indicates whether to use a plug-in strategy to initialize the instance. |
Fields inherited from class de.jstacs.scoringFunctions.AbstractNormalizableScoringFunction |
---|
alphabets, length, r |
Fields inherited from interface de.jstacs.scoringFunctions.ScoringFunction |
---|
UNKNOWN |
Constructor Summary | |
---|---|
AbstractMixtureScoringFunction(int length,
int starts,
int dimension,
boolean optimizeHidden,
boolean plugIn,
NormalizableScoringFunction... function)
This constructor creates an AbstractMixtureScoringFunction. |
|
AbstractMixtureScoringFunction(StringBuffer xml)
This is the constructor for Storable . |
Method Summary | |
---|---|
void |
addGradientOfLogPriorTerm(double[] grad,
int start)
This method computes the gradient of getLogPriorTerm() for each parameter of this model. |
AbstractMixtureScoringFunction |
clone()
Creates a clone (deep copy) of the current ScoringFunction instance. |
protected void |
cloneFunctions(NormalizableScoringFunction[] originalFunctions)
This method clones the given array of function and enables the user to do some postprocessing. |
protected void |
computeHiddenParameter(double[] statistic)
This method has to be invoked during an initialization. |
protected void |
computeLogGammaSum()
This method is used to precompute the sum of the logarithm of the gamma functions that is used in the prior. |
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 log scores of the components. |
protected void |
fromXML(StringBuffer b)
This method is called in the constructor to create a scoring function from a StringBuffer |
double[] |
getCurrentParameterValues()
Returns a double array of dimension getNumberOfParameters() containing the current parameter
values. |
NormalizableScoringFunction |
getFunction(int index)
This method returns a specific internal function |
NormalizableScoringFunction[] |
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 |
protected int[] |
getIndices(int index)
This array is used to compute the relative indices of a parameter index. |
double |
getLogPriorTerm()
This method computes a value that is proportional to getESS()*Math.log( getNormalizationConstant() ) + Math.log( prior ). |
double |
getLogScore(Sequence seq,
int start)
Returns the log score for the sequence |
protected static int |
getMaxIndex(double[] w)
Returns the index with maximal value in the array. |
double |
getNormalizationConstant()
Returns the sum of the scores over all sequences of the event space. |
protected abstract double |
getNormalizationConstantForComponent(int i)
Computes the normalization constant for the component i |
int |
getNumberOfComponents()
Returns the number of different components. |
int |
getNumberOfParameters()
The number of parameters in this scoring function. |
int |
getNumberOfRecommendedStarts()
This method return the number of recommended optimization starts. |
double[] |
getProbsForComponent(Sequence seq)
Returns the probabilities for each component |
NormalizableScoringFunction[] |
getScoringFunctions()
Returns a deep copy of all internal used ScoringFunctions |
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 and XML representation |
protected void |
init(boolean freeParams)
This method creates the underlying structure for the parameters. |
void |
initializeFunction(int index,
boolean freeParams,
Sample[] data,
double[][] weights)
This method creates the underlying structure of the scoring function. |
void |
initializeFunctionRandomly(boolean freeParams)
This method initializes the scoring function 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,
Sample[] data,
double[][] weights)
This method initializes the function 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 model is initialized. |
boolean |
isNormalized()
This method returns whether the implemented score is already normalized to 1. |
protected void |
precomputeNorm()
Precomutes the normalisation constant. |
protected void |
setHiddenParameters(double[] params,
int start)
This method set 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 + this.getNumberOfParameters() - 1 |
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 of an instance of the implementing class. |
Methods inherited from class de.jstacs.scoringFunctions.AbstractNormalizableScoringFunction |
---|
getAlphabetContainer, getInitialClassParam, getLength, getLogScore, getLogScoreAndPartialDerivation, isNormalized |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface de.jstacs.scoringFunctions.NormalizableScoringFunction |
---|
getEss, getPartialNormalizationConstant |
Methods inherited from interface de.jstacs.scoringFunctions.ScoringFunction |
---|
getInstanceName, getLogScoreAndPartialDerivation |
Field Detail |
---|
protected int[] paramRef
protected boolean optimizeHidden
protected boolean plugIn
protected NormalizableScoringFunction[] function
protected double[] hiddenParameter
protected double[] logHiddenPotential
protected double[] hiddenPotential
protected double[] componentScore
protected double[] partNorm
protected double norm
double
contains normalization constant of the instance.
protected double logHiddenNorm
double
contains logarithm of the normalization constant of hidden parameters of the instance.
protected double logGammaSum
double
contains 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
protected boolean isNormalized
Constructor Detail |
---|
public AbstractMixtureScoringFunction(int length, int starts, int dimension, boolean optimizeHidden, boolean plugIn, NormalizableScoringFunction... function) throws CloneNotSupportedException
length
- the sequence length that should be modeledstarts
- the number of starts the should be done in an optimizationdimension
- the number of different mixture componentsoptimizeHidden
- whether the parameters for the hidden variables should be optimizedplugIn
- whether the initial parameters for an optimization should be related to the data or randomly drawnfunction
- the ScoringFunctions
CloneNotSupportedException
public AbstractMixtureScoringFunction(StringBuffer xml) throws NonParsableException
Storable
.
xml
- the xml representation
NonParsableException
- if the representation could not be parsed.Method Detail |
---|
protected static final int getMaxIndex(double[] w)
w
- the array
protected void computeLogGammaSum()
public AbstractMixtureScoringFunction clone() throws CloneNotSupportedException
ScoringFunction
ScoringFunction
instance.
clone
in interface ScoringFunction
clone
in class AbstractNormalizableScoringFunction
CloneNotSupportedException
protected void cloneFunctions(NormalizableScoringFunction[] originalFunctions) throws CloneNotSupportedException
clone()
.
originalFunctions
- the array of functions to be cloned
CloneNotSupportedException
public abstract double getHyperparameterForHiddenParameter(int index)
index
.
index
- the index
public double getLogPriorTerm()
NormalizableScoringFunction
getESS()*Math.log( getNormalizationConstant() ) + Math.log( prior ).
prior is the prior for the parameters of this model.
- Returns:
getESS()*Math.log( getNormalizationConstant() ) + Math.log( prior )
- See Also:
NormalizableScoringFunction.getEss()
,
NormalizableScoringFunction.getNormalizationConstant()
public void addGradientOfLogPriorTerm(double[] grad, int start) throws Exception
NormalizableScoringFunction
getLogPriorTerm()
for each parameter of this model. The
results are added to the array grad
beginning at index start
.
grad
- the gradientstart
- the start index in the grad
array, where the partial derivations for the parameters of
this models shall be enter
Exception
NormalizableScoringFunction.getLogPriorTerm()
public int getIndexOfMaximalComponentFor(Sequence seq, int start)
seq
- the sequencestart
- the start position
public double[] getCurrentParameterValues() throws Exception
ScoringFunction
getNumberOfParameters()
containing the current parameter
values. If on e 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
- is thrown if no parameters exist, yetpublic double getLogScore(Sequence seq, int start)
ScoringFunction
seq
- the sequencestart
- the startposition in the sequence
public final double getNormalizationConstant()
NormalizableScoringFunction
public final int getNumberOfComponents()
public final int getNumberOfParameters()
ScoringFunction
UNKNOWN
.
ScoringFunction.UNKNOWN
public final int getNumberOfRecommendedStarts()
ScoringFunction
getNumberOfRecommendedStarts
in interface ScoringFunction
getNumberOfRecommendedStarts
in class AbstractNormalizableScoringFunction
public double[] getProbsForComponent(Sequence seq)
seq
- the sequence
public NormalizableScoringFunction[] getScoringFunctions() throws CloneNotSupportedException
CloneNotSupportedException
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 void initializeFunction(int index, boolean freeParams, Sample[] data, double[][] weights) throws Exception
ScoringFunction
index
- the index of the class the scoring function modelsfreeParams
- if true, the (reduced) parameterization is useddata
- the samplesweights
- the weights of the sequences in the samples
- Throws:
Exception
protected abstract void initializeUsingPlugIn(int index, boolean freeParams, Sample[] data, double[][] weights) throws Exception
index
- the class indexfreeParams
- if true, the (reduced) parameterization is useddata
- the dataweights
- the weights
- Throws:
Exception
- if the initialization could not be done- See Also:
ScoringFunction.initializeFunction(int, boolean, Sample[], double[][])
public void initializeFunctionRandomly(boolean freeParams) throws Exception
ScoringFunction
freeParams
- if true, the (reduced) parameterization is used
Exception
protected void initializeHiddenPotentialRandomly()
public boolean isInitialized()
ScoringFunction
ScoringFunction.initializeFunction(int, boolean, Sample[], double[][])
.
true
if the model is initializedpublic void setParameters(double[] params, int start)
ScoringFunction
params
between start
and
start + this.getNumberOfParameters() - 1
params
- the parametersstart
- the start indexpublic void initializeHiddenUniformly()
protected void setHiddenParameters(double[] params, int start)
params
- the parameter vectorstart
- the start indexprotected void setParametersForFunction(int index, double[] params, int start)
index
- the function indexparams
- the parameter vectorstart
- the start indexpublic final StringBuffer toXML()
Storable
protected final void fromXML(StringBuffer b) throws NonParsableException
AbstractNormalizableScoringFunction
fromXML
in class AbstractNormalizableScoringFunction
b
- the XML representation
NonParsableException
- if the StringBuffer could not be parsed.protected StringBuffer getFurtherInformation()
StringBuffer
protected void extractFurtherInformation(StringBuffer xml) throws NonParsableException
getFurtherInformation()
.
xml
- the StringBuffer containing the information
NonParsableException
- if the StringBuffer could not be parsedprotected int[] getIndices(int index)
index
- the parameter index
paramRef
protected String getXMLTag()
protected void init(boolean freeParams)
freeParams
- whether to use free parameters or allprotected final void initWithLength(boolean freeParams, int len)
paramRef
freeParams
- whether to use free parameters or alllen
- the length of the paramRef arrayprotected void computeHiddenParameter(double[] statistic)
statistic
- a statistic for the initialization of the hidden parametersScoringFunction.initializeFunction(int, boolean, Sample[], double[][])
protected void precomputeNorm()
protected abstract double getNormalizationConstantForComponent(int i)
i
i
- the index of the component
protected abstract void fillComponentScores(Sequence seq, int start)
componentScore
with the log scores of the components.
seq
- the sequencestart
- the start positionpublic boolean isNormalized()
NormalizableScoringFunction
false
.
isNormalized
in interface NormalizableScoringFunction
isNormalized
in class AbstractNormalizableScoringFunction
public NormalizableScoringFunction getFunction(int index) throws CloneNotSupportedException
index
- the index of the function
CloneNotSupportedException
- if the function could not be clonedpublic NormalizableScoringFunction[] getFunctions() throws CloneNotSupportedException
CloneNotSupportedException
- if at least one function could not be cloned
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |