bdms.mutators
#
Mutation effects generators.
Abstract base class for defining generic mutation effect generators (i.e.
\(\mathcal{p}(x\mid x')\)), with arbitrary ete3.TreeNode
attribute
dependence. Some concrete child classes are included.
These classes are used to define mutation effects for simulations with
bdms.TreeNode.evolve
.
Example
>>> import bdms
Define a discrete mutation model.
>>> mutator = bdms.mutators.DiscreteMutator(
... state_space=["a", "b", "c"],
... transition_matrix=[[0.0, 0.5, 0.5],
... [0.5, 0.0, 0.5],
... [0.5, 0.5, 0.0]],
... )
Mutate a node.
>>> node = bdms.TreeNode(state="a")
>>> mutator.mutate(node, seed=0)
>>> node.state
'c'
Module Contents#
Classes#
Abstract base class for mutators that mutate a specified |
|
Gaussian mutation effects on a specified attribute. |
|
Gaussian kernel density estimator (KDE) for mutation effect on a specified |
|
Mutations on a discrete space with a stochastic matrix. |
- class bdms.mutators.Mutator(attr='state', *args, **kwargs)#
Bases:
abc.ABC
Abstract base class for mutators that mutate a specified
ete3.TreeNode
node attribute.- Parameters:
attr (str) – Node attribute to mutate.
args (Any) –
kwargs (Any) –
- abstract mutate(node, seed=None)#
Mutate a
bdms.TreeNode
object in place.- Parameters:
node (TreeNode) – A
bdms.TreeNode
to mutate.seed (int | Generator | None) – A seed to initialize the random number generation. If
None
, then fresh, unpredictable entropy will be pulled from the OS. If anint
, then it will be used to derive the initial state. If anumpy.random.Generator
, then it will be used directly.
- Return type:
None
- abstract prob(attr1, attr2, log=False)#
Probability of mutating from
attr1
toattr2
.
- class bdms.mutators.GaussianMutator(shift=0.0, scale=1.0, attr='state')#
Bases:
Mutator
Gaussian mutation effects on a specified attribute.
- Parameters:
- mutate(node, seed=None)#
Mutate a
bdms.TreeNode
object in place.- Parameters:
node (TreeNode) – A
bdms.TreeNode
to mutate.seed (int | Generator | None) – A seed to initialize the random number generation. If
None
, then fresh, unpredictable entropy will be pulled from the OS. If anint
, then it will be used to derive the initial state. If anumpy.random.Generator
, then it will be used directly.
- Return type:
None
- class bdms.mutators.KdeMutator(data, attr='state', bw_method=None, weights=None)#
Bases:
Mutator
Gaussian kernel density estimator (KDE) for mutation effect on a specified attribute.
- Parameters:
data (numpy.typing.NDArray[numpy.float64]) – Data to fit the KDE to.
attr (str) – Node attribute to mutate.
bw_method (str | float | Callable[Ellipsis, float] | None) – KDE bandwidth (see
scipy.stats.gaussian_kde
).weights (numpy.typing.NDArray[numpy.float64] | None) – Weights of data points (see
scipy.stats.gaussian_kde
).
- mutate(node, seed=None)#
Mutate a
bdms.TreeNode
object in place.- Parameters:
node (TreeNode) – A
bdms.TreeNode
to mutate.seed (int | Generator | None) – A seed to initialize the random number generation. If
None
, then fresh, unpredictable entropy will be pulled from the OS. If anint
, then it will be used to derive the initial state. If anumpy.random.Generator
, then it will be used directly.
- Return type:
None
- class bdms.mutators.DiscreteMutator(state_space, transition_matrix, attr='state')#
Bases:
Mutator
Mutations on a discrete space with a stochastic matrix.
- Parameters:
- mutate(node, seed=None)#
Mutate a
bdms.TreeNode
object in place.- Parameters:
node (TreeNode) – A
bdms.TreeNode
to mutate.seed (int | Generator | None) – A seed to initialize the random number generation. If
None
, then fresh, unpredictable entropy will be pulled from the OS. If anint
, then it will be used to derive the initial state. If anumpy.random.Generator
, then it will be used directly.
- Return type:
None