Skip to content

Commit

Permalink
Use of linters for catching errors and formatters to fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
benhid committed Sep 7, 2020
1 parent 22e53f8 commit e246758
Show file tree
Hide file tree
Showing 161 changed files with 3,849 additions and 3,241 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,5 @@ dask-worker-space
# osx
.DS_Store

# R
.RData
.Rhistory
# Github codespaces
pythonenv3.8
35 changes: 13 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
# Minimal makefile for Sphinx documentation
#
install:
@python setup.py install

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = jMetalPy
SOURCEDIR = docs/source
BUILDDIR = build
clean:
@rm -rf build dist .eggs *.egg-info
@find . -type d -name '.mypy_cache' -exec rm -rf {} +
@find . -type d -name '__pycache__' -exec rm -rf {} +

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
black: clean
@isort --profile black jmetal/ examples/
@black jmetal/

.PHONY: help Makefile
lint:
@mypy jmetal/ --show-error-codes

# "make github" option to build gh-pages
github:
@make html
@cp -a $(BUILDDIR)/html/. docs
@rm -r $(BUILDDIR)

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
tests:
@python -m unittest discover --quiet
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[![PyPI version](https://img.shields.io/pypi/v/jMetalPy.svg?style=flat-square)]()
[![PyPI Python version](https://img.shields.io/pypi/pyversions/jMetalPy.svg?style=flat-square)]()
[![DOI](https://img.shields.io/badge/DOI-10.1016%2Fj.swevo.2019.100598-blue?style=flat-square)](https://doi.org/10.1016/j.swevo.2019.100598)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)

A paper introducing jMetalPy is available at: https://doi.org/10.1016/j.swevo.2019.100598

Expand Down Expand Up @@ -44,7 +45,7 @@ pip install "jmetalpy[core]"
Other supported commands are listed next:

```console
pip install "jmetalpy[docs]" # Install requirements for building docs
pip install "jmetalpy[dev]" # Install requirements for development
pip install "jmetalpy[distributed]" # Install requirements for parallel/distributed computing
pip install "jmetalpy[complete]" # Install all requirements
```
Expand Down Expand Up @@ -101,7 +102,7 @@ plot_front.plot(front, label='NSGAII-ZDT1', filename='NSGAII-ZDT1', format='png'
<img src=docs/source/_static/NSGAII-ZDT1.png width=450 alt="Pareto front approximation">

## Features
The current release of jMetalPy (v1.5.5) contains the following components:
The current release of jMetalPy (v1.5.7) contains the following components:

* Algorithms: local search, genetic algorithm, evolution strategy, simulated annealing, random search, NSGA-II, NSGA-III, SMPSO, OMOPSO, MOEA/D, MOEA/D-DRA, MOEA/D-IEpsilon, GDE3, SPEA2, HYPE, IBEA. Preference articulation-based algorithms (G-NSGA-II, G-GDE3, G-SPEA2, SMPSO/RP); Dynamic versions of NSGA-II, SMPSO, and GDE3.
* Parallel computing based on Apache Spark and Dask.
Expand All @@ -119,6 +120,7 @@ The current release of jMetalPy (v1.5.5) contains the following components:

## Changelog

* [v1.5.7] Use of linters for catching errors and formatters to fix style.
* [v1.5.6] Removed warnings when using Python 3.8.
* [v1.5.5] Minor bug fixes.
* [v1.5.4] Refactored quality indicators to accept numpy array as input parameter.
Expand Down
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import sys

sys.path.insert(0, os.path.abspath('../../'))

# -- Project information -----------------------------------------------------
Expand Down
32 changes: 17 additions & 15 deletions examples/experiment/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ def configure_experiment(problems: dict, n_run: int):
problem=problem,
population_size=100,
offspring_population_size=100,
mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables,
distribution_index=20),
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)
termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations),
),
algorithm_tag='NSGAII',
algorithm_tag="NSGAII",
problem_tag=problem_tag,
run=run,
)
Expand All @@ -38,9 +39,9 @@ def configure_experiment(problems: dict, n_run: int):
population_size=100,
cr=0.5,
f=0.5,
termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations),
),
algorithm_tag='GDE3',
algorithm_tag="GDE3",
problem_tag=problem_tag,
run=run,
)
Expand All @@ -50,12 +51,13 @@ def configure_experiment(problems: dict, n_run: int):
algorithm=SMPSO(
problem=problem,
swarm_size=100,
mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables,
distribution_index=20),
mutation=PolynomialMutation(
probability=1.0 / problem.number_of_variables, distribution_index=20
),
leaders=CrowdingDistanceArchive(100),
termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations)
termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations),
),
algorithm_tag='SMPSO',
algorithm_tag="SMPSO",
problem_tag=problem_tag,
run=run,
)
Expand All @@ -64,19 +66,19 @@ def configure_experiment(problems: dict, n_run: int):
return jobs


if __name__ == '__main__':
if __name__ == "__main__":
# Configure the experiments
jobs = configure_experiment(problems={'ZDT1': ZDT1(), 'ZDT2': ZDT2(), 'ZDT3': ZDT3()}, n_run=25)
jobs = configure_experiment(problems={"ZDT1": ZDT1(), "ZDT2": ZDT2(), "ZDT3": ZDT3()}, n_run=25)

# Run the study
output_directory = 'data'
output_directory = "data"

experiment = Experiment(output_dir=output_directory, jobs=jobs)
experiment.run()

# Generate summary file
generate_summary_from_experiment(
input_dir=output_directory,
reference_fronts='resources/reference_front',
quality_indicators=[GenerationalDistance(), EpsilonIndicator(), HyperVolume([1.0, 1.0])]
reference_fronts="resources/reference_front",
quality_indicators=[GenerationalDistance(), EpsilonIndicator(), HyperVolume([1.0, 1.0])],
)
87 changes: 47 additions & 40 deletions examples/experiment/statistical_analysis.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,75 @@
from jmetal.lab.experiment import generate_boxplot, generate_latex_tables, compute_mean_indicator, compute_wilcoxon
from jmetal.lab.experiment import (
compute_mean_indicator,
compute_wilcoxon,
generate_boxplot,
generate_latex_tables,
)
from jmetal.lab.statistical_test.bayesian import *
from jmetal.lab.statistical_test.functions import *
from jmetal.lab.visualization import CDplot, plot_posterior

if __name__ == '__main__':
if __name__ == "__main__":
# Generate Median & IQR tables
generate_latex_tables(filename='QualityIndicatorSummary.csv')
generate_latex_tables(filename="QualityIndicatorSummary.csv")

# Generate boxplots
generate_boxplot(filename='QualityIndicatorSummary.csv')
generate_boxplot(filename="QualityIndicatorSummary.csv")

# Wilcoxon
compute_wilcoxon(filename='QualityIndicatorSummary.csv')
compute_wilcoxon(filename="QualityIndicatorSummary.csv")

# Statistical lab

avg = compute_mean_indicator(filename='QualityIndicatorSummary.csv', indicator_name='HV')
avg = compute_mean_indicator(filename="QualityIndicatorSummary.csv", indicator_name="HV")
print(avg)

# Non-parametric test
print('-------- Sign Test --------')
print(sign_test(avg[['NSGAII', 'SMPSO']]))
print('-------- Friedman Test --------')
print("-------- Sign Test --------")
print(sign_test(avg[["NSGAII", "SMPSO"]]))
print("-------- Friedman Test --------")
print(friedman_test(avg))
print('-------- Friedman Aligned Rank Test --------')
print("-------- Friedman Aligned Rank Test --------")
print(friedman_aligned_rank_test(avg))
print('-------- Quade Test --------')
print("-------- Quade Test --------")
print(quade_test(avg))

