mango 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mango-0.2.0/mango.egg-info → mango-0.2.1}/PKG-INFO +3 -3
- {mango-0.2.0 → mango-0.2.1}/README.rst +2 -2
- mango-0.2.1/docs/source/conf.py +46 -0
- mango-0.2.1/mango/__init__.py +4 -0
- mango-0.2.1/mango/benchmark/__init__.py +1 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/ackley.py +8 -2
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/bukin.py +4 -2
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/cross_in_tray.py +4 -2
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/dolan.py +4 -2
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/drop_wave.py +4 -2
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/egg_holder.py +4 -2
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/griewank.py +4 -2
- {mango-0.2.0 → mango-0.2.1}/mango/clients/aemet.py +12 -8
- mango-0.2.1/mango/models/activations.py +32 -0
- mango-0.2.1/mango/models/genetic/config/__init__.py +1 -0
- {mango-0.2.0 → mango-0.2.1}/mango/models/genetic/config/config.py +0 -1
- {mango-0.2.0 → mango-0.2.1}/mango/models/genetic/const.py +1 -1
- mango-0.2.1/mango/models/genetic/individual/base_individual.py +270 -0
- mango-0.2.1/mango/models/genetic/population/__init__.py +1 -0
- {mango-0.2.0 → mango-0.2.1}/mango/models/genetic/population/base_population.py +270 -116
- mango-0.2.1/mango/models/genetic/problem/__init__.py +1 -0
- mango-0.2.1/mango/models/genetic/problem/base_problem.py +40 -0
- mango-0.2.1/mango/models/genetic/shared/exceptions.py +14 -0
- {mango-0.2.0 → mango-0.2.1}/mango/models/neural_networks.py +4 -3
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_ackley.cfg +4 -4
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_cross_in_tray.cfg +1 -1
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_levy.cfg +2 -2
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_rastrigin.cfg +1 -1
- {mango-0.2.0 → mango-0.2.1}/mango/tests/models_module/test_genetic.py +19 -16
- {mango-0.2.0 → mango-0.2.1/mango.egg-info}/PKG-INFO +3 -3
- {mango-0.2.0 → mango-0.2.1}/mango.egg-info/SOURCES.txt +1 -0
- {mango-0.2.0 → mango-0.2.1}/mango.egg-info/top_level.txt +1 -0
- {mango-0.2.0 → mango-0.2.1}/pyproject.toml +1 -1
- mango-0.2.0/mango/__init__.py +0 -4
- mango-0.2.0/mango/models/activations.py +0 -11
- mango-0.2.0/mango/models/genetic/individual/base_individual.py +0 -142
- mango-0.2.0/mango/models/genetic/problem/base_problem.py +0 -15
- mango-0.2.0/mango/models/genetic/shared/exceptions.py +0 -6
- mango-0.2.0/mango/tests/shap_module/__init__.py +0 -0
- mango-0.2.0/mango/tests/shared_module/__init__.py +0 -0
- mango-0.2.0/mango/tests/table_module/__init__.py +0 -0
- mango-0.2.0/mango/validators/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/LICENSE +0 -0
- {mango-0.2.0 → mango-0.2.1}/MANIFEST.in +0 -0
- {mango-0.2.0/mango/benchmark → mango-0.2.1/mango/benchmark/machine_learning}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/gramacy_lee.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/holder_table.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/langermann.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/levy.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/rastrigin.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/rosenbrock.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/schaffer.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/benchmark/optimization/schwefel.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/cli/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/cli/dashboard.py +0 -0
- {mango-0.2.0/mango/benchmark/machine_learning → mango-0.2.1/mango/clients}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/clients/arcgis.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/clients/cloud_storage.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/clients/email_downloader.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/clients/email_sender.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/clients/google_cloud_storage.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/clients/rest_client.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/config/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/config/base_config.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/dashboards/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/dashboards/assets/logo.png +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/dashboards/file_explorer_app.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/data/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/data/calendar_data.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/data/ts_dataset.pkl +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/logging/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/logging/chrono.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/logging/decorators.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/logging/logger.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/models/__init__.py +0 -0
- {mango-0.2.0/mango/clients → mango-0.2.1/mango/models/genetic}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/models/genetic/individual/__init__.py +0 -0
- {mango-0.2.0/mango/models/genetic → mango-0.2.1/mango/models/genetic/shared}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/models/pyomo.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/plots/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/plots/plots.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/processing/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/processing/date_functions.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/processing/file_functions.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/processing/object_functions.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/processing/processing_time_series.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/schemas/location.json +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/shap_analysis/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/shap_analysis/const.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/shap_analysis/shap_analysis.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/shared/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/shared/const.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/shared/decorators.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/shared/exceptions.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/shared/requirement_check.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/shared/spatial.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/table/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/table/pytups_table.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/table/pytups_tools.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/table/table_tools.py +0 -0
- {mango-0.2.0/mango/models/genetic/config → mango-0.2.1/mango/tests}/__init__.py +0 -0
- {mango-0.2.0/mango/models/genetic/population → mango-0.2.1/mango/tests/clients_module}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/clients_module/test_aemet_client.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/clients_module/test_arcgis_client.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/clients_module/test_rest_client.py +0 -0
- {mango-0.2.0/mango/models/genetic/problem → mango-0.2.1/mango/tests/config_module}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/config_module/test_config.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/const.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/json_dataset.json +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/result.json +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test.csv +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test.json +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test.xlsx +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test2.csv +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_bad_type.cfg +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_bad_value.cfg +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_bukin.cfg +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_custom_problem.cfg +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_good.cfg +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_inverted_griewank_10d.cfg +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/test_schwefel.cfg +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/variables.json +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data/variables.xlsx +0 -0
- {mango-0.2.0/mango/models/genetic/shared → mango-0.2.1/mango/tests/data_module}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/data_module/test_calendar_data.py +0 -0
- {mango-0.2.0/mango/tests → mango-0.2.1/mango/tests/initialization_library}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/initialization_library/test_init.py +0 -0
- {mango-0.2.0/mango/tests/clients_module → mango-0.2.1/mango/tests/logging_module}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/logging_module/test_logging.py +0 -0
- {mango-0.2.0/mango/tests/config_module → mango-0.2.1/mango/tests/models_module}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/models_module/test_models.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/models_module/test_optimization_benchmarks.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/models_module/test_pyomo.py +0 -0
- {mango-0.2.0/mango/tests/data_module → mango-0.2.1/mango/tests/plots_module}/__init__.py +0 -0
- {mango-0.2.0/mango/tests/initialization_library → mango-0.2.1/mango/tests/processing_module}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/processing_module/test_correlation_ts.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/processing_module/test_date_functions.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/processing_module/test_file_functions.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/processing_module/test_object_functions.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/processing_module/test_processing_time_series.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/processing_module/test_tools.py +0 -0
- {mango-0.2.0/mango/tests/logging_module → mango-0.2.1/mango/tests/shap_module}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/shap_module/test_shap_analysis.py +0 -0
- {mango-0.2.0/mango/tests/models_module → mango-0.2.1/mango/tests/shared_module}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/shared_module/test_requirement_check.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/shared_module/test_spatial.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/shared_module/test_validation.py +0 -0
- {mango-0.2.0/mango/tests/plots_module → mango-0.2.1/mango/tests/table_module}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/table_module/test_table.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/tests/table_module/test_tools.py +0 -0
- {mango-0.2.0/mango/tests/processing_module → mango-0.2.1/mango/validators}/__init__.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/validators/aemet.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango/validators/arcgis.py +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango.egg-info/dependency_links.txt +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango.egg-info/entry_points.txt +0 -0
- {mango-0.2.0 → mango-0.2.1}/mango.egg-info/requires.txt +0 -0
- {mango-0.2.0 → mango-0.2.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mango
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Library with a collection of usefull classes and methods to DRY
|
|
5
5
|
Author-email: baobab soluciones <mango@baobabsoluciones.es>
|
|
6
6
|
License: Apache Software License
|
|
@@ -51,8 +51,8 @@ Requires-Dist: plotly<=5.17.0; extra == "plot"
|
|
|
51
51
|
Provides-Extra: shap
|
|
52
52
|
Requires-Dist: shap[plots]==0.43.0; extra == "shap"
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
Mango
|
|
55
|
+
------
|
|
56
56
|
|
|
57
57
|
This a library containing several modules developed by the team at baobab soluciones. These functions, classes and methods are based on their experience, understanding and knowledge of the Python language and its ecosystem.
|
|
58
58
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
|
2
|
+
#
|
|
3
|
+
# For the full list of built-in configuration values, see the documentation:
|
|
4
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
5
|
+
|
|
6
|
+
# -- Project information -----------------------------------------------------
|
|
7
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
sys.path.insert(0, os.path.abspath("../../"))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
project = "mango"
|
|
15
|
+
copyright = "2023, baobab soluciones"
|
|
16
|
+
author = "baobab soluciones"
|
|
17
|
+
# release = "0.2.0"
|
|
18
|
+
|
|
19
|
+
# -- General configuration ---------------------------------------------------
|
|
20
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
21
|
+
|
|
22
|
+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.intersphinx", "sphinxcontrib.bibtex"]
|
|
23
|
+
|
|
24
|
+
templates_path = ["templates"]
|
|
25
|
+
exclude_patterns = ["build", "Thumbs.db", ".DS_Store"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# -- Options for HTML output -------------------------------------------------
|
|
29
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
30
|
+
|
|
31
|
+
html_theme = "shibuya"
|
|
32
|
+
html_static_path = ["static"]
|
|
33
|
+
|
|
34
|
+
# autodoc_mock_imports = ["mango"]
|
|
35
|
+
autodoc_member_order = "bysource"
|
|
36
|
+
autodoc_default_options = {"members": True, "inherited-members": True}
|
|
37
|
+
|
|
38
|
+
import mango
|
|
39
|
+
|
|
40
|
+
version = mango.__version__
|
|
41
|
+
release = mango.__version__
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# Options for bibtex
|
|
45
|
+
bibtex_bibfiles = ["./refs.bib"]
|
|
46
|
+
bibtex_default_style = "plain"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .optimization import *
|
|
@@ -7,15 +7,18 @@ def ackley(x: np.ndarray) -> float:
|
|
|
7
7
|
General Ackley function.
|
|
8
8
|
|
|
9
9
|
The Ackley function is widely used for testing optimization algorithms.
|
|
10
|
+
|
|
10
11
|
In its two-dimensional form, it is characterized by a nearly flat outer region, and a large hole at the centre.
|
|
11
12
|
The function poses a risk for optimization algorithms, particularly hillclimbing algorithms,
|
|
12
13
|
to be trapped in one of its many local minima.
|
|
13
14
|
|
|
14
15
|
The global minimum point of the function is: f(x) = 0, at x = (0, ..., 0)
|
|
15
16
|
|
|
16
|
-
:param
|
|
17
|
+
:param x: numpy array of floats. The values are evaluated in the range [-32.768, 32.768]
|
|
18
|
+
:type x: :class:`numpy.ndarray`
|
|
17
19
|
:return: the value of the function
|
|
18
20
|
:rtype: float
|
|
21
|
+
:doc-author: baobab soluciones
|
|
19
22
|
"""
|
|
20
23
|
return (
|
|
21
24
|
-20 * exp(-0.2 * sqrt(1 / len(x) * np.sum(np.square(x))))
|
|
@@ -29,7 +32,10 @@ def inverted_ackley(x: np.ndarray) -> float:
|
|
|
29
32
|
"""
|
|
30
33
|
Inverted Ackley function.
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
Some description of the function.
|
|
36
|
+
|
|
37
|
+
:param x: numpy array of floats
|
|
38
|
+
:type x: :class:`numpy.ndarray`
|
|
33
39
|
:return: the value of the function
|
|
34
40
|
:rtype: float
|
|
35
41
|
"""
|
|
@@ -11,7 +11,8 @@ def bukin_function_6(x: np.array) -> float:
|
|
|
11
11
|
|
|
12
12
|
The global minima is at (-10, 1) with a value of 0.
|
|
13
13
|
|
|
14
|
-
:param
|
|
14
|
+
:param x: array of floats. Values are between [-15, 5] for x1 and [-3, 3] for x2
|
|
15
|
+
:type x: :class:`numpy.ndarray`
|
|
15
16
|
:return: the value of the function
|
|
16
17
|
:rtype: float
|
|
17
18
|
"""
|
|
@@ -22,7 +23,8 @@ def inverted_bukin_function_6(x: np.array) -> float:
|
|
|
22
23
|
"""
|
|
23
24
|
Inverted Bukin function N. 6.
|
|
24
25
|
|
|
25
|
-
:param
|
|
26
|
+
:param x: array of floats. Values are between [-15, 5] for x1 and [-3, 3] for x2
|
|
27
|
+
:type x: :class:`numpy.ndarray`
|
|
26
28
|
:return: the value of the function
|
|
27
29
|
:rtype: float
|
|
28
30
|
"""
|
|
@@ -13,7 +13,8 @@ def cross_in_tray(x: np.array) -> float:
|
|
|
13
13
|
The global mínima is located at x = (1.34941, 1.34941), (-1.34941, 1.34941), (1.34941, -1.34941)
|
|
14
14
|
and (-1.34941, -1.34941) with a value of -2.06261
|
|
15
15
|
|
|
16
|
-
:param
|
|
16
|
+
:param x: array of floats
|
|
17
|
+
:type x: :class:`numpy.ndarray`
|
|
17
18
|
:return: the value of the function
|
|
18
19
|
:rtype: float
|
|
19
20
|
"""
|
|
@@ -36,7 +37,8 @@ def inverted_cross_in_tray(x: np.array) -> float:
|
|
|
36
37
|
The Cross-in-tray function has many widespread local minima, which are regularly distributed
|
|
37
38
|
This implementation inverts the function to test out the maximization
|
|
38
39
|
|
|
39
|
-
:param
|
|
40
|
+
:param x: array of floats
|
|
41
|
+
:type x: :class:`numpy.ndarray`
|
|
40
42
|
:return: the value of the function
|
|
41
43
|
:rtype: float
|
|
42
44
|
"""
|
|
@@ -9,7 +9,8 @@ def dolan_function_no2(x: np.array) -> float:
|
|
|
9
9
|
|
|
10
10
|
The global minima is at [8.39045925, 4.81424707, 7.34574133, 68.88246895, 3.85470806] with a value of 10^-5
|
|
11
11
|
|
|
12
|
-
:param
|
|
12
|
+
:param x: array of floats. Values are evaluated between [-100, 100]
|
|
13
|
+
:type x: :class:`numpy.ndarray`
|
|
13
14
|
:return: the value of the function
|
|
14
15
|
:rtype: float
|
|
15
16
|
"""
|
|
@@ -27,7 +28,8 @@ def inverted_dolan_function_no2(x: np.array) -> float:
|
|
|
27
28
|
"""
|
|
28
29
|
Inverted Dolan function No 2.
|
|
29
30
|
|
|
30
|
-
:param
|
|
31
|
+
:param x: array of floats. Values are evaluated between [-100, 100]
|
|
32
|
+
:type x: :class:`numpy.ndarray`
|
|
31
33
|
:return: the value of the function
|
|
32
34
|
:rtype: float
|
|
33
35
|
"""
|
|
@@ -11,7 +11,8 @@ def drop_wave(x: np.array) -> float:
|
|
|
11
11
|
|
|
12
12
|
The global minima is located at x = (0, 0) with a value of -1
|
|
13
13
|
|
|
14
|
-
:param
|
|
14
|
+
:param x: array of floats. Values usually are between -5.12 and 5.12.
|
|
15
|
+
:type x: :class:`numpy.ndarray`
|
|
15
16
|
:return: the value of the function
|
|
16
17
|
:rtype: float
|
|
17
18
|
"""
|
|
@@ -29,7 +30,8 @@ def inverted_drop_wave(x: np.array) -> float:
|
|
|
29
30
|
|
|
30
31
|
The global minima is located at x = (0, 0) with a value of -1
|
|
31
32
|
|
|
32
|
-
:param
|
|
33
|
+
:param x: array of floats. Values usually are between -5.12 and 5.12.
|
|
34
|
+
:type x: :class:`numpy.ndarray`
|
|
33
35
|
:return: the value of the function
|
|
34
36
|
:rtype: float
|
|
35
37
|
"""
|
|
@@ -12,7 +12,8 @@ def egg_holder(x: np.array) -> float:
|
|
|
12
12
|
The function is usually evaluated on the square xi ∈ [-512, 512], for all i = 1, 2.
|
|
13
13
|
The global mínima is located at x = (512, 404.2319) with a value of -959.6407
|
|
14
14
|
|
|
15
|
-
:param
|
|
15
|
+
:param x: array of floats
|
|
16
|
+
:type x: :class:`numpy.ndarray`
|
|
16
17
|
:return: the value of the function
|
|
17
18
|
:rtype: float
|
|
18
19
|
"""
|
|
@@ -28,7 +29,8 @@ def inverted_egg_holder(x: np.array) -> float:
|
|
|
28
29
|
The Egg-holder function has many widespread local minima, which are regularly distributed
|
|
29
30
|
This implementation inverts the function to test out the maximization
|
|
30
31
|
|
|
31
|
-
:param
|
|
32
|
+
:param x: array of floats
|
|
33
|
+
:type x: :class:`numpy.ndarray`
|
|
32
34
|
:return: the value of the function
|
|
33
35
|
:rtype: float
|
|
34
36
|
"""
|
|
@@ -9,7 +9,8 @@ def griewank(x: np.array) -> float:
|
|
|
9
9
|
|
|
10
10
|
The Griewank function has many widespread local minima, which are regularly distributed
|
|
11
11
|
|
|
12
|
-
:param
|
|
12
|
+
:param x: array of floats
|
|
13
|
+
:type x: :class:`numpy.ndarray`
|
|
13
14
|
:return: the value of the function
|
|
14
15
|
:rtype: float
|
|
15
16
|
"""
|
|
@@ -27,7 +28,8 @@ def inverted_griewank(x: np.array) -> float:
|
|
|
27
28
|
The Griewank function has many widespread local minima, which are regularly distributed
|
|
28
29
|
This implementation inverts the function to test out the maximization
|
|
29
30
|
|
|
30
|
-
:param
|
|
31
|
+
:param x: array of floats
|
|
32
|
+
:type x: :class:`numpy.ndarray`
|
|
31
33
|
:return: the value of the function
|
|
32
34
|
:rtype: float
|
|
33
35
|
"""
|
|
@@ -87,6 +87,7 @@ class AEMETClient(RESTClient):
|
|
|
87
87
|
def all_stations(self) -> List[dict]:
|
|
88
88
|
"""
|
|
89
89
|
This property will return all the meteorological stations in Spain.
|
|
90
|
+
|
|
90
91
|
:return: List of dictionaries with the meteorological stations
|
|
91
92
|
:doc-author: baobab soluciones
|
|
92
93
|
"""
|
|
@@ -96,6 +97,7 @@ class AEMETClient(RESTClient):
|
|
|
96
97
|
def municipios(self) -> List[dict]:
|
|
97
98
|
"""
|
|
98
99
|
This property will return all the municipios in Spain.
|
|
100
|
+
|
|
99
101
|
:return: List of dictionaries with the municipios
|
|
100
102
|
:doc-author: baobab soluciones
|
|
101
103
|
"""
|
|
@@ -401,6 +403,15 @@ class AEMETClient(RESTClient):
|
|
|
401
403
|
Main method of the class. This method will return the meteorological data from the meteorological stations in
|
|
402
404
|
Spain.
|
|
403
405
|
|
|
406
|
+
:param str station_code: meteorological station code
|
|
407
|
+
:param float lat: latitude
|
|
408
|
+
:param float long: longitude
|
|
409
|
+
:param str province: province
|
|
410
|
+
:param datetime start_date: start date
|
|
411
|
+
:param datetime end_date: end date
|
|
412
|
+
:return: a list of dictionaries with the meteorological data
|
|
413
|
+
:doc-author: baobab soluciones
|
|
414
|
+
|
|
404
415
|
Usage
|
|
405
416
|
-----
|
|
406
417
|
|
|
@@ -432,14 +443,7 @@ class AEMETClient(RESTClient):
|
|
|
432
443
|
|
|
433
444
|
>>> data = client.get_meteo_data(lat=40.4165, long=-3.70256, province="Madrid", output_format="df")
|
|
434
445
|
|
|
435
|
-
|
|
436
|
-
:param float lat: latitude
|
|
437
|
-
:param float long: longitude
|
|
438
|
-
:param str province: province
|
|
439
|
-
:param datetime start_date: start date
|
|
440
|
-
:param datetime end_date: end date
|
|
441
|
-
:return: a list of dictionaries with the meteorological data
|
|
442
|
-
:doc-author: baobab soluciones
|
|
446
|
+
|
|
443
447
|
"""
|
|
444
448
|
# Check datatype
|
|
445
449
|
if station_code and not isinstance(station_code, str):
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# noinspection PyTypeChecker
|
|
5
|
+
def sigmoid(x: float, factor: float = 1) -> float:
|
|
6
|
+
"""
|
|
7
|
+
Sigmoid funtion with a factor to control the slope
|
|
8
|
+
|
|
9
|
+
:param x: the input value
|
|
10
|
+
:type x: float
|
|
11
|
+
:param factor: the factor to control the slope, defaults to 1
|
|
12
|
+
:type factor: float, optional
|
|
13
|
+
:return: the sigmoid value
|
|
14
|
+
:rtype: float
|
|
15
|
+
"""
|
|
16
|
+
x = max(-60, min(60, factor * x))
|
|
17
|
+
return 1 / (1 + math.exp(-x))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# noinspection PyTypeChecker
|
|
21
|
+
def tanh(x: float, factor: float = 1) -> float:
|
|
22
|
+
"""
|
|
23
|
+
Tanh funtion with a factor to control the slope
|
|
24
|
+
|
|
25
|
+
:param x: the input value
|
|
26
|
+
:type x: float
|
|
27
|
+
:param factor: the factor to control the slope, defaults to 1
|
|
28
|
+
:type factor: float, optional
|
|
29
|
+
:return: the tanh value
|
|
30
|
+
"""
|
|
31
|
+
x = max(-60, min(60, factor * x))
|
|
32
|
+
return math.tanh(x)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .config import GeneticBaseConfig
|
|
@@ -51,7 +51,6 @@ class GeneticBaseConfig(BaseConfig):
|
|
|
51
51
|
),
|
|
52
52
|
],
|
|
53
53
|
"crossover": [
|
|
54
|
-
ConfigParameter("morphology_parents", int, 3, required=False),
|
|
55
54
|
ConfigParameter("offspring_size", int, 100, required=False),
|
|
56
55
|
ConfigParameter("blend_expansion", float, 0.1, required=False),
|
|
57
56
|
],
|
|
@@ -11,7 +11,7 @@ CROSSOVER_METHODS = [
|
|
|
11
11
|
"gaussian",
|
|
12
12
|
]
|
|
13
13
|
|
|
14
|
-
MUTATION_CONTROL_METHODS = ["
|
|
14
|
+
MUTATION_CONTROL_METHODS = ["static", "adaptative", "gene-based", "population-based"]
|
|
15
15
|
|
|
16
16
|
REPLACEMENT_METHODS = [
|
|
17
17
|
"elitist",
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
from random import uniform, randint
|
|
2
|
+
from mango.models.genetic.config import GeneticBaseConfig
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Individual:
|
|
7
|
+
def __init__(self, genes=None, idx: int = 0, parents: tuple = None, config=None):
|
|
8
|
+
self.fitness = None
|
|
9
|
+
self.idx = idx
|
|
10
|
+
self.config = config
|
|
11
|
+
self.parents_idx = None
|
|
12
|
+
self.parents = parents
|
|
13
|
+
|
|
14
|
+
# Info to get from config file
|
|
15
|
+
self.encoding = self.config("encoding")
|
|
16
|
+
self.min_bound = self.config("gene_min_value")
|
|
17
|
+
self.max_bound = self.config("gene_max_value")
|
|
18
|
+
self.gene_length = self.config("gene_length")
|
|
19
|
+
|
|
20
|
+
self.genes = genes
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def genes(self) -> np.ndarray:
|
|
24
|
+
"""
|
|
25
|
+
Property that stores the :class:`numpy.ndarray` of genes in the individual
|
|
26
|
+
|
|
27
|
+
If max_bound or min_bound are set, the genes values are clipped to the bounds.
|
|
28
|
+
After setting the value for the genes the hash is updated.
|
|
29
|
+
|
|
30
|
+
:param value: the new value for the genes (used on setting up the property)
|
|
31
|
+
:type value: :class:`numpy.ndarray`
|
|
32
|
+
:return: the genes value
|
|
33
|
+
"""
|
|
34
|
+
return self._genes
|
|
35
|
+
|
|
36
|
+
@genes.setter
|
|
37
|
+
def genes(self, value: np.ndarray = None):
|
|
38
|
+
if (
|
|
39
|
+
value is not None
|
|
40
|
+
and self.max_bound is not None
|
|
41
|
+
and self.min_bound is not None
|
|
42
|
+
):
|
|
43
|
+
value[np.greater(value, self.max_bound)] = self.max_bound
|
|
44
|
+
value[np.less(value, self.min_bound)] = self.min_bound
|
|
45
|
+
self._genes = value
|
|
46
|
+
if self._genes is not None:
|
|
47
|
+
self._hash = self.__hash__()
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def idx(self) -> int:
|
|
51
|
+
"""
|
|
52
|
+
Property that stores the internal idx of the Individual. This value is just to help
|
|
53
|
+
distinguish between individuals.
|
|
54
|
+
|
|
55
|
+
:param value: the new value for the idx (used on setting up the property)
|
|
56
|
+
:type value: int
|
|
57
|
+
:return: the idx value
|
|
58
|
+
"""
|
|
59
|
+
return self._idx
|
|
60
|
+
|
|
61
|
+
@idx.setter
|
|
62
|
+
def idx(self, value: int):
|
|
63
|
+
self._idx = value
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def config(self) -> GeneticBaseConfig:
|
|
67
|
+
"""
|
|
68
|
+
Property that stores the config object for the individual
|
|
69
|
+
|
|
70
|
+
:param value: the new value for the config (used on setting up the property)
|
|
71
|
+
:type value: :class:`mango.models.genetic.config.GeneticBaseConfig`
|
|
72
|
+
:return: the config value
|
|
73
|
+
"""
|
|
74
|
+
return self._config
|
|
75
|
+
|
|
76
|
+
@config.setter
|
|
77
|
+
def config(self, value: GeneticBaseConfig):
|
|
78
|
+
self._config = value
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
def parents(self) -> tuple:
|
|
82
|
+
"""
|
|
83
|
+
Property that stores the parents of the individual and their idx.
|
|
84
|
+
|
|
85
|
+
During the setter the value for attribute parents_idx
|
|
86
|
+
is updated as well as a tuple of the idx of all the parents
|
|
87
|
+
|
|
88
|
+
:param value: the new value for the parents (used on setting up the property)
|
|
89
|
+
:type value: tuple
|
|
90
|
+
:return: the parents value
|
|
91
|
+
"""
|
|
92
|
+
return self._parents
|
|
93
|
+
|
|
94
|
+
@parents.setter
|
|
95
|
+
def parents(self, value: tuple):
|
|
96
|
+
self._parents = value
|
|
97
|
+
if self._parents is not None:
|
|
98
|
+
self.parents_idx = tuple([p.idx for p in self.parents])
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def encoding(self) -> str:
|
|
102
|
+
"""
|
|
103
|
+
Property that stores the encoding type for the individual
|
|
104
|
+
|
|
105
|
+
:param value: the new value for the encoding (used on setting up the property)
|
|
106
|
+
:type value: str
|
|
107
|
+
:return: the encoding value
|
|
108
|
+
:rtype: str
|
|
109
|
+
"""
|
|
110
|
+
return self._encoding
|
|
111
|
+
|
|
112
|
+
@encoding.setter
|
|
113
|
+
def encoding(self, value):
|
|
114
|
+
self._encoding = value
|
|
115
|
+
|
|
116
|
+
@property
|
|
117
|
+
def fitness(self) -> float:
|
|
118
|
+
"""
|
|
119
|
+
Property that stores the fitness value for the individual
|
|
120
|
+
|
|
121
|
+
:param value: the new value for the fitness (used on setting up the property)
|
|
122
|
+
:type value: float
|
|
123
|
+
:return: the fitness value
|
|
124
|
+
"""
|
|
125
|
+
return self._fitness
|
|
126
|
+
|
|
127
|
+
@fitness.setter
|
|
128
|
+
def fitness(self, value):
|
|
129
|
+
self._fitness = value
|
|
130
|
+
|
|
131
|
+
@classmethod
|
|
132
|
+
def create_random_individual(
|
|
133
|
+
cls, idx: int, config: GeneticBaseConfig
|
|
134
|
+
) -> "Individual":
|
|
135
|
+
"""
|
|
136
|
+
Class method that creates a new individual with random genes.
|
|
137
|
+
|
|
138
|
+
:param idx: the idx of the new individual
|
|
139
|
+
:type idx: int
|
|
140
|
+
:param config: the config object for the individual
|
|
141
|
+
:type config: :class:`mango.models.genetic.config.GeneticBaseConfig`
|
|
142
|
+
:return: the new individual
|
|
143
|
+
"""
|
|
144
|
+
ind = cls(idx=idx, config=config)
|
|
145
|
+
|
|
146
|
+
ind.create_random_genes()
|
|
147
|
+
return ind
|
|
148
|
+
|
|
149
|
+
def create_random_genes(self):
|
|
150
|
+
"""
|
|
151
|
+
Method to create random genes for an individual based on the encoding type.
|
|
152
|
+
|
|
153
|
+
The genes are stored in the :attr:`genes` attribute
|
|
154
|
+
"""
|
|
155
|
+
if self.encoding == "real":
|
|
156
|
+
self.genes = np.random.uniform(
|
|
157
|
+
self.min_bound, self.max_bound, self.gene_length
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
elif self.encoding == "binary":
|
|
161
|
+
self.genes = np.random.randint(0, 2, self.gene_length)
|
|
162
|
+
|
|
163
|
+
elif self.encoding == "integer":
|
|
164
|
+
self.genes = np.random.randint(
|
|
165
|
+
self.min_bound, self.max_bound + 1, self.gene_length
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
def mutate(self, mutation_prob: float = None):
|
|
169
|
+
"""
|
|
170
|
+
Method to mutate the individual based on the encoding type.
|
|
171
|
+
|
|
172
|
+
The mutation probability is used to determine if the individual will be mutated or not.
|
|
173
|
+
An individual can have more than one gene that gets mutated. The
|
|
174
|
+
|
|
175
|
+
:param mutation_prob: the probability of mutation
|
|
176
|
+
:type mutation_prob: float
|
|
177
|
+
"""
|
|
178
|
+
keep = True
|
|
179
|
+
while keep:
|
|
180
|
+
chance = uniform(0, 1)
|
|
181
|
+
if chance <= mutation_prob:
|
|
182
|
+
if self.encoding == "real":
|
|
183
|
+
self._mutate_real()
|
|
184
|
+
elif self.encoding == "binary":
|
|
185
|
+
self._mutate_binary()
|
|
186
|
+
elif self.encoding == "integer":
|
|
187
|
+
self._mutate_integer()
|
|
188
|
+
else:
|
|
189
|
+
raise NotImplemented("Only real encoding is implemented for now")
|
|
190
|
+
self._hash = self.__hash__()
|
|
191
|
+
else:
|
|
192
|
+
keep = False
|
|
193
|
+
|
|
194
|
+
def _mutate_binary(self):
|
|
195
|
+
"""
|
|
196
|
+
Mutation method for the binary values encoding.
|
|
197
|
+
|
|
198
|
+
This mutation is a simple bit flip on the calculated gene position
|
|
199
|
+
"""
|
|
200
|
+
gene_position = randint(0, self.gene_length - 1)
|
|
201
|
+
self.genes[gene_position] = 1 - self.genes[gene_position]
|
|
202
|
+
|
|
203
|
+
def _mutate_integer(self):
|
|
204
|
+
"""
|
|
205
|
+
Mutation method for the integer values encoding.
|
|
206
|
+
|
|
207
|
+
This mutation is a simple random value between the min and max bounds (randint)
|
|
208
|
+
"""
|
|
209
|
+
gene_position = randint(0, self.gene_length - 1)
|
|
210
|
+
self.genes[gene_position] = randint(self.min_bound, self.max_bound)
|
|
211
|
+
|
|
212
|
+
def _mutate_real(self):
|
|
213
|
+
"""
|
|
214
|
+
Mutation method for the real values encoding
|
|
215
|
+
|
|
216
|
+
This mutation is a simple random value between the min and max bounds
|
|
217
|
+
"""
|
|
218
|
+
gene_position = randint(0, self.gene_length - 1)
|
|
219
|
+
self.genes[gene_position] = uniform(self.min_bound, self.max_bound)
|
|
220
|
+
|
|
221
|
+
def dominates(self, other):
|
|
222
|
+
"""
|
|
223
|
+
This method should implement the logic to check if one individual dominates another one
|
|
224
|
+
|
|
225
|
+
The domination concept is mainly used in multiobjective optimization problems.
|
|
226
|
+
A solution dominates another when the first one is equal or better in all objectives and one objective
|
|
227
|
+
is at least better than the other solution
|
|
228
|
+
"""
|
|
229
|
+
raise NotImplemented
|
|
230
|
+
|
|
231
|
+
def copy(self) -> "Individual":
|
|
232
|
+
"""
|
|
233
|
+
Method to create a copy of the individual
|
|
234
|
+
"""
|
|
235
|
+
return Individual(
|
|
236
|
+
genes=self.genes.copy(),
|
|
237
|
+
idx=self.idx,
|
|
238
|
+
config=self.config,
|
|
239
|
+
parents=self.parents,
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
def __hash__(self):
|
|
243
|
+
"""
|
|
244
|
+
Method to calculate the hash of the individual and store it in the :attr:`_hash` attribute
|
|
245
|
+
|
|
246
|
+
The hash is calculated based on the byte representation of the genes of the individual so that only individuals
|
|
247
|
+
with the same genome have the hash
|
|
248
|
+
"""
|
|
249
|
+
return hash(self.genes.tobytes())
|
|
250
|
+
|
|
251
|
+
def __eq__(self, other) -> bool:
|
|
252
|
+
"""
|
|
253
|
+
Method to compare two individuals
|
|
254
|
+
|
|
255
|
+
In order to make this comparison as fast as possible it used the pre-generated hash to compare the individuals.
|
|
256
|
+
So the comparison is made on the genotype instead of the phenotype, as two individuals with different
|
|
257
|
+
genotypes can have the same phenotype, so they should be considered as not equal
|
|
258
|
+
for crossover and genetic diversity purposes.
|
|
259
|
+
|
|
260
|
+
:param other: the other individual to compare
|
|
261
|
+
:return: True if the individuals are equal, False otherwise
|
|
262
|
+
:rtype: bool
|
|
263
|
+
"""
|
|
264
|
+
if isinstance(other, self.__class__):
|
|
265
|
+
return self._hash == other._hash
|
|
266
|
+
|
|
267
|
+
return False
|
|
268
|
+
|
|
269
|
+
def __repr__(self):
|
|
270
|
+
return f"Individual {self.idx}"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .base_population import Population
|