Algorithm Result#

class raphtory.AlgorithmResult#

Bases: object

Methods:

get(key)

Returns the value corresponding to the provided key in the result hashmap.

get_all()

Returns a reference to the entire result hashmap.

group_by()

Groups the AlgorithmResult by its values.

sort_by_key([reverse])

Sorts the AlgorithmResult by its keys in ascending or descending order.

sort_by_value([reverse])

Sorts the AlgorithmResult by its values in ascending or descending order.

to_df()

Creates a dataframe from the result

to_string()

Returns a formatted string representation of the algorithm.

top_k(k[, percentage, reverse])

Retrieves the top-k elements from the AlgorithmResult based on its values.

get(key)#

Returns the value corresponding to the provided key in the result hashmap.

Parameters:

key – The key of type H for which the value is to be retrieved.

get_all()#

Returns a reference to the entire result hashmap.

group_by()#

Groups the AlgorithmResult by its values.

Returns:

A HashMap where keys are unique values from the AlgorithmResult and values are vectors containing keys of type H that share the same value.

sort_by_key(reverse=True)#

Sorts the AlgorithmResult by its keys in ascending or descending order.

Parameters:

reverse (bool) – If true, sorts the result in descending order; otherwise, sorts in ascending order.

Returns:

A sorted vector of tuples containing keys of type H and values of type Y.

sort_by_value(reverse=True)#

Sorts the AlgorithmResult by its values in ascending or descending order.

Parameters:

reverse (bool) – If true, sorts the result in descending order; otherwise, sorts in ascending order.

Returns:

A sorted vector of tuples containing keys of type H and values of type Y.

to_df()#

Creates a dataframe from the result

Returns:

A pandas.DataFrame containing the result

to_string()#

Returns a formatted string representation of the algorithm.

top_k(k, percentage=False, reverse=True)#

Retrieves the top-k elements from the AlgorithmResult based on its values.

Parameters:
  • k (int) – The number of elements to retrieve.

  • percentage (bool) – If true, the k parameter is treated as a percentage of total elements.

  • reverse (bool) – If true, retrieves the elements in descending order; otherwise, in ascending order.

Returns:

An Option containing a vector of tuples with keys of type H and values of type Y. If percentage is true, the returned vector contains the top k percentage of elements. If percentage is false, the returned vector contains the top k elements. Returns None if the result is empty or if k is 0.