Triplet Profiles#

Working with Triplet Profiles#

The phylozoo.core.triplet module provides the TripletProfile class, which represents a probability distribution over the possible triplet topologies for a specific three-taxon set. The weights in a triplet profile always sum to 1.0 (within a small tolerance): if no weights are given, each triplet gets equal weight \(1/k\) (where \(k\) is the number of triplets); if weights are given, they must sum to 1.0. Triplet profiles are essential for modeling uncertainty or mixed phylogenetic signals in triplet-based analyses.

Creating Triplet Profiles#

Triplet profiles can be created by specifying triplets and their corresponding weights:

from phylozoo.core.triplet import TripletProfile, Triplet
from phylozoo.core.split import Split

# Create triplets
t1 = Triplet(Split({"A"}, {"B", "C"}))
t2 = Triplet(Split({"B"}, {"A", "C"}))

# Create a profile using a dictionary (weights must sum to 1.0)
profile = TripletProfile({t1: 0.7, t2: 0.3})

# Create a profile from a list of (triplet, weight) tuples (weights must sum to 1.0)
full_profile = TripletProfile([
    (t1, 0.5),
    (t2, 0.3),
    (Triplet(Split({"C"}, {"A", "B"})), 0.2)
])

# Create a profile from a list of triplets (equal weight 1/k each, so total 1.0)
equal_profile = TripletProfile([t1, t2])  # Each gets weight 0.5

All triplets in a profile must have the same three taxa.

Accessing Profile Properties#

Basic properties

Triplet profiles provide access to their taxa, triplet weights, and induced split:

# Access taxa
taxa = profile.taxa    # frozenset({"A", "B", "C"})

# Get mapping of all triplets to their weights
triplets_map = profile.triplets  # Mapping[Triplet, float]

# Get weight for a specific triplet
weight = profile.get_weight(some_triplet)  # Returns weight or 0.0

# Get split if profile has a single triplet
split = profile.split  # Split object or None

Resolution status

The is_resolved() method checks whether the profile is resolved, meaning all triplets in the profile are resolved:

# Check if profile is resolved (all triplets resolved)
resolved = profile.is_resolved()  # True if all triplets are resolved

Triviality

The is_trivial() method checks whether the profile contains only one triplet:

# Check if profile is trivial (only one triplet)
trivial = profile.is_trivial()  # True if profile has only one triplet

See Also#