Mixture
from BEAM import Mixture
group = Mixture([donor_a, donor_b, donor_c]) # equal weightsgroup = Mixture([donor_a, donor_b], weights=[0.7, 0.3])The distribution : pick member with probability , then a
sequence from that member. This is different from pooling counts with merged, which can join
stretches of sequence from different members into sequences no member writes; see
Merging counts or mixing models.
All members must share alphabet, order and maximum length (otherwise IncompatibleMembers).
Weights must be non-negative and sum to 1; they are refused, not rescaled, when they do not.
Diversity
Section titled “Diversity”| Method | Returns | How it is computed |
|---|---|---|
hill_number(q), hill_numbers(orders) | Effective number of sequences of the mixture at order q. | Directly, over every sequence, for q = 0 and every integer q ≥ 2. Other orders raise UnsupportedOrder; at q = 1 use entropy_bounds(). |
alpha_diversity(q) | The diversity of a typical member: the members’ Hill numbers averaged by the power mean of order (harmonic at ). | Directly. |
beta_diversity(q) | .beta, .gamma, .alpha: how many effectively distinct members the group has, from 1 to the number of members. | Directly, at the same orders. At q = 1, .lower and .upper give guaranteed bounds and .beta is None; samples= adds a sampled .estimate. |
entropy_bounds() | Guaranteed lower and upper bounds on the Shannon entropy (), in nats: the weighted mean of the members’ entropies, and that plus the entropy of the weights. | Directly. |
entropy_estimate(n=10000, seed=None) | A sampled estimate of the Shannon entropy, with its standard error. | By sampling, and labelled as such. |
support_size() | .value: the number of distinct sequences at least one member can produce. support_size(exact=False) returns only its bounds .lower and .upper, at no cost. | Directly, for up to 64 members. |
Why is treated differently: see Computed, not simulated.
The cost grows with the number of members : every quantity at an integer order takes
one sweep over the sequences for every combination of members, at . Time
one log_inner_product(0, 1) on your own models before computing a large gram_matrix(); with
many large members, holding the models in memory runs out before the sweeps do.
Scoring and drawing
Section titled “Scoring and drawing”| Method | Returns |
|---|---|
pseq(seq_or_list, log=False), log_pseq(seq) | Probability of a sequence (or of each in a list) under the mixture. |
sample(n, *, seed=None) | n sequences drawn from the mixture. |
member_weights(length) | The members’ weights among sequences of one length, . |
Overlap between members
Section titled “Overlap between members”| Method | Returns |
|---|---|
gram_matrix(), log_gram_matrix() | : the chance that one draw from member and one from member are the same sequence. |
bhattacharyya_coefficient(i, j), bhattacharyya_matrix() | , from 0 (no shared sequence) to 1 (identical members). |
hellinger_distance(i, j) | , a distance between two members. |