Source Result#
SourceResult is an abstract class for returning information to the user about a source inference algorithm that has been run.
- class cosasi.source_inference.source_results.SourceResult(source_type, inference_method, scores, G, algorithm_details=True, reverse=True)#
Abstract class outlining response object for the result of a source inference algorithm.
- Parameters
source_type (str) – either “single-source” or “multi-source”
inference_method (str) – name of the source localization algorithm used
scores (dict) – per-item scores for ranking, retrieval, etc.
G (NetworkX Graph) – The original graph the infection process was run on. I is a subgraph of G induced by infected vertices at observation time.
algorithm_details (bool) – if True, includes relevant information about the source inference algorithm used
reverse (bool (default True)') – if True, ranks items from highest score to lowest if False, ranks items from lowest score to highest
Methods
evaluate(true_source)Runs evaluation algorithms and returns a dictionary of results.
evaluate_distance(true_source)Finds the shortest path length between each node in the solution set and the true souce.
evaluate_solution_rank(true_source)Finds the rank of the true source, by the algorithm's scoring protocol.
rank()Rank nodes by score.
topn([n])Returns the top n item indices by rank.
- evaluate(true_source)#
Runs evaluation algorithms and returns a dictionary of results.
- Parameters
true_source (graph index - str, int, etc.) – the actual source node
- evaluate_distance(true_source)#
Finds the shortest path length between each node in the solution set and the true souce.
- Parameters
true_source (tuple) – the actual source set
- evaluate_solution_rank(true_source)#
Finds the rank of the true source, by the algorithm’s scoring protocol.
- Parameters
true_source (graph index - str, int, etc.) – the actual source node
- rank()#
Rank nodes by score.
- Return type
list of item indices
- topn(n=1)#
Returns the top n item indices by rank.
Rank can be highest-first (reverse==True) or lowest-first (reverse==False)
- Parameters
n (int) – number of item indices to return
- Return type
list of item indices