ivy.chars.mk_mr module¶
-
class
ivy.chars.mk_mr.
ModelOrderMetropolis
(stochastic)[source]¶ Bases:
pymc.StepMethods.Metropolis
Custom step method for model order
-
class
ivy.chars.mk_mr.
SwitchpointMetropolis
(stochastic, tree, seg_map, stepsize=0.05, seglen=0.02)[source]¶ Bases:
pymc.StepMethods.Metropolis
Custom step algorithm for selecting a new switchpoint
-
ivy.chars.mk_mr.
create_likelihood_function_multimk
(tree, chars, Qtype, nregime, pi=u'Equal', findmin=True)[source]¶
-
ivy.chars.mk_mr.
create_likelihood_function_multimk_mods
(tree, chars, mods, pi=u'Equal', findmin=True, orderedparams=True)[source]¶ Create a likelihood function for testing the parameter values of user- specified models
-
ivy.chars.mk_mr.
create_mkmr_ar
(tree, chars, nregime, findmin=True)[source]¶ Create preallocated arrays. For use in mk function
Nodelist = edgelist of nodes in postorder sequence
-
ivy.chars.mk_mr.
create_mkmr_mb_ar
(tree, chars, nregime, findmin=True)[source]¶ Preallocated arrays for midbranch mk_mr
Create preallocated arrays. For use in mk_mr midbranch function
Nodelist = edgelist of nodes in postorder sequence
-
ivy.chars.mk_mr.
fill_model_mr_Q
(Qparams, mods, Q)[source]¶ Fill a Q-matrix with Qparams corresponding to the model.
Individual Q matrices are filled rowwise
Function alters Q in place
-
ivy.chars.mk_mr.
lf_mk_mr_midbranch_mods
(tree, chars, mods, pi=u'Equal', findmin=True, orderedparams=True)[source]¶ Create a likelihood function for testing the parameter values of user- specified models with switchpoints allowed in the middle of branches
-
ivy.chars.mk_mr.
locs_from_switchpoint
(tree, switches, locs=None)[source]¶ Given a tree and a list of nodes to be switchpoints, return an array of all node indices in one regime vs the other
Parameters: Returns: - Array of indices of all nodes associated with each switchpoint, plus
all nodes “outside” the switches in the last list
Return type: np.array
-
ivy.chars.mk_mr.
mk_mr_midbranch
(tree, chars, Qs, switchpoint, pi=u'Equal', returnPi=False, ar=None, debug=False)[source]¶ Calculate likelhiood of mk model with BAMM-like multiple regimes
Parameters: - tree (Node) – Root node of a tree. All branch lengths must be greater than 0 (except root)
- chars (dict) –
Dict mapping character states to tip labels. Character states should be coded 0,1,2...
Can also be a list with tip states in preorder sequence
- Qs (np.array) – Array of instantaneous rate matrices
- locs (np.array) – Array of the same length as Qs containing the node indices that correspond to each Q matrix
- p (np.array) – Optional pre-allocated p matrix
- pi (str or np.array) –
Option to weight the root node by given values. Either a string containing the method or an array of weights. Weights should be given in order.
Accepted methods of weighting root:
Equal: flat prior Equilibrium: Prior equal to stationary distribution
of Q matrix- Fitzjohn: Root states weighted by how well they
- explain the data at the tips.
Returns: Log-likelihood of tree/characters given the Q matrices.
Return type: (float)
-
ivy.chars.mk_mr.
mk_multi_bayes
(tree, chars, nregime, qidx, pi=u'Equal', seglen=0.02, stepsize=0.05)[source]¶ Create a Bayesian multi-mk model. User specifies which regime models to use and the Bayesian model finds the switchpoints.
Parameters: - tree (Node) – Root node of tree.
- chars (dict) – Dict mapping tip labels to discrete character states. Character states must be in the form of [0,1,2...]
- regime (int) – The number of distinct regimes to test. Set to 1 for an Mk model, set to greater than 1 for a multi-regime Mk model.
- qidx (np.array) –
Index specifying the model to test
- columns:
- 0, 1, 2 - index axes of q 3 - index of params
This scheme allows flexible specification of models. E.g.: Symmetric mk2:
- params = [0.2]; qidx = [[0,0,1,0],
- [0,1,0,0]]
- Asymmetric mk2:
- params = [0.2,0.6]; qidx = [[0,0,1,0],
- [0,1,0,1]]
Note
The qidx corresponding to the first q matrix (first column 0) is always the root regime
- pi (str or np.array) –
Option to weight the root node by given values. Either a string containing the method or an array of weights. Weights should be given in order.
Accepted methods of weighting root:
Equal: flat prior Equilibrium: Prior equal to stationary distribution
of Q matrix- Fitzjohn: Root states weighted by how well they
- explain the data at the tips.
- seglen (float) – Size of segments to break tree into. The smaller this value, the more “fine-grained” the analysis will be. Optional, defaults to 2% of the root-to-tip length.
- stepsize (float) – Maximum size of steps for switchpoints to take. Optional, defaults to 5% of root-to-tip length.
-
ivy.chars.mk_mr.
random_tree_location
(seg_map)[source]¶ Select random location on tree with uniform probability
Returns: - node and float, which represents the how far along the branch to
- the parent node the switch occurs on
Return type: tuple