mutators module#
Classes for defining mutation effect generators \(\mathcal{p}(x\mid x')\), with
arbitrary bdms.Tree attribute dependence. An abstract base class and
several concrete child classes are included.
These classes are used to define mutation effects for simulations with
bdms.Tree.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.Tree(state="a")
>>> mutator.mutate(node, seed=0)
>>> node.state
'c'
- class bdms.mutators.Mutator(attr='state', *args, **kwargs)#
Bases:
ABCAbstract base class for mutators that mutate a specified
bdms.Treenode attribute.- Parameters:
attr (
str) – Node attribute to mutate.
- abstractmethod mutate(node, seed=None)#
Mutate a
bdms.Treeobject in place.- Parameters:
seed (
int|Generator|None) – A seed to initialize the random number generation. IfNone, 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:
- abstractmethod prob(attr1, attr2, log=False)#
Probability of mutating from
attr1toattr2.
- class bdms.mutators.GaussianMutator(shift=0.0, scale=1.0, attr='state')#
Bases:
MutatorGaussian mutation effects on a specified attribute.
- Parameters:
- mutate(node, seed=None)#
Mutate a
bdms.Treeobject in place.- Parameters:
seed (
int|Generator|None) – A seed to initialize the random number generation. IfNone, 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:
- class bdms.mutators.KdeMutator(data, attr='state', bw_method=None, weights=None)#
Bases:
MutatorGaussian kernel density estimator (KDE) for mutation effect on a specified attribute.
- Parameters:
- mutate(node, seed=None)#
Mutate a
bdms.Treeobject in place.- Parameters:
seed (
int|Generator|None) – A seed to initialize the random number generation. IfNone, 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:
- class bdms.mutators.DiscreteMutator(state_space, transition_matrix, attr='state')#
Bases:
MutatorMutations on a discrete space with a stochastic matrix.
- Parameters:
- state_space_idxs: dict[Any, int]#
Mapping from state values to their indices in the transition matrix.
- mutate(node, seed=None)#
Mutate a
bdms.Treeobject in place.- Parameters:
seed (
int|Generator|None) – A seed to initialize the random number generation. IfNone, 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: