phylojunction.pgm package

Submodules

phylojunction.pgm.pgm module

class phylojunction.pgm.pgm.ConstantFn

Bases: ValueGenerator

Class for deterministically generating values.

An object is class whenever user input must be parsed and modified before it can be stored in a DAG node.

abstract property CT_FN_NAME
class phylojunction.pgm.pgm.DeterministicNodeDAG(node_name: str, value: List[Any] | None = None, call_order_idx: int | None = None, deterministic: bool = True, parent_nodes: List[NodeDAG] | None = None)

Bases: NodeDAG

Derived DAG node that holds value dependent on another node’s.

Deterministic node values depend deterministically on those from parent nodes. These nodes are used to modify and annotate stochastic node values.

get_node_stats_str(start: int, end: int, repl_idx: int) str
plot_node(axes: Axes, sample_idx: int | None = 0, repl_idx: int | None = 0, repl_size: int | None = 1, branch_attr: str | None = 'state', draw_reconstructed: bool | None = False) None
populate_operator_weight()
class phylojunction.pgm.pgm.DirectedAcyclicGraph

Bases: object

Directed acyclic graph (DAG) class defining the model.

Parameters:
  • node_val_dict (dict) – Dictionary with keys being DAG nodes, and values being the values stored in the nodes.

  • name_node_dict (dict) – Dictionary with keys being DAG node names, and the DAG nodes themselves as values.

  • n_nodes (int) – Total number of DAG nodes in the graph.

  • sample_size (int) – How many samples (simulations) to be either drawn or specified in every DAG node.

add_node(node_dag: NodeDAG) None
get_display_str_by_name(node_name, sample_idx=None, repl_size=1)
get_node_dag_by_name(node_name)
get_sorted_node_dag_list() List[NodeDAG]
n_nodes: int
name_node_dict: Dict[str, NodeDAG]
node_val_dict: Dict[NodeDAG, Any]
property random_seed: int
sample_size: int
class phylojunction.pgm.pgm.DistrForSampling

Bases: ValueGenerator

Class for randomly generating (i.e., sampling) values.

An object of this class is required by stochastic DAG nodes so values can be sampled.

abstract property DN_NAME: str
class phylojunction.pgm.pgm.NodeDAG(node_name: str, sample_size: int | None, replicate_size: int = 1, value: List[Any] | None = None, call_order_idx: int | None = None, sampled: bool = False, deterministic: bool = False, clamped: bool = False, parent_nodes: List[NodeDAG] | None = None)

Bases: ABC

Node class for building directed acyclic graphs (DAGs).

This class has abstract methods, so it cannot be instantiated. It is derived by StochasticNodeDAG and DeterministicNodeDAG

Parameters:
  • node_name (str) – Name of the node, e.g., ‘lambda’.

  • sample_size (int) – How many samples (simulations) to be either drawn or specified for the node.

  • replicate_size (int) – How many replicates (for each sample) to be drawn or specified the node. This is the size of a ‘plate’ in graphical notation. Defaults to 1.

  • value (object) – List of values associated to node. Defaults to None.

  • call_order_idx (int) – The order at which this node was added to DAG. If it is the first node of the DAG, for example, this value is 1. Defaults to None.

  • sampled (bool) – Flag specifying if what the ‘value’ attribute

  • to (stores are stochastic samples from a distribution. Defaults) – ‘False’.

  • deterministic (bool) – Flag specifying if what the ‘value’ attribute stores is the output of a deterministic function. Defaults to ‘False’.

  • clamped (bool) – Flag specifying if what the ‘value’ attribute stores is observed (i.e., data). Defaults to ‘False’.

  • parent_nodes (NodeDAG) – List of (parent) NodeDAG objects that are in the path between this node and the outermost layer in the DAG. Defaults to None.

call_order_idx: int
abstract get_node_stats_str(start: int, end: int, repl_idx: int) str
get_start2end_str(start: int, end: int, repl_idx: int = 0, is_tree: bool = False, display_reconstructed: bool = False) str