# Post-hoc tests
print('-------- Friedman Post-Hoc Test --------')
z, p_val, adj_pval = friedman_ph_test(avg, control=0, apv_procedure='Bonferroni')
print('z values \n', z)
print('p-values \n', p_val)
print('adjusted p-values \n', adj_pval)
print('-------- Friedman Aligned Rank Post-Hoc Test --------')
z, p_val, adj_pval = friedman_aligned_ph_test(avg, apv_procedure='Shaffer')
print('z values \n', z)
print('p-values \n', p_val)
print('adjusted p-values \n', adj_pval)
print('-------- QuadeTest Post-Hoc Test --------')
z, p_val, adj_pval = quade_ph_test(avg, apv_procedure='Holm')
print('z values \n', z)
print('p-values \n', p_val)
print('adjusted p-values \n', adj_pval)
print("-------- Friedman Post-Hoc Test --------")
z, p_val, adj_pval = friedman_ph_test(avg, control=0, apv_procedure="Bonferroni")
print("z values \n", z)
print("p-values \n", p_val)
print("adjusted p-values \n", adj_pval)
print("-------- Friedman Aligned Rank Post-Hoc Test --------")
z, p_val, adj_pval = friedman_aligned_ph_test(avg, apv_procedure="Shaffer")
print("z values \n", z)
print("p-values \n", p_val)
print("adjusted p-values \n", adj_pval)
print("-------- QuadeTest Post-Hoc Test --------")
z, p_val, adj_pval = quade_ph_test(avg, apv_procedure="Holm")
print("z values \n", z)
print("p-values \n", p_val)
print("adjusted p-values \n", adj_pval)

# Plot critical distance

CDplot(avg.T, alpha=0.15, higher_is_better=True)

print('-------- Bayesian Sign Test --------')
bst, DProcess = bayesian_sign_test(avg[['NSGAII', 'SMPSO']], rope_limits=[-0.002, 0.002],
prior_strength=0.5, return_sample=True)
plot_posterior(DProcess, higher_is_better=True, alg_names=['NSGAII', 'SMPSO'])
print("-------- Bayesian Sign Test --------")
bst, DProcess = bayesian_sign_test(
avg[["NSGAII", "SMPSO"]], rope_limits=[-0.002, 0.002], prior_strength=0.5, return_sample=True
)
plot_posterior(DProcess, higher_is_better=True, alg_names=["NSGAII", "SMPSO"])

print('Pr(NSGAII < SMPSO) = %.3f' % bst[0])
print('Pr(NSGAII ~= SMPSO) = %.3f' % bst[1])
print('Pr(NSGAII > SMPSO) = %.3f' % bst[2])
print("Pr(NSGAII < SMPSO) = %.3f" % bst[0])
print("Pr(NSGAII ~= SMPSO) = %.3f" % bst[1])
print("Pr(NSGAII > SMPSO) = %.3f" % bst[2])

print('-------- Bayesian Signed Rank Test --------')
bst, DProcess = bayesian_signed_rank_test(avg[['NSGAII', 'SMPSO']], rope_limits=[-0.002, 0.002],
prior_strength=0.5, return_sample=True)
plot_posterior(DProcess, higher_is_better=True, alg_names=['NSGAII', 'SMPSO'])
print("-------- Bayesian Signed Rank Test --------")
bst, DProcess = bayesian_signed_rank_test(
avg[["NSGAII", "SMPSO"]], rope_limits=[-0.002, 0.002], prior_strength=0.5, return_sample=True
)
plot_posterior(DProcess, higher_is_better=True, alg_names=["NSGAII", "SMPSO"])

print('Pr(NSGAII < SMPSO) = %.3f' % bst[0])
print('Pr(NSGAII ~= SMPSO) = %.3f' % bst[1])
print('Pr(NSGAII > SMPSO) = %.3f' % bst[2])
print("Pr(NSGAII < SMPSO) = %.3f" % bst[0])
print("Pr(NSGAII ~= SMPSO) = %.3f" % bst[1])
print("Pr(NSGAII > SMPSO) = %.3f" % bst[2])
10 changes: 5 additions & 5 deletions examples/multiobjective/gde3/dynamic_gde3.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from jmetal.algorithm.multiobjective.gde3 import DynamicGDE3
from jmetal.problem.multiobjective.fda import FDA2
from jmetal.util.observable import TimeCounter
from jmetal.util.observer import WriteFrontToFileObserver, PlotFrontToFileObserver
from jmetal.util.observer import PlotFrontToFileObserver, WriteFrontToFileObserver
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
if __name__ == "__main__":
problem = FDA2()

