PhyNetPy Documentation

Library for the Development and Use of Phylogenetic Network Methods

State Module v1.0.0

State management for MCMC accept/reject decisions with model validation.

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

State

class State

Class that implements accept/reject functionality for the Metropolis-Hastings algorithm. There are 2 model objects, one of which is the current state, and the other is the model used to test changes and moves to the current accepted version. Rejection is implemented by reverting the change on the proposed model (like git revert). Acceptance is implemented by duplicating the move on the current model (like git merge).

Constructor

__init__(model: Model | None = None, validate: Callable[[Model], bool] = acyclic_routine) -> None

Initialize a State. A State contains two models-- one current model, and one proposed model that contains one singular edit to the current model. At the very beginning of the State and before the execution of a method, the two models will be carbon copies of each other.

Parameter Type Description
model Model | None, optional A Phylogenetic Model. Defaults to
None only used for if bootstrapping is to be used.
validate Callable[[Model], bool] A callable function that checks for model validity. The parameter for such a function should be a Model object, and return True if the Model is
valid False if not. Defaults to 'acyclic_routine', which checks that the Model's phylogenetic network is free of cycles.

Methods

likelihood -> float

Calculates the likelihood of the current model

Parameter Type Description
Returns a float that is the model likelihood for the current accepted state
generate_next(move: Move) -> bool

Set the proposed model to a new model that is the result of applying one move to the former proposed model

Parameter Type Description
move Move Any instantiated subclass of Move.
Returns: bool: True if the network associated with the model is valid, False otherwise.
revert(move: Move) -> None

Set the proposed model to the former proposed model, the move that was made was not a beneficial one.

Parameter Type Description
move Move Any instantiated subclass of Move.
commit(move: Move) -> None

The proposed change was beneficial. Make the same move on the current model as was made to the proposed model.

Parameter Type Description
move Move Any instantiated subclass of Move.
proposed -> Model

Grab the proposed model.

Returns: Model: The proposed / edited Model.
bootstrap(data: Matrix, submodel: GTR) -> None

Generate an initial state by 1) simulating a network 2) building a model based on that network and some input data. Currently only in use for the simplest case, a DNA/Felsenstein model.

Parameter Type Description
data Matrix The nexus file data that has been preprocessed by the Matrix class.
submodel GTR Any substitution model (can be subtype of GTR)
write_line_to_summary(line: str) -> None

Accumulate log output by appending line to the end of the current string. 'line' need not be new line terminated.

Parameter Type Description
line str logging information, plain text.
validate_proposed_network(prev_move: Move) -> bool

Check certain conditions on a network to check for validity.

Parameter Type Description
prev_move Move the move obj that was imposed on the current model
Returns: bool: True if valid, False otherwise.

Module Functions

acyclic_routine(model: Model) -> bool

Checks the Model's network for cycles.

Parameter Type Description
model Model A Model with a phylogenetic network.
Returns: bool: True if the model's network is free of cycles, False if it contains cycles.

Navigation

Modules

This Page