Skip to content

Commit

Permalink
Merge branch 'anyoptimization:main' into reconstruct_objs
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfall-xi authored Mar 13, 2024
2 parents 9f12609 + af8d260 commit 8d9214d
Show file tree
Hide file tree
Showing 138 changed files with 2,971 additions and 3,563 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: "Set up Python"
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
Expand All @@ -24,7 +24,7 @@ jobs:
linux: "python setup.py sdist"
macos: "python setup.py bdist_wheel"
windows: "python setup.py bdist_wheel"
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist
Expand All @@ -39,6 +39,7 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
include:
- os: ubuntu-latest
python-version: "3.11"
Expand All @@ -48,7 +49,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9
- uses: RalfG/python-wheels-manylinux-build@v0.7.1-manylinux2014_x86_64
Expand All @@ -58,7 +59,7 @@ jobs:
python-versions: "cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311"
- name: "Remove non-compatible packages"
run: "sudo rm dist/*linux_x86_64.whl\n"
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install Python 3
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Dependencies
Expand Down
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/srstevenson/nb-clean
rev: 3.1.0
hooks:
- id: nb-clean
args:
- --remove-empty-cells
- --preserve-cell-metadata
- tags
- format
- raw_mimetype
- --
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ pygments
bs4
pandoc
ipykernel
jinja2==3
jinja2==3.1.3
122 changes: 25 additions & 97 deletions docs/source/algorithms/hyperparameters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
{
"cell_type": "raw",
"metadata": {
"pycharm": {
"name": "#%% raw\n"
},
"raw_mimetype": "text/restructuredtext"
},
"source": [
Expand All @@ -14,21 +11,14 @@
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"metadata": {},
"source": [
"# Hyperparameters"
]
},
{
"cell_type": "raw",
"metadata": {
"pycharm": {
"name": "#%% raw\n"
},
"raw_mimetype": "text/restructuredtext"
},
"source": [
Expand All @@ -40,29 +30,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"metadata": {},
"source": [
"Most algoriths have **hyperparameters**. For some optimization methods the parameters are already defined and can directly be optimized. For instance, for Differential Evolution (DE) the parameters can be found by:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2022-08-01T02:36:48.308627Z",
"iopub.status.busy": "2022-08-01T02:36:48.308160Z",
"iopub.status.idle": "2022-08-01T02:36:48.364512Z",
"shell.execute_reply": "2022-08-01T02:36:48.363614Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"metadata": {},
"outputs": [],
"source": [
"import json\n",
Expand All @@ -75,40 +51,22 @@
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"metadata": {},
"source": [
"If not provided directly, when initializing a `HyperparameterProblem` these variables are directly used for optimization."
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"metadata": {},
"source": [
"Secondly, one needs to define what exactly should be optimized. For instance, for a single run on a problem (with a fixed random seed) using the well-known parameter optimization toolkit [Optuna](https://optuna.org), the implementation may look as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2022-08-01T02:36:48.369753Z",
"iopub.status.busy": "2022-08-01T02:36:48.369415Z",
"iopub.status.idle": "2022-08-01T02:36:59.415863Z",
"shell.execute_reply": "2022-08-01T02:36:59.414988Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"metadata": {},
"outputs": [],
"source": [
"from pymoo.algorithms.hyperparameters import SingleObjectiveSingleRun, HyperparameterProblem\n",
Expand Down Expand Up @@ -141,29 +99,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"metadata": {},
"source": [
"Of course, you can also directly use the `MixedVariableGA` available in our framework:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2022-08-01T02:36:59.419480Z",
"iopub.status.busy": "2022-08-01T02:36:59.419084Z",
"iopub.status.idle": "2022-08-01T02:37:05.995629Z",
"shell.execute_reply": "2022-08-01T02:37:05.994612Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"metadata": {},
"outputs": [],
"source": [
"from pymoo.algorithms.hyperparameters import SingleObjectiveSingleRun, HyperparameterProblem\n",
Expand Down Expand Up @@ -198,29 +142,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"metadata": {},
"source": [
"Now, optimizing the parameters for a **single random seed** is often not desirable. And this is precisely what makes hyper-parameter optimization computationally expensive. So instead of using just a single random seed, we can use the `MultiRun` performance assessment to average over multiple runs as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2022-08-01T02:37:06.000183Z",
"iopub.status.busy": "2022-08-01T02:37:05.999864Z",
"iopub.status.idle": "2022-08-01T02:37:21.459474Z",
"shell.execute_reply": "2022-08-01T02:37:21.458554Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"metadata": {},
"outputs": [],
"source": [
"from pymoo.algorithms.hyperparameters import HyperparameterProblem, MultiRun, stats_single_objective_mean\n",
Expand Down Expand Up @@ -255,29 +185,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"metadata": {},
"source": [
"Another way of performance measure is the number of evaluations until a specific goal has been reached. For single-objective optimization, such a goal is most likely until a minimum function value has been found. Thus, for the termination, we use `MinimumFunctionValueTermination` with a value of `1e-5`. We run the method for each random seed until this value has been reached or at most `500` function evaluations have taken place. The performance is then measured by the average number of function evaluations (`func_stats=stats_avg_nevals`) to reach the goal."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2022-08-01T02:37:21.462989Z",
"iopub.status.busy": "2022-08-01T02:37:21.462728Z",
"iopub.status.idle": "2022-08-01T02:37:38.013305Z",
"shell.execute_reply": "2022-08-01T02:37:38.012403Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"metadata": {},
"outputs": [],
"source": [
"from pymoo.algorithms.hyperparameters import HyperparameterProblem, MultiRun, stats_avg_nevals\n",
Expand Down Expand Up @@ -313,7 +229,19 @@
]
}
],
"metadata": {},
"metadata": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
22 changes: 20 additions & 2 deletions docs/source/algorithms/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
" moo/age2\n",
" moo/rvea\n",
" moo/sms\n",
" moo/dnsga2\n"
" moo/dnsga2\n",
" moo/kgb\n"
]
},
{
Expand All @@ -77,7 +78,24 @@
]
}
],
"metadata": {},
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 8d9214d

Please sign in to comment.