time_counter = TimeCounter(delay=1)
Expand All @@ -16,10 +16,10 @@
population_size=100,
cr=0.5,
f=0.5,
termination_criterion=StoppingByEvaluations(max_evaluations=500)
termination_criterion=StoppingByEvaluations(max_evaluations=500),
)

algorithm.observable.register(observer=PlotFrontToFileObserver('dynamic_front_vis'))
algorithm.observable.register(observer=WriteFrontToFileObserver('dynamic_front'))
algorithm.observable.register(observer=PlotFrontToFileObserver("dynamic_front_vis"))
algorithm.observable.register(observer=WriteFrontToFileObserver("dynamic_front"))

algorithm.run()
14 changes: 7 additions & 7 deletions examples/multiobjective/gde3/gde3_spark_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from jmetal.util.solution import print_function_values_to_file, print_variables_to_file
from jmetal.util.termination_criterion import StoppingByEvaluations

if __name__ == '__main__':
if __name__ == "__main__":
problem = ZDT1Modified()

algorithm = GDE3(
Expand All @@ -13,16 +13,16 @@
cr=0.5,
f=0.5,
termination_criterion=StoppingByEvaluations(max_evaluations=100),
population_evaluator=SparkEvaluator()
population_evaluator=SparkEvaluator(),
)

algorithm.run()
front = algorithm.get_result()

# Save results to file
print_function_values_to_file(front, 'FUN.' + algorithm.get_name() + "." + problem.get_name())
print_variables_to_file(front, 'VAR.' + algorithm.get_name() + "." + problem.get_name())
print_function_values_to_file(front, "FUN." + algorithm.get_name() + "." + problem.get_name())
print_variables_to_file(front, "VAR." + algorithm.get_name() + "." + problem.get_name())

print('Algorithm (continuous problem): ' + algorithm.get_name())
print('Problem: ' + problem.get_name())
print('Computing time: ' + str(algorithm.total_computing_time))
print("Algorithm (continuous problem): " + algorithm.get_name())
print("Problem: " + problem.get_name())
print("Computing time: " + str(algorithm.total_computing_time))
28 changes: 13 additions & 15 deletions examples/multiobjective/gde3/gde3_zdt1.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
from jmetal.algorithm.multiobjective.gde3 import GDE3
from jmetal.problem import ZDT1
from jmetal.util.solution import read_solutions, print_function_values_to_file, print_variables_to_file
from jmetal.util.solution import (
print_function_values_to_file,
print_variables_to_file,
read_solutions,
)
from jmetal.util.termination_criterion import StoppingByKeyboard

if __name__ == '__main__':
if __name__ == "__main__":
problem = ZDT1()
problem.reference_front = read_solutions(filename='resources/reference_front/ZDT1.pf')
problem.reference_front = read_solutions(filename="resources/reference_front/ZDT1.pf")

algorithm = GDE3(
problem=problem,
population_size=100,
cr=0.5,
f=0.5,
termination_criterion=StoppingByKeyboard()
)
algorithm = GDE3(problem=problem, population_size=100, cr=0.5, f=0.5, termination_criterion=StoppingByKeyboard())

algorithm.run()
front = algorithm.get_result()

# Save results to file
print_function_values_to_file(front, 'FUN.' + algorithm.label)
print_variables_to_file(front, 'VAR.'+ algorithm.label)
print_function_values_to_file(front, "FUN." + algorithm.label)
print_variables_to_file(front, "VAR." + algorithm.label)

print(f'Algorithm: ${algorithm.get_name()}')
print(f'Problem: ${problem.get_name()}')
print(f'Computing time: ${algorithm.total_computing_time}')
print(f"Algorithm: ${algorithm.get_name()}")
print(f"Problem: ${problem.get_name()}")
print(f"Computing time: ${algorithm.total_computing_time}")
Loading

0 comments on commit e246758

Please sign in to comment.