# Algorithm Result#

class raphtory.AlgorithmResult#

Bases: `object`

Methods:

 `get`(key) Returns the value corresponding to the provided key Returns a Dict containing all the vertices (as keys) and their corresponding values (values) or none. Returns a a list of all values Returns a dict with vertex names and values Groups the AlgorithmResult by its values. Returns a tuple of the max result with its key Returns a tuple of the median result with its key Returns a tuple of the min result with its key `sort_by_value`([reverse]) Sorts the AlgorithmResult by its values in ascending or descending order. `sort_by_vertex`([reverse]) Sorts by vertex id in ascending or descending order. `sort_by_vertex_name`([reverse]) The function sort_by_vertex_name sorts a vector of tuples containing a vertex and an optional value by the vertex name in either ascending or descending order. Creates a dataframe from the result 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

Parameters:

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

get_all()#

Returns a Dict containing all the vertices (as keys) and their corresponding values (values) or none.

Returns:

A dict of vertices and their values

get_all_values()#

Returns a a list of all values

get_all_with_names()#

Returns a dict with vertex names and values

Returns:

a dict with vertex names and values

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.

max()#

Returns a tuple of the max result with its key

median()#

Returns a tuple of the median result with its key

min()#

Returns a tuple of the min result with its key

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.

sort_by_vertex(reverse=True)#

Sorts by vertex id in ascending or descending order.

Parameters:

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

Returns:

A sorted list of tuples containing vertex names and values.

sort_by_vertex_name(reverse=True)#

The function sort_by_vertex_name sorts a vector of tuples containing a vertex and an optional value by the vertex name in either ascending or descending order.

Parameters:
• reverse (bool) – A boolean value indicating whether the sorting should be done in reverse order or not.

• true (If reverse is) –

• order (the sorting will be done in descending) –

• in (otherwise it will be done) –

• order. (ascending) –

Returns:

The function sort_by_vertex_name returns a vector of tuples. Each tuple contains a Vertex and value

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.