metrics
This module comptute metrics about interaction graphs and community memberships.
It uses networkx.Graph as graph representation.
- class GroundtruthMetricsComputer(graph=None, graph_partition=None, static_community=None, static_community_graph=None, evolving_community=None, snapshot=None, member=None, member_snapshot=None, flow=None, components=True)
Bases:
MetricsComputerThis class defines the metrics computer for a whole groundtruth.
For every metrics argument if nothing is provided, the handler defaults to using all metrics given to the same name module handler (with _handler at the end of its variable name).
- Parameters:
graph (
Optional[list[Metric]]) – list of metrics for thegraphhandlergraph_partition (
Optional[list[Metric]]) – list of metrics for thegraph_partitionhandlerstatic_community (
Optional[list[Metric]]) – list of metrics for thestatic_communityhandlerstatic_community_graph (
Optional[list[Metric]]) – list of metrics for thestatic_community_graphhandlerevolving_community (
Optional[list[Metric]]) – list of metrics for theevolving_communityhandlersnapshot (
Optional[list[Metric]]) – list of metrics for thesnapshothandlermember (
Optional[list[Metric]]) – list of metrics for thememberhandlermember_snapshot (
Optional[list[Metric]]) – list of metrics for themember_snapshothandlerflow (
Optional[list[Metric]]) – list of metrics for theflowhandlercomponents (
bool) – toggle whethergraphandgraph_partitionmetrics are computed on each graph connected component as well.
It aggregates the following types of metrics as handlers:
- Attr graph:
- Attr graph_partition:
- Attr static_community:
- Attr static_community_graph:
- Attr evolving_community:
- Attr snapshot:
- Attr member:
- Attr member_snapshot:
- Attr flow:
- compute(groundtruth)
Compute all metrics for given groundtruth.
- Parameters:
groundtruth (
Groundtruth) –- Return type:
dict[str,list[dict[str,Any]]]- Returns:
results
- property fields: dict[str, list[str]]
Return fields grouped by handlers.
- Return type:
dict[str,list[str]]- Returns:
- property graph_component: MetricsHandler
Return the metrics handler on graph components.
It’s equal to the
graphhandler ifcomponentsisTrue, an empty metrics handler otherwise.- Return type:
- Returns:
- property graph_component_partition: MetricsHandler
Return the metrics handler on graph components partitions.
It’s equal to the
graph_partitionhandler ifcomponentsisTrue, an empty metrics handler otherwise.- Return type:
- Returns:
- property handlers: dict[str, MetricsHandler]
Return dict of handlers.
- Return type:
dict[str,MetricsHandler]- Returns:
- class Metric(func, fields=None)
Bases:
objectThis class wraps a metric function to standardize it.
- Parameters:
func (
Callable) – raw metric function (must return one value or several as a tuple)fields (
Optional[list[str]]) – fields returned by the func metric (in same order)
- __call__(*args, **kwargs)
Call self as a function.
- Return type:
dict[str,Any]
- classmethod make(*dargs)
Decorate a raw metric function.
This can be used as a parametrized decorator or a simple decorator, by providing the decorator (or not) with a list of fields. If no fields are provided, the function name is assumed as the only field of the metric.
- Parameters:
dargs – function or the list of fields as str objects
- Returns:
- class MetricsHandler(*funcs)
Bases:
objectThis class defines a handlers of metrics.
It calls all stored metrics in
funcand merge their results in one dictionary onMetrics.compute()calls.Metrics can be added using one of several ways:
modify the
funcsattribute (to avoid)by adding the raw metric function using += statement
by decorating the raw metric function with the wanted handler instance
- Parameters:
funcs (
Metric) – metrics
Note
This uses a listener/callback pattern.
- __call__(*dargs)
Decorate a raw metric function and add it as a callback.
This can be used as a parametrized decorator or a simple decorator, by providing the decorator (or not) with a list of fields. If no fields are provided, the function name is assumed as the only field of the metric.
- Parameters:
dargs – function or the list of fields as str objects
- Returns:
- clear()
Remove all metrics from handler.
- Return type:
None
- compute(*args, **kwargs)
Compute all metrics and merge their results.
- Return type:
dict[str,Any]- Returns:
merged metrics results
- copy()
Return a copy of the handler.
- Return type:
- Returns:
- property fields: list[str]
Return merged list of fields.
- Return type:
list[str]- Returns:
- evolving_community_handler = <dyn.benchmark.metrics.MetricsHandler object>
Metric handler containing all evolving community metrics
- flow_handler = <dyn.benchmark.metrics.MetricsHandler object>
Metric handler containing all community flow metrics
- graph_handler = <dyn.benchmark.metrics.MetricsHandler object>
Metric handler containing all graph metrics
- graph_heavy_metrics = [<Metric(func=<function diameter>, fields=['diameter'])>, <Metric(func=<function average_shortest_path_length>, fields=['average_shortest_path_length'])>]
This is a list of heavy graph computation metrics.
Note
they are a part of the graph_handler set of metrics
- graph_partition_handler = <dyn.benchmark.metrics.MetricsHandler object>
Metric handler containing all graph partition metrics
- member_handler = <dyn.benchmark.metrics.MetricsHandler object>
Metric handler containing all member metrics
- member_snapshot_handler = <dyn.benchmark.metrics.MetricsHandler object>
Metric handler containing all member snapshot metrics
- snapshot_handler = <dyn.benchmark.metrics.MetricsHandler object>
Metric handler containing all snapshot metrics
- static_community_graph_handler = <dyn.benchmark.metrics.MetricsHandler object>
Metric handler containing all static community graph metrics
- static_community_handler = <dyn.benchmark.metrics.MetricsHandler object>
Metric handler containing all static community metrics