Skip to content

Commit

Permalink
Merge pull request #87 from LucasAlegre/feature/add_cardinality_metric
Browse files Browse the repository at this point in the history
Adding cardinality metric
  • Loading branch information
ffelten authored Jan 15, 2024
2 parents 030b8a2 + a30e285 commit 6688e0f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/algos/performances.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For single-policy algorithms, the metric used will be the scalarized return of t
### Multi-policy algorithms
For multi-policy algorithms, we propose to rely on various metrics to assess the quality of the **discounted** Pareto Fronts (PF) or Convex Coverage Set (CCS). In general, we want to have a metric that is able to assess the convergence of the PF, a metric that is able to assess the diversity of the PF, and a hybrid metric assessing both. The metrics are implemented in `common/performance_indicators`. We propose to use the following metrics:
* (Diversity) Sparsity: average distance between each consecutive point in the PF. From the PGMORL paper [1]. Keyword: `eval/sparsity`.
* (Diversity) Cardinality: number of points in the PF. Keyword: `eval/cardinality`.
* (Convergence) IGD: a SOTA metric from Multi-Objective Optimization (MOO) literature. It requires a reference PF that we can compute a posteriori. That is, we do a merge of all the PFs found by the method and compute the IGD with respect to this reference PF. Keyword: `eval/igd`.
* (Hybrid) Hypervolume: a SOTA metric from MOO and MORL literature. Keyword: `eval/hypervolume`.

Expand Down
3 changes: 3 additions & 0 deletions morl_baselines/common/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from morl_baselines.common.pareto import filter_pareto_dominated
from morl_baselines.common.performance_indicators import (
cardinality,
expected_utility,
hypervolume,
igd,
Expand Down Expand Up @@ -168,12 +169,14 @@ def log_all_multi_policy_metrics(
hv = hypervolume(hv_ref_point, filtered_front)
sp = sparsity(filtered_front)
eum = expected_utility(filtered_front, weights_set=equally_spaced_weights(reward_dim, n_sample_weights))
card = cardinality(filtered_front)

wandb.log(
{
"eval/hypervolume": hv,
"eval/sparsity": sp,
"eval/eum": eum,
"eval/cardinality": card,
"global_step": global_step,
},
commit=False,
Expand Down
14 changes: 14 additions & 0 deletions morl_baselines/common/performance_indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ def expected_utility(front: List[np.ndarray], weights_set: List[np.ndarray], uti
return np.mean(np.array(maxs), axis=0)


def cardinality(front: List[np.ndarray]) -> float:
"""Cardinality Metric.
Cardinality of the Pareto front approximation.
Args:
front: current pareto front to compute the cardinality on
Returns:
float: cardinality metric
"""
return len(front)


def maximum_utility_loss(
front: List[np.ndarray], reference_set: List[np.ndarray], weights_set: np.ndarray, utility: Callable = np.dot
) -> float:
Expand Down

0 comments on commit 6688e0f

Please sign in to comment.