Coverage for lingpy/algorithm/cluster_util.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Various utility functions which are useful for algorithmic operations"""
"""Only allow to have sequences which have consecutive ordering of elements.
Parameters ---------- sequence : list A cluster sequence in which elements should be consecutively ordered, starting from 0, and identical segments in the sequence retrieve the same number.
Returns ------- valid_cluster : bool True, if the cluster is valid, and False if it judged to be invalid.
Examples -------- We define a valid and an invalid cluster sequence:
>>> clrA = [0, 1, 2, 3] >>> clrB = [1, 1, 2, 3] # should be [0, 0, 1, 2] >>> from lingpy.algorithm.utils import valid_cluster >>> valid_cluster(clrA) True >>> valid_cluster(clrB) False
Seealso: -------- generate_all_clusters generate_random_cluster order_cluster mutate_cluster
"""
"""Generate all possible clusters for a number of elements.
Returns ------- clr : iterator An iterator that will yield the next of all possible clusters.
Seealso ------- valid_cluster generate_random_cluster order_cluster mutate_cluster """
"""Generate a random cluster for a number of elements.
Parameters ---------- numbers : int Number of separate entities which should be clustered. bias : str (default=False) When set to "lumper" will tend to create larger groups, when set to "splitter" it will tend to produce smaller groups.
Returns ------- cluster : list A list with consecutive ordering of clusters, starting from zero.
Seealso ------- valid_cluster generate_all_clusters order_cluster mutate_cluster
"""
else:
"""Order a cluster into the form of a valid cluster.
Parameters ---------- clr : list A list with clusters assigned by given each element a specific clusuter ID.
Returns ------- valid_cluster : list A list in which the IDs start from zero and increase consecutively with each new cluster introduced.
Seealso ------- valid_cluster generate_all_clusters generate_random_cluster mutate_cluster """
"""Mutate a cluster.
Parameters ---------- clr : cluster A list with ordered clusters. chance : float (default=0.5) The mutation rate for each element in a cluster. If set to 0.5, this means that in 50% of the cases, an element will be assigned to another cluster or a new cluster.
Returns ------- valid_cluster : list A newly clustered list in consecutive order.
Seealso ------- valid_cluster generate_all_clusters generate_random_cluster order_cluster
""" else:
|