ivy.chars.hrm_bayesian module¶
-
class
ivy.chars.hrm_bayesian.
QmatMetropolis
(stochastic, nparam, nchar, nregime)[source]¶ Bases:
pymc.StepMethods.Metropolis
Custom step algorithm for selecting a new model
-
class
ivy.chars.hrm_bayesian.
QmatMetropolis_mk
(stochastic, all_mods)[source]¶ Bases:
pymc.StepMethods.Metropolis
Custom step algorithm for selecting a new model
-
ivy.chars.hrm_bayesian.
ShiftedGamma
(shape, shift=1, name=u'ShiftedGamma')[source]¶ Gamma distribution that has been shifted by some constant.
-
ivy.chars.hrm_bayesian.
fill_model_Q
(mod, Qparams, Q)[source]¶ Create Q matrix given model and parameters.
Parameters: - mod (list) –
List of tuples. Code for the mode used. The first nregime tuples correspond to the within-regime transition rates for each regime. The last tuple corresponds to the between-regime transition rates. Ex. [(1, 2), (3, 4), (5, 6, 7, 8)] corresponds to a matrix of:
[-,1,5,-] [2,-,-,6] [7,-,-,3] [-,8,4,-] - Qparams (list) – List of floats corresponding to the values for slow, medium, fast, etc. rates. The first is always 0
- Q (np.array) – Pre-allocated Q matrix
- mod (list) –
-
ivy.chars.hrm_bayesian.
fill_model_mk
(mod, Qparams, Q, mask)[source]¶ Fill cells of Q with Qparams based on mod
-
ivy.chars.hrm_bayesian.
hrm_allmodels_bayes
(tree, chars, nregime, nparam, modseed, pi=u'Equal', dbname=None)[source]¶ Use an MCMC chain to fit a hrm model with a limited number of parameters.
The chain will step through different models, placing a prior on simpler models
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
- nregime (int) – Number of regimes
- nparam (int) – Number of unique parameters to allow in a model
- modseed (tuple) – Starting model for the MCMC chain. A tuple of ints. Must be a valid model or adjacent to at least one valid model.
- pi (str) – Either “Equal”, “Equilibrium”, or “Fitzjohn”. How to weight values at root node. Defaults to “Equal” Method “Fitzjohn” is not thouroughly tested, use with caution
-
ivy.chars.hrm_bayesian.
is_valid_model
(mod, nparam, nchar, nregime, mod_order)[source]¶ Check if a given model is valid
-
ivy.chars.hrm_bayesian.
make_qmat_stoch
(nobschar, nregime, nparam, mod_order_list, modseed, name=u'qmat_stoch')[source]¶ Make a stochastic to use for a model-changing step
-
ivy.chars.hrm_bayesian.
make_qmat_stoch_mk
(all_mods, name=u'qmat_stoch')[source]¶ Stochastic for use in model-changing step
-
ivy.chars.hrm_bayesian.
mk_allmodels_bayes
(tree, chars, nparam, pi=u'Equal', dbname=None)[source]¶ Fit an mk model with nparam parameters distributed about the Q matrix.
-
ivy.chars.hrm_bayesian.
new_hrm_model
(mod, nparam, nchar, nregime, mod_order)[source]¶ Return new, valid model by changing one parameter of current model
-
ivy.chars.hrm_bayesian.
number_connected
(mod, nchar, nregime, n_wr, n_br)[source]¶ Test how many regimes are connected in some way
-
ivy.chars.hrm_bayesian.
unique_models
(nchar, nregime, nparam)[source]¶ Create a list of all possible models for a Q matrix with nchar distinct character states and nregime distinct regimes, filling all cells with nparam + 0.
Parameters: Returns: - List of all unique models. Each item contains a tuple of the
within-regime parameters and a tuple of the between-regime parameters.
Return type: