Experiments¶
Running the experiment¶
This is an example of an experimental study based on solving three problems of the ZDT family with three different algorithms: NSGA-II, GDE3 and SMPSO.
The hypervolume, generational distance and epsilon indicators are used for performance assessment.
from jmetal.algorithm.multiobjective.gde3 import GDE3
from jmetal.algorithm.multiobjective.nsgaii import NSGAII
from jmetal.algorithm.multiobjective.smpso import SMPSO
from jmetal.core.quality_indicator import *
from jmetal.lab.experiment import Experiment, Job, generate_summary_from_experiment
from jmetal.operator import PolynomialMutation, SBXCrossover
from jmetal.problem import ZDT1, ZDT2, ZDT3
from jmetal.util.archive import CrowdingDistanceArchive
from jmetal.util.termination_criterion import StoppingByEvaluations
def configure_experiment(problems: dict, n_run: int):
jobs = []
max_evaluations = 25000
for run in range(n_run):
for problem_tag, problem in problems.items():
jobs.append(
Job(
algorithm=NSGAII(
problem=problem,
population_size=100,
offspring_population_size=100,
mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables(),
distribution_index=20),
crossover=SBXCrossover(probability=1.0, distribution_index=20),
termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
),
algorithm_tag='NSGAII',
problem_tag=problem_tag,
run=run,
)
)
jobs.append(
Job(
algorithm=GDE3(
problem=problem,
population_size=100,
cr=0.5,
f=0.5,
termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
),
algorithm_tag='GDE3',
problem_tag=problem_tag,
run=run,
)
)
jobs.append(
Job(
algorithm=SMPSO(
problem=problem,
swarm_size=100,
mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables(),
distribution_index=20),
leaders=CrowdingDistanceArchive(100),
termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
),
algorithm_tag='SMPSO',
problem_tag=problem_tag,
run=run,
)
)
return jobs
if __name__ == '__main__':
# Configure the experiments
jobs = configure_experiment(problems={'ZDT1': ZDT1(), 'ZDT2': ZDT2(), 'ZDT3': ZDT3()}, n_run=31)
# Run the study
output_directory = 'data'
experiment = Experiment(output_dir=output_directory, jobs=jobs)
experiment.run()
Summary file¶
The results of this experiment can be summarized to a CSV file as follows:
if __name__ == '__main__':
# experiment = ...
# Generate summary file
generate_summary_from_experiment(
input_dir=output_directory,
reference_fronts='resources/reference_fronts',
quality_indicators=[GenerationalDistance(), EpsilonIndicator(), HyperVolume([1.0, 1.0])]
)
This file contains all the information of the quality indicator values, for each configuration and run. The summary file is the input of all the statistical tests, so that they can be applied to any valid file having the proper format.
$ head QualityIndicatorSummary.csv
Algorithm,Problem,ExecutionId,IndicatorName,IndicatorValue
NSGAII,ZDT1,0,EP,0.015705992620067832
NSGAII,ZDT1,1,EP,0.012832504015918067
...
API¶
experiment
¶
logger = get_logger(__name__)
module-attribute
¶
.. module:: laboratory :platform: Unix, Windows :synopsis: Run experiments. WIP!
.. moduleauthor:: Antonio Benítez-Hidalgo antonio.b@uma.es
Experiment(output_dir, jobs, m_workers=6)
¶
Run an experiment to execute a list of jobs.
:param output_dir: Base directory where each job will save its results.
:param jobs: List of Jobs (from mod:
jmetal.util.laboratory)) to be executed.
:param m_workers: Maximum number of workers to execute the Jobs in parallel.
Source code in src/jmetal/lab/experiment.py
generate_summary_from_experiment(input_dir, quality_indicators, reference_fronts='')
¶
Compute a list of quality indicators. The input data directory must met the following structure (this is generated automatically by the Experiment class):
-
-
algorithm_a
-
problem_a
-
FUN.0.tsv
- FUN.1.tsv
- VAR.0.tsv
- VAR.1.tsv
- ...
-
:param input_dir: Directory where all the input data is found (function values and variables). :param reference_fronts: Directory where reference fronts are found. :param quality_indicators: List of quality indicators to compute. :return: None.
Source code in src/jmetal/lab/experiment.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
generate_median_and_wilcoxon_latex_tables(filename, output_dir='latex/meansAndWilcoxon')
¶
Generate Latex tables including medians and IQRs. Additionally, the last algorithm is considered as the reference algorithm, and the cells include a symbol indicating whether the differences with the reference algorithm are significant or not according to the Wilcoxon rank sum test.
:param filename: Input filename (summary). :param output_dir: Output path.
Source code in src/jmetal/lab/experiment.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | |
generate_kolmogorov_smirnov_latex_tables(filename, output_dir='latex/KolmogorovSmirnov')
¶
Generate Latex tables with the results of the Kolmogorov-Smirnov test. The last algorithm is considered as the reference algorithm, and the cells include a symbol with the p-value < 0.05.
:param filename: Input filename (summary). :param output_dir: Output path.
Source code in src/jmetal/lab/experiment.py
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |