PhyNetPy Documentation

Library for the Development and Use of Phylogenetic Network Methods

MetropolisHastings Module v1.0.0

Metropolis-Hastings MCMC and Hill Climbing search algorithms for phylogenetic inference.

Author:
Mark Kessler
Last Edit:
3/11/25
Source:
MetropolisHastings.py

Exceptions

exception HillClimbException(Exception)

This exception is raised when there is an error running the Hill Climbing algorithm.

exception MetropolisHastingsException(Exception)

This exception is raised when there is an error running the Metropolis Hastings algorithm.

ProposalKernel

class ProposalKernel(ABC)

Abstract class that defines proposal kernel behavior. In general, simply must have a generate method that spits out a move.

Constructor

__init__() -> None

Initialize a proposal kernel

Methods

generate -> Move abstract

*ABSTRACT METHOD* Generate the next move for a model to apply to the network.

Returns: Move: Any newly instantiated object that is a subclass of Move.

Infer_MP_Allop_Kernel

class Infer_MP_Allop_Kernel(ProposalKernel)

Proposal kernel for the Infer_MP_Allop_2.0 method.

Constructor

__init__() -> None

Initialize proposal kernel for the Infer_MP_Allop_2.0 method.

Methods

generate -> SwitchParentage

Simply return a new SwitchParentage object.

Returns: SwitchParentage: A new switch parentage move.

HillClimbing

class HillClimbing

Class that implements the Hill Climbing search method.

Constructor

__init__(pkernel: ProposalKernel, submodel: GTR = None, data: Matrix | None = None, model: Model | None = None, num_iter: int = 500, stochastic: int = -1, enhanced_stop: bool = True) -> None

Initialize a Hill Climb search.

Parameter Type Description
pkernel ProposalKernel Some proposal kernel
submodel GTR, optional A substitution model. Defaults to JC.
data Matrix | None, optional A data matrix. Defaults to None.
model Model | None, optional A Model obj. Defaults to None.
num_iter int, optional Number of iterations. Defaults to 500.
stochastic int, optional Random seed. Defaults to -1.
enhanced_stop bool, optional Early stopping flag. Defaults to True.

Methods

run -> State

Run the hill climbing algorithm.

Returns: State: The final end state of the model.
run_many(count: int) -> list[float]

Runs the hill climbing algorithm 'count' times.

Parameter Type Description
count int the number of times to run.
Returns: list[float]: [mean, median, max, min]

MetropolisHastings

class MetropolisHastings

A special case of Hill Climbing, in which moves are accepted even if the score is not an improvement, based on the Hastings Ratio.

Constructor

__init__(pkernel: ProposalKernel, submodel: GTR = None, data: Matrix | None = None, model: Model | None = None, num_iter: int = 500) -> None

Initialize a Metropolis Hastings search.

Parameter Type Description
pkernel ProposalKernel A proposal kernel.
submodel GTR, optional A substitution model. Defaults to JC.
data Matrix | None, optional The data. Defaults to None.
model Model | None, optional A phylogenetic model. Defaults to None.
num_iter int, optional Number of iterations. Defaults to 500.

Methods

run -> State

Run the Metropolis-Hastings algorithm.

Returns: State: The end state.
run_many_different_start(count: int, format_stats: bool = True) -> list[float]

Runs the MH algorithm 'count' times.

Parameter Type Description
count int The number of times to run.
format_stats bool Flag to print stats.
Returns: list[float]: [mean, median, max, min]

Navigation

Modules

This Page