Skip to content

Latest commit

 

History

History
99 lines (79 loc) · 3.1 KB

reference.md

File metadata and controls

99 lines (79 loc) · 3.1 KB

Algorithms reference

The provided algorithms are 3:

They all can be specialized in the way they handle the diversity computation of:

Provide as argument to the algorithms your implementation of the diversity function in order to handle any type of element.

Greedy algorithm

def greedy(elements, k, diversity_element_set=diversity_element_set):
    """
    elements:               input array, the initial set of elements
    k:                      number of selected elements
    diversity_element_set:  diversity function to test the diversity of an element and a set
    return:                 set of most diverse selected elements
    """

Interchange algorithm

def interchange(elements, k, diversity_element_set=diversity_element_set, diversity_set=diversity_set):
    """
    elements:               input array, the initial set of elements
    k:                      number of selected elements
    diversity_element_set:  diversity function to test the diversity between an element and a set
    diversity_set:          diversity function to test the diversity of a set
    return:                 set of most diverse selected elements
    """

Neighborhood algorithm

def neighborhood(elements, ngb_range, diversity_element_element=diversity_element_element):
    """
    elements:                   input array, the initial set of elements
    ngb_range:                  neighborhood range used to define the neighbors of an element
    diversity_element_element:  diversity function to test the diversity between two elements
    return:                     set of most diverse selected elements
    """

Diversity functions reference

Diversity element-element

def diversity_element_element(e1, e2):
    """
    Diversity function to compare an ELEMENT against another ELEMENT
    :param e1: element
    :param e2: element
    :return:   diversity value
    """

Diversity element-set

def diversity_element_set(element, sett):
    """
    Diversity function to compare an ELEMENT against a SET
    :param element: element
    :param sett:    set against which calculate diversity
    :return:        diversity value
    """

Diversity of a set

def diversity_set(sett):
    """
    Diversity function to compute the diversity "amount" of a SET.
    :param sett:    set for which calculate the diversity
    :return:        diversity value
    """