Exemple #1
0
def diversity(activity):
    transactions = transpose(activity)
    unique_transactions = unique(transactions)
    buckets = list(map(lambda t: transactions.count(t), unique_transactions))
    numerator = reduce(lambda s, n: s + n * (n - 1), buckets, 0)
    num_of_transactions = len(transactions)
    denominator = num_of_transactions * (num_of_transactions - 1)
    try:
        return 1 - numerator / denominator
    except ZeroDivisionError:
        return 0
Exemple #2
0
def _flatten_spectra(spectra):
    components = spectra[0]
    transactions = spectra[1:]
    unique_components = set(components[1:])
    for component in unique_components:
        positions = _indexes(component, components)
        for j, transaction in enumerate(transactions):
            if sum([transaction[i] for i in positions]) > 0:
                for p in positions:
                    transactions[j][p] = 1
    data = [components] + transactions
    component_columns = transpose(data)
    return transpose(unique(component_columns))
Exemple #3
0
def _get_classes(spectra):
    components = _unique_components(spectra)
    classes = unique(list(map(_get_class, components)))
    return reduce(_assign_class, components, _parent_dict(classes))
Exemple #4
0
def _get_packages(spectra):
    components = _unique_components(spectra)
    packages = list(map(_get_package, components))
    packages = unique(packages)
    return reduce(_assign_package, components, _parent_dict(packages))
Exemple #5
0
def uniqueness(activity):
    g = unique(activity)
    try:
        return len(g) / len(activity)
    except ZeroDivisionError:
        return 0