Get string representation of values within specific range.

is_clamped: bool
is_deterministic: bool
is_sampled: bool
node_name: str
parent_nd_list: List[NodeDAG] | None
abstract plot_node(axes: Axes, sample_idx: int = 0, repl_idx: int = 0, repl_size: int = 1, branch_attr: str | None = 'state', draw_reconstructed: bool | None = False) None
abstract populate_operator_weight() None
property repl_size
property sample_size
property value
class phylojunction.pgm.pgm.StochasticNodeDAG(node_name: str, sample_size: int, sampled_from: DistrForSampling | None = None, returned_from: ConstantFn | None = None, value: List[Any] | None = None, replicate_size: int = 1, call_order_idx: int | None = None, deterministic: bool = False, clamped: bool = False, parent_nodes: List[Any] | None = None)

Bases: NodeDAG

Derived DAG node that can generate own value.

This class is also used when a value is being specified by a user, or parsed from it. In other words, constant nodes in the graph are still stochastic DAG nodes under the hood.

Parameters:
  • sampling_dn (DistrForSampling) – Distribution object for randomly sampling values.

  • constant_fn (ConstantFn) – Function object for obtaining constant values modified from some user input.

  • operator_weight (float) – Weight given to MCMC move.

constant_fn: ConstantFn | None
generate_value() List[Any]

Generate value.

get_node_stats_str(start: int, end: int, repl_idx: int) str
operator_weight: float
plot_node(axes: Axes, sample_idx: int = 0, repl_idx: int = 0, repl_size: int = 1, branch_attr: str = 'state', draw_reconstructed: bool | None = False) None

Plot node (side-effect) on provided Axes object

Parameters:
  • axes (matplotlib.pyplot.Axes) – Axes object where we are drawing the tree.

  • sample_idx (int) – Which sample to plot. Defaults to 0.

  • repl_idx (int) – Which replicate to plot (one replicated is plotted at a time). Defaults to 0.

  • repl_size (int) – How many scalar random variables to plot at a time. Defaults to 1.

  • branch_attr (str, optional) – If tree, which branch attribute to color branch according to. Defaults to ‘state’.

  • draw_reconstructed (bool, optional) – Flag specifying if to draw reconstructed tree instead of complete tree. Defaults to ‘False’.

populate_operator_weight() None
sampling_dn: DistrForSampling | None
class phylojunction.pgm.pgm.ValueGenerator

Bases: ABC

abstract generate() List[Any]
abstract get_rev_inference_spec_info() List[str]
abstract init_check_vectorize_sample_size(param_list: List[Any] = []) List[List[int | float | str]] | None

Check sample size against number of provided parameter values

This is the function behind the vectorization functionality

n_repl()
n_samples()
phylojunction.pgm.pgm.abstract_attribute(obj: Callable[[Any], R] = None) R
phylojunction.pgm.pgm.extract_vals_as_str_from_node_dag(val_list: List[NodeDAG | str]) List[str]

Get values from DAG node.

If all elements are strings, returns copy of ‘val_list’. When elements are StochasticNodeDAGs, replaces those objects by their values after casting to string (their values must be within a list).

Raises:

VariableMisspec – Is raised if DAG node does not have a value or if it cannot be string-fied.

Returns:

List of values as strings.

Return type:

(str)

phylojunction.pgm.pgm.extract_value_from_dagnodes(dag_node_list: List[NodeDAG]) List[float]

_summary_

Parameters:

dag_node_list (NodeDAG) – List of NodeDAG objects.

Raises:
  • ec.NoPlatingAllowedError – _description_

  • ec.StateDependentParameterMisspec – _description_

Returns:

List of values extracted from the DAG node.

Return type:

(list)

phylojunction.pgm.pgm.plot_blank(axes: Axes) None
phylojunction.pgm.pgm.plot_node_histogram(axes: Axes, values_list: List[float], sample_idx: int | None = None, repl_size: int = 1) None

Module contents