The provided algorithms are 3:
They all can be specialized in the way they handle the diversity computation of:
- element-element
- element-set
- "diversity amount" of a set of elements
Provide as argument to the algorithms your implementation of the diversity function in order to handle any type of element.
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
"""
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
"""
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
"""
def diversity_element_element(e1, e2):
"""
Diversity function to compare an ELEMENT against another ELEMENT
:param e1: element
:param e2: element
:return: diversity value
"""
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
"""
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
"""