Algorithm Result#
- class raphtory.AlgorithmResult#
Bases:
object
Methods:
get
(key)Returns the value corresponding to the provided key
get_all
()Returns a Dict containing all the nodes (as keys) and their corresponding values (values) or none.
Returns a a list of all values
Returns a dict with node names and values
group_by
()Groups the AlgorithmResult by its values.
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_node
([reverse])Sorts by node id in ascending or descending order.
sort_by_node_name
([reverse])The function sort_by_node_name sorts a vector of tuples containing a node and an optional value by the node name in either 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
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 nodes (as keys) and their corresponding values (values) or none.
- Returns:
A dict of nodes and their values
- get_all_values()#
Returns a a list of all values
- get_all_with_names()#
Returns a dict with node names and values
- Returns:
a dict with node 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_node(reverse=True)#
Sorts by node 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 node names and values.
- sort_by_node_name(reverse=True)#
The function sort_by_node_name sorts a vector of tuples containing a node and an optional value by the node 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_node_name returns a vector of tuples. Each tuple contains a Node and value
- 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.