public class BNDiffSMParameterTree extends Object implements Cloneable, Storable
BNDiffSMParameter in a
BayesianNetworkDiffSM.| Modifier and Type | Class and Description |
|---|---|
class |
BNDiffSMParameterTree.TreeElement
Class for the nodes of a
BNDiffSMParameterTree |
| Constructor and Description |
|---|
BNDiffSMParameterTree(int pos,
int[] contextPoss,
AlphabetContainer alphabet,
int firstParent,
int[] firstChildren)
Creates a new
BNDiffSMParameterTree for the parameters at position
pos using the parent positions in contextPoss. |
BNDiffSMParameterTree(StringBuffer source)
Recreates a
BNDiffSMParameterTree from its XML representation as
returned by toXML(). |
| Modifier and Type | Method and Description |
|---|---|
void |
addCount(Sequence seq,
int start,
double count)
Adds
count to the parameter as returned by
getParameterFor(Sequence, int). |
void |
backward(BNDiffSMParameterTree[] trees,
int[][] order)
Computes the backward-part of the normalization constant
starting from this
BNDiffSMParameterTree. |
BNDiffSMParameterTree |
clone() |
Double |
computeGammaNorm()
Computes the Gamma-normalization for the prior.
|
void |
copy(BNDiffSMParameterTree parameterTree)
Copies the values of the parameters from another
BNDiffSMParameterTree. |
void |
divideByUnfree()
Divides each of the normalized parameters on a simplex by the last
BNDiffSMParameter, which is defined not to be free. |
void |
drawKLDivergences(double[] kls,
double[] weights,
double[][][][] contrast,
double samples)
Draws KL-divergences between the distributions given by
contrast[i] each weighted by weights[i]
kls.length distributions drawn from a Dirichlet density centered around contrast, i.e. |
void |
drawKLDivergences(double weight,
double[] kls,
int startIdx,
int endIdx,
double[][][] contrast,
double samples)
Draws KL-divergences between the distribution given by
contrast and
endIdx-startIdx distributions drawn from a Dirichlet density centered around contrast, i.e. |
void |
fill(double[] weight,
double[][][][] distribution)
Fills all parameters with the probabilities given in
distribution. |
double |
forward(BNDiffSMParameterTree[] trees)
Computes the forward-part of the normalization constant starting from
this
BNDiffSMParameterTree. |
int |
getFirstParent()
Returns the first parent of the random variable of this
BNDiffSMParameterTree in the topological ordering of the network
structure of the enclosing BayesianNetworkDiffSM. |
double |
getKLDivergence(double[][][] ds)
Returns the KL-divergence of the distribution of this
BNDiffSMParameterTree and the distribution given by
ds. |
double |
getKLDivergence(double[] weight,
double[][][][] distribution)
Returns the KL-divergence of the distribution of this
BNDiffSMParameterTree and a number of distribution given by
ds and weighted by weight |
double |
getLocalScoreFor(Sequence seq,
int i)
Returns the score for the symbol at this
BNDiffSMParameterTree starting
from offset i |
byte |
getMaximalMarkovOrder()
Returns the maximal Markov order of this tree.
|
double |
getMaximumScore()
Returns the maximum score in this tree.
|
int |
getNumberOfParents()
Returns the number of parents for the random variable of this
BNDiffSMParameterTree in the network structure of the enclosing
BayesianNetworkDiffSM. |
BNDiffSMParameter |
getParameterFor(int[] seq,
int start)
Returns the
BNDiffSMParameter that is responsible for the suffix of
sequence seq starting at position start. |
BNDiffSMParameter |
getParameterFor(Sequence seq,
int start)
Returns the
BNDiffSMParameter that is responsible for the suffix of
sequence seq starting at position start. |
int[] |
getParameterIndexesForSamplingStep(int step,
int offset)
Returns the indexes of the parameters, incremented by
offset, that
shall be sampled in step step of a grouped sampling process. |
double |
getProbFor(Sequence sequence)
|
void |
initializeRandomly(double ess)
Initializes the parameters of this
BNDiffSMParameterTree randomly. |
void |
insertProbs(double[] probs)
Computes the probabilities for a PWM, i.e.
|
void |
invalidateNormalizers()
Resets all pre-computed normalization constants.
|
boolean |
isLeaf()
Indicates if the random variable of this
BNDiffSMParameterTree is a
leaf, i.e. |
LinkedList<BNDiffSMParameter> |
linearizeParameters()
Extracts the
BNDiffSMParameters from the leaves of this tree in
left-to-right order (as specified by the order of the alphabet) and
returns them as a LinkedList. |
void |
normalizeParameters()
Normalizes the parameter values to the corresponding log-probabilities.
|
void |
normalizePlugInParameters()
Starts the normalization of the plug-in parameters to the logarithm of the
MAP-estimates.
|
void |
print()
Prints the structure of this tree.
|
void |
setParameterFor(int symbol,
int[][] context,
BNDiffSMParameter par)
Sets the instance of the
BNDiffSMParameter for symbol symbol and
context context to BNDiffSMParameter par. |
String |
toHtml(NumberFormat nf)
Returns an HTML representation of this tree.
|
String |
toString(NumberFormat nf)
Returns a string representation of this tree using the provided
NumberFormat. |
StringBuffer |
toXML()
Works as defined in
Storable. |
public BNDiffSMParameterTree(int pos,
int[] contextPoss,
AlphabetContainer alphabet,
int firstParent,
int[] firstChildren)
BNDiffSMParameterTree for the parameters at position
pos using the parent positions in contextPoss.
These are used to extract the correct alphabet out of
alphabet for every context position. The first parent is the
first parent of the random variable at pos as given by the
topological ordering of the network structure of the enclosing
BayesianNetworkDiffSM. The first children are the
children the random variable at pos is the first parent for.pos - the position of the random variable of the parameters in the
treecontextPoss - the positions of the contextalphabet - the alphabet of the enclosing
BayesianNetworkDiffSMfirstParent - the first parent of this random variable, or -1
if the random variable has no parentfirstChildren - the first children of this random variablepublic BNDiffSMParameterTree(StringBuffer source) throws NonParsableException
BNDiffSMParameterTree from its XML representation as
returned by toXML(). BNDiffSMParameterTree does not
implement the Storable interface to recycle the
AlphabetContainer of the enclosing
BayesianNetworkDiffSM, but besides the different
constructor works like any implementation of Storable.source - the XML representation as StringBufferNonParsableException - if the XML code could not be parsedpublic BNDiffSMParameterTree clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionpublic String toString(NumberFormat nf)
NumberFormat.nf - the number formatpublic void insertProbs(double[] probs)
throws Exception
probs. Used by
BayesianNetworkDiffSM.getPWM().probs - the array to store the probabilities for a PWMException - if the tree structure does have a non-empty contextpublic LinkedList<BNDiffSMParameter> linearizeParameters()
BNDiffSMParameters from the leaves of this tree in
left-to-right order (as specified by the order of the alphabet) and
returns them as a LinkedList.BNDiffSMParameters from the leaves in linear orderpublic boolean isLeaf()
BNDiffSMParameterTree is a
leaf, i.e. it has no children in the network structure of the enclosing
BayesianNetworkDiffSM.true if this tree is a leaf, false otherwisepublic int getNumberOfParents()
BNDiffSMParameterTree in the network structure of the enclosing
BayesianNetworkDiffSM. This corresponds to the length of
the context or the depth of the tree.public void print()
public BNDiffSMParameter getParameterFor(Sequence seq, int start)
BNDiffSMParameter that is responsible for the suffix of
sequence seq starting at position start.seq - the Sequencestart - the first position in the suffixBNDiffSMParameter that is responsible for the suffixpublic BNDiffSMParameter getParameterFor(int[] seq, int start)
BNDiffSMParameter that is responsible for the suffix of
sequence seq starting at position start.seq - the sequence encoded as int arraystart - the first position in the suffixBNDiffSMParameter that is responsible for the suffixpublic void setParameterFor(int symbol,
int[][] context,
BNDiffSMParameter par)
BNDiffSMParameter for symbol symbol and
context context to BNDiffSMParameter par.symbol - the symbolcontext - the contextpar - the new BNDiffSMParameter instancepublic void invalidateNormalizers()
public double forward(BNDiffSMParameterTree[] trees) throws RuntimeException
BNDiffSMParameterTree. This is only possible for roots, i.e.
BNDiffSMParameterTrees that do not have parents in the network structure
of the enclosing BayesianNetworkDiffSM.trees - the array of all trees as from the enclosing
BayesianNetworkDiffSMRuntimeException - if this BNDiffSMParameterTree is not a rootpublic void backward(BNDiffSMParameterTree[] trees, int[][] order) throws RuntimeException
BNDiffSMParameterTree. This is only possible for
leaves, i.e. BNDiffSMParameterTrees that do not have children in the
network structure of the enclosing BayesianNetworkDiffSM.trees - the array of all trees as from the enclosing
BayesianNetworkDiffSMorder - the topological ordering as returned by
TopSort.getTopologicalOrder(int[][])RuntimeException - if this BNDiffSMParameterTree is not a leafpublic void addCount(Sequence seq, int start, double count)
count to the parameter as returned by
getParameterFor(Sequence, int).seq - the sequencestart - the first position of the suffix of seqcount - the added countpublic void normalizePlugInParameters()
public void normalizeParameters()
BayesianNetworkDiffSM.getLogNormalizationConstant() should
return 0.public void divideByUnfree()
BNDiffSMParameter, which is defined not to be free. In the log-space this amounts
to subtracting the value of the last BNDiffSMParameter from all BNDiffSMParameters on the
simplex.public StringBuffer toXML()
Storable.
Returns an XML representation of this BNDiffSMParameterTree.toXML in interface StorableBNDiffSMParameterTreeStorable.toXML()public int getFirstParent()
BNDiffSMParameterTree in the topological ordering of the network
structure of the enclosing BayesianNetworkDiffSM.public void drawKLDivergences(double weight,
double[] kls,
int startIdx,
int endIdx,
double[][][] contrast,
double samples)
contrast and
endIdx-startIdx distributions drawn from a Dirichlet density centered around contrast, i.e. the hyper-parameters
of the Dirichlet density are the probabilities of contrast weighted by samples. The drawn KL-divergences are stored
into kls between startIndex and endIndex (exclusive).weight - a weight on the KL-divergenceskls - the array of KL-divergences which is filledstartIdx - the first indexendIdx - the index after the last indexcontrast - the distribution to check againstsamples - number of sequences + equivalent sample sizepublic double getKLDivergence(double[][][] ds)
BNDiffSMParameterTree and the distribution given by
ds.ds - the distributionpublic double getKLDivergence(double[] weight,
double[][][][] distribution)
BNDiffSMParameterTree and a number of distribution given by
ds and weighted by weightdistribution - the distributionweight - the weights on the distributionspublic void drawKLDivergences(double[] kls,
double[] weights,
double[][][][] contrast,
double samples)
contrast[i] each weighted by weights[i]
kls.length distributions drawn from a Dirichlet density centered around contrast, i.e. the hyper-parameters
of the Dirichlet density are the probabilities of contrast weighted by samples. The drawn KL-divergences are added
to the entries of kls.kls - the array of KL-divergences which is filledweights - the weights on the distributions in contrastcontrast - the distribution to check againstsamples - number of sequences + equivalent sample sizepublic void fill(double[] weight,
double[][][][] distribution)
distribution.distribution - the distributionweight - the weights on the distributionspublic void copy(BNDiffSMParameterTree parameterTree)
BNDiffSMParameterTree.parameterTree - the templatepublic void initializeRandomly(double ess)
BNDiffSMParameterTree randomly.ess - the equivalent sample sizepublic Double computeGammaNorm()
public double getProbFor(Sequence sequence)
sequence - the sequencepublic int[] getParameterIndexesForSamplingStep(int step,
int offset)
offset, that
shall be sampled in step step of a grouped sampling process.step - the stepoffset - the offset on the parameter indexespublic byte getMaximalMarkovOrder()
public double getMaximumScore()
public String toHtml(NumberFormat nf)
nf - the number formatpublic double getLocalScoreFor(Sequence seq, int i)
BNDiffSMParameterTree starting
from offset iseq - the sequencei - the offset