|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.scoringFunctions.directedGraphicalModels.ParameterTree
public class ParameterTree
Class for the tree that represents the context of a Parameter
in a
BayesianNetworkScoringFunction
.
Constructor Summary | |
---|---|
ParameterTree(int pos,
int[] contextPoss,
AlphabetContainer alphabet,
int firstParent,
int[] firstChildren)
Creates a new ParameterTree for the parameters at position
pos using the parent positions in contextPoss . |
|
ParameterTree(StringBuffer source,
AlphabetContainer alphabet)
Recreates a ParameterTree from its XML representation as
returned by toXML() . |
Method Summary | |
---|---|
void |
addCount(Sequence seq,
int start,
double count)
Adds count to the parameter as returned by
getParameterFor(Sequence, int) . |
void |
backward(ParameterTree[] trees,
int[][] order)
Computes the backward-part of the normalization constant starting from this ParameterTree . |
ParameterTree |
clone()
|
Double |
computeGammaNorm()
Computes the Gamma-normalization for the prior. |
void |
copy(ParameterTree parameterTree)
Copies the values of the parameters from another ParameterTree . |
void |
divideByUnfree()
Divides each of the normalized parameters on a simplex by the last Parameter , 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. the hyper-parameters
of the Dirichlet density are the probabilities of contrast weighted by samples . |
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. the hyper-parameters
of the Dirichlet density are the probabilities of contrast weighted by samples . |
void |
fill(double[][][] fillEmptyWith)
Fills all parameters with the probabilities given in fillEmptyWith . |
double |
forward(ParameterTree[] trees)
Computes the forward-part of the normalization constant starting from this ParameterTree . |
static ParameterTree[] |
fromStringArray(String[] strs,
AlphabetContainer alphabet)
Recreates an array of ParameterTree s from their
XML representation as given in strs . |
int |
getFirstParent()
Returns the first parent of the random variable of this ParameterTree in the topological ordering of the network
structure of the enclosing BayesianNetworkScoringFunction . |
double |
getKLDivergence(double[][][] ds)
Returns the KL-divergence of the distribution of this ParameterTree and the distribution given by
ds as returned by VariableLengthScoringFunction.getAllConditionalStationaryDistributions() |
double |
getKLDivergence(double[] weight,
double[][][][] distribution)
Returns the KL-divergence of the distribution of this ParameterTree and a number of distribution given by
ds as returned by VariableLengthScoringFunction.getAllConditionalStationaryDistributions() and weighted by weight |
int |
getNumberOfParents()
Returns the number of parents for the random variable of this ParameterTree in the network structure of the enclosing
BayesianNetworkScoringFunction . |
Parameter |
getParameterFor(Sequence seq,
int start)
Returns the Parameter that is responsible for the suffix of
sequence seq starting at position start . |
void |
initializeRandomly(double ess)
Initializes the parameters of this ParameterTree randomly. |
void |
insertProbs(double[] probs)
Computes the probabilities for a PWM, i.e. the parameters in the tree have an empty context, and inserts them into probs . |
void |
invalidateNormalizers()
Resets all pre-computed normalization constants. |
boolean |
isLeaf()
Indicates if the random variable of this ParameterTree is a
leaf, i.e. it has no children in the network structure of the enclosing
BayesianNetworkScoringFunction . |
LinkedList<Parameter> |
linearizeParameters()
Extracts the Parameter s 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,
Parameter par)
Sets the instance of the Parameter for symbol symbol and
context context to Parameter par . |
String |
toString()
|
static String[] |
toStringArray(ParameterTree[] trees)
Creates a String array from the XML representation of all
ParameterTree s in trees as returned by the
corresponding toXML() methods. |
StringBuffer |
toXML()
Works as defined in Storable . |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ParameterTree(int pos, int[] contextPoss, AlphabetContainer alphabet, int firstParent, int[] firstChildren)
ParameterTree
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
BayesianNetworkScoringFunction
. 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
BayesianNetworkScoringFunction
firstParent
- the first parent of this random variable, or -1
if the random variable has no parentfirstChildren
- the first children of this random variablepublic ParameterTree(StringBuffer source, AlphabetContainer alphabet) throws NonParsableException
ParameterTree
from its XML representation as
returned by toXML()
. ParameterTree
does not
implement the Storable
interface to recycle the
AlphabetContainer
of the enclosing
BayesianNetworkScoringFunction
, but besides the different
constructor works like any implementation of Storable
.
source
- the XML representation as StringBuffer
alphabet
- the alphabet
NonParsableException
- if the XML code could not be parsedMethod Detail |
---|
public ParameterTree clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public String toString()
toString
in class Object
public void insertProbs(double[] probs) throws Exception
probs
. Used by
BayesianNetworkScoringFunction.getPWM()
.
probs
- the array to store the probabilities for a PWM
Exception
- if the tree structure does have a non-empty contextpublic LinkedList<Parameter> linearizeParameters()
Parameter
s 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
.
Parameter
s from the leaves in linear orderpublic boolean isLeaf()
ParameterTree
is a
leaf, i.e. it has no children in the network structure of the enclosing
BayesianNetworkScoringFunction
.
true
if this tree is a leaf, false
otherwisepublic int getNumberOfParents()
ParameterTree
in the network structure of the enclosing
BayesianNetworkScoringFunction
. This corresponds to the length of
the context or the depth of the tree.
public void print()
public Parameter getParameterFor(Sequence seq, int start)
Parameter
that is responsible for the suffix of
sequence seq
starting at position start
.
seq
- the Sequence
start
- the first position in the suffix
Parameter
that is responsible for the suffixpublic void setParameterFor(int symbol, int[][] context, Parameter par)
Parameter
for symbol symbol
and
context context
to Parameter
par
.
symbol
- the symbolcontext
- the contextpar
- the new Parameter
instancepublic void invalidateNormalizers()
public double forward(ParameterTree[] trees) throws RuntimeException
ParameterTree
. This is only possible for roots, i.e.
ParameterTree
s that do not have parents in the network structure
of the enclosing BayesianNetworkScoringFunction
.
trees
- the array of all trees as from the enclosing
BayesianNetworkScoringFunction
RuntimeException
- if this ParameterTree
is not a rootpublic void backward(ParameterTree[] trees, int[][] order) throws RuntimeException
ParameterTree
. This is only possible for
leaves, i.e. ParameterTree
s that do not have children in the
network structure of the enclosing BayesianNetworkScoringFunction
.
trees
- the array of all trees as from the enclosing
BayesianNetworkScoringFunction
order
- the topological ordering as returned by
TopSort.getTopologicalOrder(int[][])
RuntimeException
- if this ParameterTree
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 seq
count
- the added countpublic void normalizePlugInParameters()
public void normalizeParameters()
BayesianNetworkScoringFunction.getNormalizationConstant()
should
return 1.
public void divideByUnfree()
Parameter
, which is defined not to be free. In the log-space this amounts
to subtracting the value of the last Parameter
from all Parameter
s on the
simplex.
public StringBuffer toXML()
Storable
.
Returns an XML representation of this ParameterTree
.
ParameterTree
Storable.toXML()
public static String[] toStringArray(ParameterTree[] trees)
String
array from the XML representation of all
ParameterTree
s in trees
as returned by the
corresponding toXML()
methods.
trees
- the array of ParameterTree
s, e.g. as returned by fromStringArray(String[], AlphabetContainer)
ParameterTree
s as String
arrayfromStringArray(String[], AlphabetContainer)
public static ParameterTree[] fromStringArray(String[] strs, AlphabetContainer alphabet) throws NonParsableException
ParameterTree
s from their
XML representation as given in strs
.
strs
- the XML representations as String
array, e.g. as returned by
toStringArray(ParameterTree[])
alphabet
- the alphabet of the enclosing
BayesianNetworkScoringFunction
ParameterTree
s
NonParsableException
- if one of the XML representations could not be
parsedtoStringArray(ParameterTree[])
public int getFirstParent()
ParameterTree
in the topological ordering of the network
structure of the enclosing BayesianNetworkScoringFunction
.
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).
kls
- the array of KL-divergences which is filledstartIdx
- the first indexendIdx
- the index after the last indexcontrast
- the distribution to check against, as returned by VariableLengthScoringFunction.getAllConditionalStationaryDistributions()
samples
- number of sequences + equivalent sample sizepublic double getKLDivergence(double[][][] ds)
ParameterTree
and the distribution given by
ds
as returned by VariableLengthScoringFunction.getAllConditionalStationaryDistributions()
ds
- the distribution
public double getKLDivergence(double[] weight, double[][][][] distribution)
ParameterTree
and a number of distribution given by
ds
as returned by VariableLengthScoringFunction.getAllConditionalStationaryDistributions()
and weighted by weight
distribution
- the distributionweight
- the weights on the distributions
public 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 against, as returned by VariableLengthScoringFunction.getAllConditionalStationaryDistributions()
samples
- number of sequences + equivalent sample sizepublic void fill(double[][][] fillEmptyWith)
fillEmptyWith
.
fillEmptyWith
- the replacementpublic void copy(ParameterTree parameterTree)
ParameterTree
.
parameterTree
- the templatepublic void initializeRandomly(double ess)
ParameterTree
randomly.
ess
- the equivalent sample sizepublic Double computeGammaNorm()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |