@@ -49,19 +49,19 @@ def __init__(self, error_code):
49
49
super ().__init__ (self .message )
50
50
51
51
52
- def read_datasets (filename , / ):
52
+ def read_datasets (filename : str | os . PathLike | StringIO , / ) -> np . ndarray :
53
53
"""Read an input dataset file, parsing the file and returning a numpy array.
54
54
55
55
Parameters
56
56
----------
57
- filename : file, str, pathlib.Path
58
- Filename of the dataset file. Each row of the table appears as one line of the file. Datasets are separated by an empty line.
59
- If it does not contain an absolute path, the file name is relative to the current working directory.
60
- If the filename has extension `'.xz'`, it is decompressed to a temporary file before reading it.
57
+ filename:
58
+ Filename of the dataset file or :class:`~io.StringIO` directly containing the file contents.
59
+ If it does not contain an absolute path, the filename is relative to the current working directory.
60
+ If the filename has extension ``.xz``, it is decompressed to a temporary file before reading it.
61
+ Each line of the file corresponds to one point of one dataset. Different datasets are separated by an empty line.
61
62
62
63
Returns
63
64
-------
64
- numpy.ndarray
65
65
An array containing a representation of the data in the file.
66
66
The first :math:`n-1` columns contain the numerical data for each of the objectives.
67
67
The last column contains an identifier for which set the data is relevant to.
@@ -170,6 +170,10 @@ def igd(data, /, ref, *, maximise=False) -> float:
170
170
171
171
.. seealso:: For details about parameters, return value and examples, see :func:`igd_plus`. For details of the calculation, see :ref:`igd_hausdorf`.
172
172
173
+ Returns
174
+ -------
175
+ A single numerical value
176
+
173
177
"""
174
178
data_p , nobj , npoints , ref_p , ref_size , maximise_p = _unary_refset_common (
175
179
data , ref , maximise
@@ -232,6 +236,10 @@ def avg_hausdorff_dist(data, /, ref, *, maximise=False, p: float = 1) -> float:
232
236
p :
233
237
Hausdorff distance parameter. Must be larger than 0.
234
238
239
+ Returns
240
+ -------
241
+ A single numerical value
242
+
235
243
"""
236
244
if p <= 0 :
237
245
raise ValueError ("'p' must be larger than zero" )
@@ -245,7 +253,9 @@ def avg_hausdorff_dist(data, /, ref, *, maximise=False, p: float = 1) -> float:
245
253
)
246
254
247
255
248
- def epsilon_additive (data , / , ref , * , maximise = False ) -> float :
256
+ def epsilon_additive (
257
+ data : ArrayLike , / , ref : ArrayLike , * , maximise : bool | list [bool ] = False
258
+ ) -> float :
249
259
"""Additive epsilon metric.
250
260
251
261
`data` and `reference` must all be larger than 0 for :func:`epsilon_mult`.
@@ -254,13 +264,13 @@ def epsilon_additive(data, /, ref, *, maximise=False) -> float:
254
264
255
265
Parameters
256
266
----------
257
- data : numpy.ndarray
267
+ data :
258
268
Numpy array of numerical values, where each row gives the coordinates of a point in objective space.
259
269
If the array is created from the :func:`read_datasets` function, remove the last (set) column
260
- ref : numpy.ndarray or list
270
+ ref :
261
271
Reference point set as a numpy array or list. Must have same number of columns as a single point in the \
262
272
dataset
263
- maximise : bool or list of bool
273
+ maximise :
264
274
Whether the objectives must be maximised instead of minimised. \
265
275
Either a single boolean value that applies to all objectives or a list of booleans, with one value per objective. \
266
276
Also accepts a 1d numpy array with value 0/1 for each objective
@@ -291,7 +301,11 @@ def epsilon_additive(data, /, ref, *, maximise=False) -> float:
291
301
def epsilon_mult (data , / , ref , * , maximise = False ) -> float :
292
302
"""Multiplicative epsilon metric.
293
303
294
- .. seealso:: For details about parameters, return value and examples, see :func:`epsilon_add`. For details of the calculation, see :ref:`epsilon_metric`.
304
+ .. seealso:: For details about parameters, return value and examples, see :func:`epsilon_additive`. For details of the calculation, see :ref:`epsilon_metric`.
305
+
306
+ Returns
307
+ -------
308
+ A single numerical value
295
309
296
310
"""
297
311
data_p , nobj , npoints , ref_p , ref_size , maximise_p = _unary_refset_common (
@@ -301,7 +315,7 @@ def epsilon_mult(data, /, ref, *, maximise=False) -> float:
301
315
302
316
303
317
# FIXME: TODO maximise option
304
- def hypervolume (data : ArrayLike , / , ref ) -> float :
318
+ def hypervolume (data : ArrayLike , / , ref : ArrayLike ) -> float :
305
319
r"""Hypervolume indicator.
306
320
307
321
Compute the hypervolume metric with respect to a given reference point
@@ -318,7 +332,7 @@ def hypervolume(data: ArrayLike, /, ref) -> float:
318
332
data :
319
333
Numpy array of numerical values, where each row gives the coordinates of a point.
320
334
If the array is created from the :func:`read_datasets` function, remove the last column.
321
- ref : ArrayLike or list
335
+ ref :
322
336
Reference point as a 1D vector. Must be same length as a single point in the `data`.
323
337
324
338
Returns
@@ -371,19 +385,21 @@ def hypervolume(data: ArrayLike, /, ref) -> float:
371
385
return hv
372
386
373
387
374
- def is_nondominated (data , maximise = False , keep_weakly : bool = False ):
388
+ def is_nondominated (
389
+ data : ArrayLike , / , * , maximise = False , keep_weakly : bool = False
390
+ ):
375
391
"""Identify dominated points according to Pareto optimality.
376
392
377
393
Parameters
378
394
----------
379
- data : numpy array
380
- Numpy array of numerical values, where each row gives the coordinates of a point in objective space.
395
+ data :
396
+ Array of numerical values, where each row gives the coordinates of a point in objective space.
381
397
If the array is created from the :func:`read_datasets()` function, remove the last column.
382
398
maximise : single bool, or list of booleans
383
399
Whether the objectives must be maximised instead of minimised.
384
400
Either a single boolean value that applies to all objectives or a list of boolean values, with one value per objective.
385
401
Also accepts a 1D numpy array with value 0/1 for each objective.
386
- keep_weakly: bool
402
+ keep_weakly:
387
403
If ``False``, return ``False`` for any duplicates of nondominated points.
388
404
389
405
Returns
@@ -426,16 +442,16 @@ def is_nondominated(data, maximise=False, keep_weakly: bool = False):
426
442
return np .frombuffer (nondom , dtype = bool )
427
443
428
444
429
- def filter_dominated (data , / , * , maximise = False , keep_weakly = False ):
445
+ def filter_dominated (data , / , * , maximise = False , keep_weakly : bool = False ):
430
446
"""Remove dominated points according to Pareto optimality.
431
447
432
- See: :func:`is_nondominated` for details
448
+ See: :func:`is_nondominated` for details.
433
449
"""
434
450
return data [is_nondominated (data , maximise , keep_weakly ), :]
435
451
436
452
437
453
def filter_dominated_within_sets (
438
- data , / , * , maximise = False , keep_weakly = False
454
+ data , / , * , maximise = False , keep_weakly : bool = False
439
455
):
440
456
"""Given a dataset with multiple sets (last column gives the set index), filter dominated points within each set.
441
457
@@ -452,7 +468,7 @@ def filter_dominated_within_sets(
452
468
Whether the objectives must be maximised instead of minimised. \
453
469
Either a single boolean value that applies to all objectives or a list of booleans, with one value per objective. \
454
470
Also accepts a 1D numpy array with values 0 or 1 for each objective
455
- keep_weakly: bool
471
+ keep_weakly:
456
472
If False, return False for any duplicates of nondominated points.
457
473
458
474
Returns
@@ -504,19 +520,21 @@ def filter_dominated_within_sets(
504
520
return data [is_nondom , :]
505
521
506
522
507
- def pareto_rank (data , / , * , maximise = False ):
508
- r"""Ranks points according to Pareto-optimality, which is also called nondominated sorting.
523
+ def pareto_rank (data : ArrayLike , / , * , maximise = False ):
524
+ r"""Rank points according to Pareto-optimality ( nondominated sorting) .
509
525
510
- Ranks points according to Pareto-optimality, which is also called nondominated sorting :footcite:p:`Deb02nsga2`.
526
+ The function :func:`pareto_rank` is meant to be used like
527
+ :func:`numpy.argsort`, but it assigns indexes according to Pareto
528
+ dominance. Duplicated points are kept on the same front. The resulting
529
+ ranking can be used to partition points into different lists or arrays,
530
+ each of them being mutually nondominated :footcite:p:`Deb02nsga2`.
511
531
512
- `pareto_rank` is meant to be used like :func:`numpy.argsort`, but it assigns
513
- indexes according to Pareto dominance. Duplicated points are kept on the
514
- same front. With 2 columns, the code uses the :math:`O(n \log n)` algorithm
515
- by :footcite:t:`Jen03`.
532
+ With 2 columns, the code uses the :math:`O(n \log n)` algorithm by
533
+ :footcite:t:`Jen03`.
516
534
517
535
Parameters
518
536
----------
519
- data : numpy array
537
+ data :
520
538
Numpy array of numerical values, where each row gives the coordinates of a point in objective space.
521
539
If the array is created from the :func:`read_datasets()` function, remove the last column.
522
540
maximise : single bool, or list of booleans
0 commit comments