metrics

Spatial and temporal graph metric computations.

class fstg_toolkit.metrics.MetricsRegistry(_MetricsRegistry__registry: dict[str, MetricFunction] = <factory>)[source]

Bases: object

A named registry that maps metric names to their computation functions.

Metrics are stored in an internal dictionary and can be added, removed, and iterated over. The registry is frozen at the dataclass level, but the internal dict is mutable to allow dynamic registration of metrics.

__iter__()[source]

Iterate over (name, func) pairs in the registry.

add(name: str, func: MetricFunction) None[source]

Register a metric function under the given name.

Parameters:
  • name (str) – The display name of the metric.

  • func (MetricFunction) – A callable that accepts a SpatioTemporalGraph and returns a metric value.

remove(name: str) None[source]

Unregister the metric with the given name.

Parameters:

name (str) – The name of the metric to remove.

Raises:

KeyError – If no metric with that name exists in the registry.

fstg_toolkit.metrics.assortativity(graph: SpatioTemporalGraph) float[source]
fstg_toolkit.metrics.average_degree(graph: SpatioTemporalGraph) float[source]
fstg_toolkit.metrics.burstiness(graph: SpatioTemporalGraph) float[source]
fstg_toolkit.metrics.calculate_spatial_metrics(graph: SpatioTemporalGraph) list[MetricRecord][source]
fstg_toolkit.metrics.calculate_temporal_metrics(graph: SpatioTemporalGraph) list[MetricRecord][source]
fstg_toolkit.metrics.clustering(graph: SpatioTemporalGraph) float[source]
fstg_toolkit.metrics.density(graph: SpatioTemporalGraph) float[source]
fstg_toolkit.metrics.gather_metrics(dataset: ~fstg_toolkit.io.GraphsDataset, selection: ~typing.Sequence[tuple[str, ...]], calculator: MetricsCalculator, callback: ~typing.Callable[[tuple[str, ...]], None] | None = <function <lambda>>, max_cpus: int = 1) DataFrame[source]
fstg_toolkit.metrics.get_metrics_registry(name: str) MetricsRegistry[source]

Return (or create) the named MetricsRegistry.

Parameters:

name (str) – The registry name, e.g. 'local' or 'global'.

Returns:

The registry associated with name. A new empty registry is created the first time a name is requested.

Return type:

MetricsRegistry

fstg_toolkit.metrics.global_efficiency(graph: SpatioTemporalGraph) float[source]
fstg_toolkit.metrics.mean_areas(graph: SpatioTemporalGraph) dict[str, float][source]
fstg_toolkit.metrics.memory(graph: SpatioTemporalGraph) float[source]
fstg_toolkit.metrics.metric(registry_name: str, name: str)[source]
fstg_toolkit.metrics.metrics_index_columns(index_columns: list[str] | None)[source]

Decorator that attaches extra index column names to a metrics calculator.

The annotated column names are later used by gather_metrics() to promote those columns from the records DataFrame into multi-level index levels.

Parameters:

index_columns (list[str] or None) – Names of the columns to promote to index levels.

Returns:

The same function with an index_columns attribute attached.

Return type:

Callable

fstg_toolkit.metrics.modularity(graph: SpatioTemporalGraph) float[source]
fstg_toolkit.metrics.reorg_rate(graph: SpatioTemporalGraph) float[source]
fstg_toolkit.metrics.transitions_distribution(graph: SpatioTemporalGraph) dict[str, int][source]