code: def test_crowding_distance() -> None:
      params = ng.p.Tuple(
          ng.p.Scalar(lower=0, upper=2), ng.p.Scalar(lower=0, upper=2)
      )
  
      candidates: tp.List[p.Parameter] = []
      v = sorted([random.uniform(0.01, 0.99) for i in range(4)])
      loss_values = [[0.0, 5.0], [v[0], v[3]], [v[1], v[2]], [1.0, 0.0]]
      for i, v in enumerate(loss_values):
          candidates.append(
              params.spawn_child().set_standardized_data(v)
          )
          candidates[i]._losses = np.array(v)
      crowding_distance = nsga2.CrowdingDistance()
      crowding_distance.compute_distance(candidates)
  
      # For objective 1
      cdist_1 = (loss_values[2][0] - loss_values[0][0]) / abs(
          loss_values[0][0] - loss_values[-1][0]
      )
      cdist_2 = (loss_values[3][0] - loss_values[1][0]) / abs(
          loss_values[0][0] - loss_values[-1][0]
      )
  
      # For objective 2
      cdist_1 += (loss_values[0][1] - loss_values[2][1]) / abs(
          loss_values[0][1] - loss_values[-1][1]
      )
      cdist_2 += (loss_values[1][1] - loss_values[3][1]) / abs(
          loss_values[0][1] - loss_values[-1][1]
      )
  
      assert candidates[0]._meta["crowding_distance"] == float("inf")
      np.testing.assert_almost_equal(
          candidates[1]._meta["crowding_distance"], cdist_1, decimal=3
      )
      np.testing.assert_almost_equal(
          candidates[2]._meta["crowding_distance"], cdist_2, decimal=3
      )
      assert candidates[3]._meta["crowding_distance"] == float("inf")
  
file_path: nevergrad/nevergrad/optimization/multiobjective/test_nsga2.py
imports: import random
  import numpy
  import nevergrad
  import nevergrad.common.typing
  from nevergrad.parametrization import parameter
  from .None import nsga2
label_desc: Use image node_id 1 for calling a global function with example usage: test_crowding_distance() without return types