Behaviour Metrics

behavior_metrics.py

Utility functions for analyzing single-run black box optimization traces.

Each function expects a pandas DataFrame that contains at least:
  • a column “evaluations” integer evaluation index (starting at 1 or 0)

  • a column “raw_y” objective function value (the lower the better)

  • coordinate columns named “x0”, “x1”, … “x{d-1}”

Optimisation direction: these metrics describe the search behaviour of an optimiser on a black-box problem (e.g. an IOH/BBOB trace) and assume that raw_y is minimised: “best”, “improvement” and “best-so-far” all mean the lowest raw_y. They do not use BLADE’s fitness or its direction (Problem.minimisation). For a maximisation trace, pass -raw_y.

The helper get_coordinates(df) extracts the X matrix.

Many metrics also accept optional keyword arguments such as bounds (the search space lower/upper bounds) or radius.

All functions return a scalar float unless stated otherwise.

Author: Niki van Stein (May 2025)

iohblade.behaviour_metrics.average_convergence_rate(df: DataFrame, optimum: float | None = None) → float

Geometric mean of successive error ratios (Chen & He, 2020). ACR < 1 implies convergence; smaller = faster.

iohblade.behaviour_metrics.average_distance_to_best_so_far(df: DataFrame) → float

For each evaluation k>0, compute distance to best point found up to k-1. Average these distances lower = more exploitative.

Returns 0.0 for fewer than two evaluations (no distance is defined).

iohblade.behaviour_metrics.average_nearest_neighbor_distance(df: DataFrame, step=10, history=1000) → float

Average Euclidean distance from each point (except the first) to its nearest previous point – proxy for sequential novelty / exploration.

iohblade.behaviour_metrics.avg_exploration_exploitation_chunked(df: DataFrame, chunk_size: int = 500, bounds: Sequence[Tuple[float, float]] | None = None, rng: Generator | None = None) → Tuple[float, float]
iohblade.behaviour_metrics.closed_form_random_search_diversity(bounds: Sequence[Tuple[float, float]]) → float
iohblade.behaviour_metrics.compute_behavior_metrics(df: DataFrame, *, bounds: Sequence[Tuple[float, float]] | None = None, radius: float | None = None, disp_samples: int = 10000)

Compute all scalar behavior metrics and return them in a dictionary.

raw_y is assumed to be minimised (see the module docstring).

Parameters:
  • df (pd.DataFrame) – One optimisation trace (see the module docstring).

  • bounds (list[tuple[float, float]], optional) – Search space bounds per dimension, used for the dispersion, the exploration percentage and the default radius; default (-5, 5) per dimension.

  • radius (float, optional) – Radius of the intensification ratio; default 10% of the width of the first dimension.

  • disp_samples (int) – Random samples for the dispersion estimate.

Returns:

The metrics by name.

Return type:

dict[str, float]

iohblade.behaviour_metrics.coverage_dispersion(df: DataFrame, bounds: Sequence[Tuple[float, float]] = None, n_samples: int = 10000, rng: Generator | None = None) → float

Approximate dispersion: max distance from a random point in the domain to its nearest evaluated sample. Lower is better (more coverage).

iohblade.behaviour_metrics.estimate_random_search_diversity(bounds: Sequence[Tuple[float, float]], n: int = 500, samples: int = 10000, rng: Generator | None = None) → float
iohblade.behaviour_metrics.get_coordinates(df: DataFrame) → ndarray

Return (N, d) array with decision variables extracted from x-columns.

iohblade.behaviour_metrics.get_objective(df: DataFrame) → ndarray

Return 1‑D array with objective values (raw_y).

iohblade.behaviour_metrics.improvement_statistics(df: DataFrame) → Tuple[float, float]

Returns (avg_improvement, success_rate) where success_rate is the fraction of iterations that improved the best, and avg_improvement is the mean improvement magnitude on improving iterations.

iohblade.behaviour_metrics.intensification_ratio(df: DataFrame, radius: float) → float

Fraction of evaluations lying within a given radius of the final best point. Higher -> stronger intensification / exploitation near the best.

iohblade.behaviour_metrics.last_improvement_fraction(df: DataFrame) → float

Fraction of evaluations since the last improvement (0-1).

Returns 0.0 for fewer than two evaluations (the only evaluation is the best so far, so no evaluation came after the last improvement).

iohblade.behaviour_metrics.longest_no_improvement_streak(df: DataFrame) → int

Return the length of the longest consecutive streak with no improvement.

iohblade.behaviour_metrics.spatial_entropy(df: DataFrame, bandwidth: str | float = 'scott') → float

Differential entropy estimate of the empirical sample distribution. Uses Gaussian KDE from scipy. High entropy -> diverse sampling.