phylox.generators.mcmc.base
Functions
|
Computes the acceptance probability of a move. |
- phylox.generators.mcmc.base.acceptance_probability(network, result_network, move, move_type_probabilities, number_of_leaves=None, current_reticulation_number=None, symmetries=False)
Computes the acceptance probability of a move.
- Parameters:
network – the network before the move.
result_network – the network after the move.
move – the move.
move_type_probabilities – the move type probabilities.
number_of_leaves – the number of leaves in the network.
current_reticulation_number – the current number of reticulations in the network.
symmetries – whether to correct for symmetries.
- Returns:
the acceptance probability of the move.
- phylox.generators.mcmc.base.sample_mcmc_networks(starting_network, move_type_probabilities, restriction_map=None, correct_symmetries=True, burn_in=1000, number_of_samples=1, add_root_if_necessary=False, seed=None)
Samples phylogenetic networks using a Markov-Chain Monte Carlo method.
- Parameters:
starting_network – the phylox.DiNetwork used as the starting point of the Markov chain.
move_type_probabilities – a dictionary mapping MoveTypes to probabilities.
restriction_map – a boolean function that takes a phylox.DiNetwork as input.
correct_symmetries – whether to correct for symmetries in the acceptance probability, set to True for uniform distribution.
burn_in – the number of steps (including rejected proposals) between each sample.
number_of_samples – the number of networks to sample.
add_root_if_necessary – whether to add a root edge to each root if it has out-degree > 1.
seed – the seed for the random number generator.
- Returns:
a list of phylox.DiNetwork objects.
- Example:
>>> from phylox import DiNetwork >>> from phylox.rearrangement.movetype import MoveType >>> from phylox.generators.mcmc import sample_mcmc_networks >>> starting_network = DiNetwork( ... edges = ((0,1), (0,2), (1,2), (1,3), (2,4)), ... labels = ((3, "A"), (4, "B")), ... ) >>> move_type_probabilities = { ... MoveType.TAIL: 0.2, ... MoveType.VPLU: 0.4, ... MoveType.VMIN: 0.4, ... } >>> restriction_map = (lambda nw: nw.reticulation_number < 2) >>> sampled_networks = sample_mcmc_networks( ... starting_network, ... move_type_probabilities, ... restriction_map=restriction_map, ... correct_symmetries=False, ... burn_in=100, ... number_of_samples=50, ... add_root_if_necessary=False, ... seed=1, ... ) >>> all([network.reticulation_number<2 for network in sampled_networks]) True >>> all([len(network.leaves)==2 for network in sampled_networks]) True