|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstatalign.base.Utils
public class Utils
This class contains multi-purpose static functions.
Field Summary | |
---|---|
static boolean |
DEBUG
Debugging mode (various consistency checks done if on) |
static boolean |
DOWNWEIGHT_INDEL_LIKELIHOOD
If true then we downweight the indel contribution to the overall likelihood. |
static org.apache.commons.math3.random.RandomGenerator |
generator
The random number generator used throughout the program. |
static double |
LEAF_COUNT_POW
Power determining how much we favour realigning the larger subtree first when doing a nearest-neighbour interchange move. |
static double |
log0
log(0) is set to Double.NEGATIVE_INFINITY. |
static double |
LOW_COUNT_MULTIPLIER
|
static int |
LOW_COUNT_THRESHOLD
|
static double |
MAX_ACCEPTANCE
During the burnin, the proposalWidthControlVariable for all continuous parameters is adjusted in order to ensure that the average acceptance rate is between MIN_ACCEPTANCE and MAX_ACCEPTANCE where possible. |
static int |
MAX_SILENT_LENGTH
|
static double |
MIN_ACCEPTANCE
During the burnin, the proposalWidthControlVariable for all McmcMove objects is adjusted (if McmcMove.autoTune=true ) in order to ensure that the average
acceptance rate is between MIN_ACCEPTANCE and MAX_ACCEPTANCE where possible. |
static double |
MIN_EDGE_LENGTH
|
static double |
MIN_SAMPLES_FOR_ACC_ESTIMATE
Number of samples during burnin used to get a rough estimate of the current acceptance rate, for the purposes of tuning the proposal variance control parameters. |
static int |
MIN_SEQ_LENGTH
Minimum length for internal node sequence. |
static boolean |
SHAKE_IF_STUCK
If true then during the first half of the burnin
if a particular McmcMove has been below its minimum acceptance
rate for at least (LOW_COUNT_THRESHOLD * MIN_SAMPLES_FOR_ACC_ESTIMATE)
iterations, then for the purposes of computing the acceptance
ratio, we multiply the new log likelihood by LOW_COUNT_MULTIPLIER
raised to a power that increases with the number of iterations
beyond the threshold. |
static double |
SILENT_INSERT_PROB
|
static double |
SPAN_MULTIPLIER
During the burnin, the proposalWidthControlVariable for all continuous parameters is adjusted in order to ensure that the average acceptance rate is between MIN_ACCEPTANCE and MAX_ACCEPTANCE where possible. |
static boolean |
USE_FULL_WINDOWS
If this is set to true then the alignment moves operate
on the whole alignment rather than selecting subwindows. |
static boolean |
USE_INDEL_CORRECTION_FACTOR
If true then we divide out the stationary probability of the internal nodes from the indel likelihood, as per Redelings and Suchard (2005), using the TKF92 stationary distribution defined in Thorne et al. (1992). |
static boolean |
USE_MODEXT_EM
If true, then ModelExtensions are allowed to offer a contribution to the emission probability used to compute the dynamic programming matrices for alignment proposals. |
static boolean |
USE_MODEXT_UPP
If true, then ModelExtensions are allowed to offer an upper contribution to the emission probability used to compute the dynamic programming matrices for alignment proposals. |
static boolean |
USE_UPPER
Whether to use information from the upper parts of the tree in order to fill out the hmm2 and hmm3
matrices. |
static boolean |
VERBOSE
|
static double |
WINDOW_MULTIPLIER
Initial value for the alignment proposal window length multiplier. |
Method Summary | ||
---|---|---|
static java.lang.String[] |
alignmentTransformation(java.lang.String[] s,
java.lang.String[] names,
java.lang.String type,
InputData input)
Transforms an alignment into the prescribed format |
|
static double |
calcEmProb(double[] fel,
double[] aaEquDist)
Calculates emission probability from Felsenstein likelihoods |
|
static int |
chooseOne(double prob,
statalign.base.MuDouble selectLogLike)
Behaves exactly like weightedChoose(new double[]{1-prob,prob}, selectLogLike), but faster |
|
static java.util.List<java.lang.String> |
classesInPackage(java.lang.String packageName)
Finds all classes in a given package and all of its subpackages by walking through class path. |
|
static java.lang.String |
convertTime(long x)
Takes a time in milliseconds and converts to a string to be printed. |
|
static char[] |
copyOf(char[] array)
|
|
static double[] |
copyOf(double[] array)
|
|
static int[] |
copyOf(int[] array)
|
|
static
|
findPlugins(java.lang.Class<T> superClass)
Locates all plugins that are descendants of the specified plugin superclass. |
|
static boolean |
isValidHistory(boolean p,
boolean g,
boolean[] neighb)
For a tree of the form: gg / g / \ p u / \ t b this function determines valid possible indel states for p and g
given fixed states for the neighbouring nodes. |
|
static boolean |
isValidHistory(boolean p,
boolean g,
boolean[] neighb,
boolean gIsRoot)
For a tree of the form: gg / g / \ p u / \ t b or, if gIsRoot = true , then for a tree of the form
g
/ \
p u
/ \
t b
this function determines valid possible indel states for p and g
given fixed states for the neighbouring nodes. |
|
static
|
iterate(java.util.Enumeration<T> en)
Makes Enumeration iterable. |
|
static java.lang.String |
joinStrings(java.lang.Object[] strs,
java.lang.String separator)
Joins strings using a separator string. |
|
static java.lang.String |
joinStrings(java.lang.Object[] strs,
java.lang.String prefix,
java.lang.String separator)
Joins strings using a prefix and a separator string. |
|
static int |
linearizerWeight(int length,
statalign.base.MuDouble selectLike,
double expectedLength)
This function selects a random integer with expected value given by expectedLength. |
|
static double |
linearizerWeightProb(int length,
int index,
double expectedLength)
This function returns the probability of choosing a particular index with linearizerWeight. |
|
static double |
logAdd(double a,
double b)
Logarithmically add two numbers |
|
static double |
logBetaDensity(double x,
double alpha,
double beta)
|
|
static double |
logGammaDensity(double x,
double shape,
double rate)
|
|
static int |
logWeightedChoose(double[] logWeights)
|
|
static int |
logWeightedChoose(double[] logWeights,
statalign.base.MuDouble selectLogLike)
Equivalent to weightedChoose(weights, selectLogLike) where logWeights[i] = Math.log(weights[i]), but avoids overflows that might result from exponentiation. |
|
static int |
minMax(int value,
int min,
int max)
|
|
static java.lang.String |
repeatedString(java.lang.String s,
int n)
|
|
static int |
weightedChoose(double[] weights)
|
|
static int |
weightedChoose(double[] weights,
statalign.base.MuDouble selectLogLike)
Similar to weightedChoose(weights), but the log-probability of the selection will be subtracted from the mutable double object selectLogLike (reason: proposal is in the denominator of acceptance ratio) (MuDouble is used to allow for another return value, in C++ a double pointer/reference could be used instead) |
|
static int |
weightedChoose(int[] weights)
This function returns a random index, weighted by the weights in the array `weights' |
|
static int |
weightedChoose(java.util.List<java.lang.Double> weights,
statalign.base.MuDouble selectLogLike)
|
|
static int |
weightedChoose(java.util.List<java.lang.Integer> weights)
This function returns a random index, weighted by the weights in the array `weights' |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static boolean DEBUG
public static boolean USE_FULL_WINDOWS
true
then the alignment moves operate
on the whole alignment rather than selecting subwindows. This
is usually much slower.
public static boolean USE_MODEXT_EM
public static boolean USE_MODEXT_UPP
public static boolean USE_UPPER
hmm2
and hmm3
matrices.
public static double LEAF_COUNT_POW
public static org.apache.commons.math3.random.RandomGenerator generator
public static final double SPAN_MULTIPLIER
public static final double MIN_ACCEPTANCE
McmcMove.autoTune=true
) in order to ensure that the average
acceptance rate is between MIN_ACCEPTANCE and MAX_ACCEPTANCE where possible.
This is done by repeatedly multiplying the proposalWidthControlVariable
by SPAN_MULTIPLIER until the acceptance falls within the desired range.
public static final double MAX_ACCEPTANCE
public static double WINDOW_MULTIPLIER
public static final double MIN_SAMPLES_FOR_ACC_ESTIMATE
public static final double log0
public static final double MIN_EDGE_LENGTH
public static final int MIN_SEQ_LENGTH
public static final boolean DOWNWEIGHT_INDEL_LIKELIHOOD
public static final boolean USE_INDEL_CORRECTION_FACTOR
public static final int LOW_COUNT_THRESHOLD
public static final double LOW_COUNT_MULTIPLIER
public static final boolean SHAKE_IF_STUCK
true
then during the first half of the burnin
if a particular McmcMove has been below its minimum acceptance
rate for at least (LOW_COUNT_THRESHOLD * MIN_SAMPLES_FOR_ACC_ESTIMATE)
iterations, then for the purposes of computing the acceptance
ratio, we multiply the new log likelihood by LOW_COUNT_MULTIPLIER
raised to a power that increases with the number of iterations
beyond the threshold. This gradually favours the state jumping,
which may be useful to avoid getting stuck in local modes during the
burnin. Ideally such a scheme should not be needed, however.
public static final int MAX_SILENT_LENGTH
public static final double SILENT_INSERT_PROB
public static boolean VERBOSE
Method Detail |
---|
public static double logGammaDensity(double x, double shape, double rate)
x
- shape
- rate
-
public static double logBetaDensity(double x, double alpha, double beta)
x
- alpha
- beta
-
public static int linearizerWeight(int length, statalign.base.MuDouble selectLike, double expectedLength)
length
- The length of the array we need.selectLike
- A mutable double object to return the selection probabilityexpectedLength
- The expected window length.
public static double linearizerWeightProb(int length, int index, double expectedLength)
length
- Distribution parameter as in linearizerWeightindex
- Selected index
public static int weightedChoose(int[] weights)
public static int weightedChoose(java.util.List<java.lang.Integer> weights)
public static int weightedChoose(double[] weights, statalign.base.MuDouble selectLogLike)
public static int weightedChoose(double[] weights)
public static int weightedChoose(java.util.List<java.lang.Double> weights, statalign.base.MuDouble selectLogLike)
public static int chooseOne(double prob, statalign.base.MuDouble selectLogLike)
public static int logWeightedChoose(double[] logWeights, statalign.base.MuDouble selectLogLike)
public static int logWeightedChoose(double[] logWeights)
public static boolean isValidHistory(boolean p, boolean g, boolean[] neighb)
gg / g / \ p u / \ t bthis function determines valid possible indel states for
p
and g
given fixed states for the neighbouring nodes.
p
- The presence/absence of node p
.g
- The presence/absence of node b
.neighb
- An array indicating the state of the neighbouring nodes, in the order
{t,b,u,gg}
.
p
and b
are compatible with the neighbouring states.public static boolean isValidHistory(boolean p, boolean g, boolean[] neighb, boolean gIsRoot)
gg / g / \ p u / \ t bor, if
gIsRoot = true
, then for a tree of the form
g / \ p u / \ t bthis function determines valid possible indel states for
p
and g
given fixed states for the neighbouring nodes.
gIsRoot
- This is true
if g
is the root of the tree.p
- The presence/absence of node p
.g
- The presence/absence of node b
.neighb
- An array indicating the state of the neighbouring nodes, in the order
{t,b,u,gg}
(if gIsRoot=false
), or {t,b,u}
(if gIsRoot=true
).
p
and b
are compatible with the neighbouring states.public static java.lang.String convertTime(long x)
x
- The time to be formatted, in milliseconds (as a long).
public static double logAdd(double a, double b)
a
- log(x)b
- log(y)
public static double calcEmProb(double[] fel, double[] aaEquDist)
public static java.lang.String repeatedString(java.lang.String s, int n)
public static <T> java.lang.Iterable<T> iterate(java.util.Enumeration<T> en)
T
- Enumeration element typeen
- the Enumeration
public static java.lang.String joinStrings(java.lang.Object[] strs, java.lang.String separator)
Object
s
converting them to strings using their toString
method.
strs
- strings to joinseparator
- the separator string
public static java.lang.String joinStrings(java.lang.Object[] strs, java.lang.String prefix, java.lang.String separator)
Object
s converting them to strings using their
toString
method.
strs
- strings to joinprefix
- prefix for each stringseparator
- the separator string
public static java.util.List<java.lang.String> classesInPackage(java.lang.String packageName)
packageName
- the package in which the classes are searched for
public static <T> java.util.List<T> findPlugins(java.lang.Class<T> superClass)
root.plugins
where root
refers
to the package of the superclass.
superClass
- the ancestral plugin class
public static java.lang.String[] alignmentTransformation(java.lang.String[] s, java.lang.String[] names, java.lang.String type, InputData input)
s
- String array containing the alignment in StatAlign formattype
- The name of the format, might be "StatAlign", "Clustal", "Fasta", "Phylip", "Nexus"input
- The input data. Needed for the Nexus format that needs
a name of the alignment (set to input.title) the type of the alignment (either
nucleotide or protein, read from input.model) and the list of characters
in the substitution model (also read from input.model).
public static char[] copyOf(char[] array)
public static int[] copyOf(int[] array)
public static double[] copyOf(double[] array)
public static int minMax(int value, int min, int max)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |