diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 77811f5..46ac988 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,6 @@ stages: - sonarqube-check + - build include: - local: ".gitlab/ci/*.gitlab-ci.yml" diff --git a/.gitlab/ci/pypi.gitlab-ci.yml b/.gitlab/ci/pypi.gitlab-ci.yml new file mode 100644 index 0000000..e4eddf1 --- /dev/null +++ b/.gitlab/ci/pypi.gitlab-ci.yml @@ -0,0 +1,18 @@ +variables: + PYTHON_VERSION: "3.9" + TWINE_USERNAME: "__token__" + +build-package: + stage: build + image: python:${PYTHON_VERSION} + script: + - pip install --upgrade pip + - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - pip install setuptools wheel twine + - python setup.py bdist_wheel sdist + - twine upload dist/*.whl dist/*.tar.gz + + only: + changes: + - "setup.py" + - "pso/__init__.py" diff --git a/README.md b/README.md index 760daee..335d429 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ [![Python Package Index publish](https://github.com/jung-geun/PSO/actions/workflows/pypi.yml/badge.svg?event=push)](https://github.com/jung-geun/PSO/actions/workflows/pypi.yml) [![PyPI - Version](https://img.shields.io/pypi/v/pso2keras)](https://pypi.org/project/pso2keras/) +[![Quality Gate Status](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a&metric=alert_status&token=sqb_5fa45d924cd1c13f71a23a9283fba9460dc63eb6)](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a) +[![Duplicated Lines (%)](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a&metric=duplicated_lines_density&token=sqb_5fa45d924cd1c13f71a23a9283fba9460dc63eb6)](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a) +[![Security Rating](https://sonar.pieroot.xyz/api/project_badges/measure?project=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a&metric=security_rating&token=sqb_5fa45d924cd1c13f71a23a9283fba9460dc63eb6)](https://sonar.pieroot.xyz/dashboard?id=pieroot_pso_6a2f36a9-2688-4900-a4a5-5be85f36f75a) ### 목차 diff --git a/example/pso2mnist.ipynb b/example/pso2mnist.ipynb index 3c3c91c..5afc5e5 100644 --- a/example/pso2mnist.ipynb +++ b/example/pso2mnist.ipynb @@ -1,2108 +1,39 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "provenance": [], - "gpuType": "T4", - "toc_visible": true, - "authorship_tag": "ABX9TyNDq7eqYNONDQtXQtyrQuT3", - "include_colab_link": true - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - }, - "accelerator": "GPU", - "widgets": { - "application/vnd.jupyter.widget-state+json": { - "60384954600849c984ec832f1e0ba089": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HBoxModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HBoxModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HBoxView", - "box_style": "", - "children": [ - "IPY_MODEL_f4493e24f41f46d98a5c6307d4381858", - "IPY_MODEL_244e9d76fe934af2b536d4a41bd9ebc5", - "IPY_MODEL_64ee09f226ae41e8a8d7203db2370f64" - ], - "layout": "IPY_MODEL_62129a4ae85b4aabb44cbb4c594ae7e5" - } - }, - "f4493e24f41f46d98a5c6307d4381858": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_bd5692b1b8b4471f901e27df360f055e", - "placeholder": "​", - "style": "IPY_MODEL_0cd1cd1ade0445a28f6020c1b52ed7f4", - "value": "Initializing Particles: 100%" - } - }, - "244e9d76fe934af2b536d4a41bd9ebc5": { - "model_module": "@jupyter-widgets/controls", - "model_name": "FloatProgressModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatProgressModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "ProgressView", - "bar_style": "success", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_f60caa635a1f4024b6bfd9bdc9a2d500", - "max": 500, - "min": 0, - "orientation": "horizontal", - "style": "IPY_MODEL_f3452c1a31664a38b4ba3ad870cb9286", - "value": 500 - } - }, - "64ee09f226ae41e8a8d7203db2370f64": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_262f741d45bf4069912d9e4ba4345450", - "placeholder": "​", - "style": "IPY_MODEL_02e4861a0c934115bf494bca20a87e83", - "value": " 500/500 [03:47<00:00, 1.63it/s]" - } - }, - "62129a4ae85b4aabb44cbb4c594ae7e5": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "bd5692b1b8b4471f901e27df360f055e": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "0cd1cd1ade0445a28f6020c1b52ed7f4": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "f60caa635a1f4024b6bfd9bdc9a2d500": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "f3452c1a31664a38b4ba3ad870cb9286": { - "model_module": "@jupyter-widgets/controls", - "model_name": "ProgressStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "ProgressStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "bar_color": null, - "description_width": "" - } - }, - "262f741d45bf4069912d9e4ba4345450": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "02e4861a0c934115bf494bca20a87e83": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "0aa01a9086594c09b7be442781d15761": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HBoxModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HBoxModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HBoxView", - "box_style": "", - "children": [ - "IPY_MODEL_55e5e64d8e484ae89b2bf56c0ce8a4e1", - "IPY_MODEL_b14bb35224404b58b2ea121b91152564", - "IPY_MODEL_8eacb4db3ae345bfa22f89ec79285648" - ], - "layout": "IPY_MODEL_045717bfe98c420ebc4342d0061913a0" - } - }, - "55e5e64d8e484ae89b2bf56c0ce8a4e1": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_6bd647b0e49c4d13b3a937dd325054d0", - "placeholder": "​", - "style": "IPY_MODEL_86ccd693148940d29d5ed92a81a0d25c", - "value": "Initializing velocity: 100%" - } - }, - "b14bb35224404b58b2ea121b91152564": { - "model_module": "@jupyter-widgets/controls", - "model_name": "FloatProgressModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatProgressModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "ProgressView", - "bar_style": "success", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_bf1ea704226b4fee9caed1a86bd6fc03", - "max": 500, - "min": 0, - "orientation": "horizontal", - "style": "IPY_MODEL_bf625ea23d2c4aaa9cbc404fe88f0c61", - "value": 500 - } - }, - "8eacb4db3ae345bfa22f89ec79285648": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_520f094d24d443e0b487d2717569f3b5", - "placeholder": "​", - "style": "IPY_MODEL_eb816e9a17e245f5b0c41c552dd76183", - "value": " 500/500 [16:28<00:00, 1.96s/it]" - } - }, - "045717bfe98c420ebc4342d0061913a0": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "6bd647b0e49c4d13b3a937dd325054d0": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "86ccd693148940d29d5ed92a81a0d25c": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "bf1ea704226b4fee9caed1a86bd6fc03": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "bf625ea23d2c4aaa9cbc404fe88f0c61": { - "model_module": "@jupyter-widgets/controls", - "model_name": "ProgressStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "ProgressStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "bar_color": null, - "description_width": "" - } - }, - "520f094d24d443e0b487d2717569f3b5": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "eb816e9a17e245f5b0c41c552dd76183": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "fae612998dec4856b30ebb2e5ececdfc": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HBoxModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HBoxModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HBoxView", - "box_style": "", - "children": [ - "IPY_MODEL_fae548adc4294068a80d5b11572e411e", - "IPY_MODEL_415a6d555c95480da6fb9ad727ffd69a", - "IPY_MODEL_7e7a010af89d42bd94c558bb72d76230" - ], - "layout": "IPY_MODEL_63d9eccdf7ea4a22a692cc1e0c1fbbc7" - } - }, - "fae548adc4294068a80d5b11572e411e": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_822baf2dcccb41dcafc7139114a268a0", - "placeholder": "​", - "style": "IPY_MODEL_f1599b1fafd6424483c5f404b3c79fd6", - "value": "best 0.2993 | 0.1576: 1%" - } - }, - "415a6d555c95480da6fb9ad727ffd69a": { - "model_module": "@jupyter-widgets/controls", - "model_name": "FloatProgressModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatProgressModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "ProgressView", - "bar_style": "", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_6b60ab162f5a43e49904ea89ffe0f3ba", - "max": 200, - "min": 0, - "orientation": "horizontal", - "style": "IPY_MODEL_b2a43a859d8e442d8d2dc8eb2cb489a4", - "value": 2 - } - }, - "7e7a010af89d42bd94c558bb72d76230": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_5c9870ced6f845f2909f706727ba5877", - "placeholder": "​", - "style": "IPY_MODEL_456cfb7462d74aeab02f9a0af32f769f", - "value": " 2/200 [23:28<29:39:45, 539.32s/it]" - } - }, - "63d9eccdf7ea4a22a692cc1e0c1fbbc7": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "822baf2dcccb41dcafc7139114a268a0": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "f1599b1fafd6424483c5f404b3c79fd6": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "6b60ab162f5a43e49904ea89ffe0f3ba": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "b2a43a859d8e442d8d2dc8eb2cb489a4": { - "model_module": "@jupyter-widgets/controls", - "model_name": "ProgressStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "ProgressStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "bar_color": null, - "description_width": "" - } - }, - "5c9870ced6f845f2909f706727ba5877": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "456cfb7462d74aeab02f9a0af32f769f": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "09eb0575ee1c4bd288b5f0a79c506f67": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HBoxModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HBoxModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HBoxView", - "box_style": "", - "children": [ - "IPY_MODEL_cb35fee4c8a94812b209a61499687824", - "IPY_MODEL_bbca06083a094719a58367dce36c5fe0", - "IPY_MODEL_df7e251ff08b443f924eafcdf4627721" - ], - "layout": "IPY_MODEL_c1026663b57243d5b4fd651d06b83beb" - } - }, - "cb35fee4c8a94812b209a61499687824": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_fb4c68e932bc48ada671c11bd4b51fcb", - "placeholder": "​", - "style": "IPY_MODEL_0efa7087787445f993e83a41ebc5136d", - "value": "acc : 0.2136 loss : 0.1573: 100%" - } - }, - "bbca06083a094719a58367dce36c5fe0": { - "model_module": "@jupyter-widgets/controls", - "model_name": "FloatProgressModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatProgressModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "ProgressView", - "bar_style": "", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_95840eaab18b4dd6ba90acd7602112c1", - "max": 500, - "min": 0, - "orientation": "horizontal", - "style": "IPY_MODEL_c1525b47e0d9487fb54849863ebaa4e0", - "value": 500 - } - }, - "df7e251ff08b443f924eafcdf4627721": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_f20e024da5414b00becceb0541e3e45e", - "placeholder": "​", - "style": "IPY_MODEL_1b6fed5a1fb24d7d8fcc7dfd7e56e618", - "value": " 500/500 [08:41<00:00, 1.28it/s]" - } - }, - "c1026663b57243d5b4fd651d06b83beb": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": "hidden", - "width": null - } - }, - "fb4c68e932bc48ada671c11bd4b51fcb": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "0efa7087787445f993e83a41ebc5136d": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "95840eaab18b4dd6ba90acd7602112c1": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "c1525b47e0d9487fb54849863ebaa4e0": { - "model_module": "@jupyter-widgets/controls", - "model_name": "ProgressStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "ProgressStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "bar_color": null, - "description_width": "" - } - }, - "f20e024da5414b00becceb0541e3e45e": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "1b6fed5a1fb24d7d8fcc7dfd7e56e618": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "31537bf870cd4dbcbee4f55d1383a4f4": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HBoxModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HBoxModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HBoxView", - "box_style": "", - "children": [ - "IPY_MODEL_78c7e54708884ef0bf3feadf4e86b27b", - "IPY_MODEL_de7b67b83e934558a122203e6314fb67", - "IPY_MODEL_00e855c093c947a2bf0c7ec644b6e401" - ], - "layout": "IPY_MODEL_b4929212a2634d7ea12a77f79e4d61ff" - } - }, - "78c7e54708884ef0bf3feadf4e86b27b": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_cbea21e8c9004b149bd86e1b0c1e67ce", - "placeholder": "​", - "style": "IPY_MODEL_f1b4dc5fe13546c19c4bbfecb390e328", - "value": "acc : 0.2564 loss : 0.1487: 100%" - } - }, - "de7b67b83e934558a122203e6314fb67": { - "model_module": "@jupyter-widgets/controls", - "model_name": "FloatProgressModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatProgressModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "ProgressView", - "bar_style": "", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_0048352cbddf4e5282be22298975efc4", - "max": 500, - "min": 0, - "orientation": "horizontal", - "style": "IPY_MODEL_52d399c1dfe4440baa77b540a2b5664c", - "value": 500 - } - }, - "00e855c093c947a2bf0c7ec644b6e401": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_4ce75915aeb4484e9f1d3f6a2a262c76", - "placeholder": "​", - "style": "IPY_MODEL_191804b6a0d64c1aafd50b1518c8e7e5", - "value": " 500/500 [09:08<00:00, 1.18s/it]" - } - }, - "b4929212a2634d7ea12a77f79e4d61ff": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": "hidden", - "width": null - } - }, - "cbea21e8c9004b149bd86e1b0c1e67ce": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "f1b4dc5fe13546c19c4bbfecb390e328": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "0048352cbddf4e5282be22298975efc4": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "52d399c1dfe4440baa77b540a2b5664c": { - "model_module": "@jupyter-widgets/controls", - "model_name": "ProgressStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "ProgressStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "bar_color": null, - "description_width": "" - } - }, - "4ce75915aeb4484e9f1d3f6a2a262c76": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "191804b6a0d64c1aafd50b1518c8e7e5": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "872b2c7612c44b15bdcee774fb9e70b7": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HBoxModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HBoxModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HBoxView", - "box_style": "", - "children": [ - "IPY_MODEL_b14aa26f85e148359bc9abff58951b51", - "IPY_MODEL_77a9f488c18c4487ae107bee7362b643", - "IPY_MODEL_b66fc8e0b5144229a69c5f2942ab796a" - ], - "layout": "IPY_MODEL_bdda4512f2ec4290b29bf69d9b4808fe" - } - }, - "b14aa26f85e148359bc9abff58951b51": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_2fb4ef63d0824d36952f860f57e228ea", - "placeholder": "​", - "style": "IPY_MODEL_a637e3a3a7144f6db19eb3bbd812722f", - "value": "acc : 0.2993 loss : 0.1401: 91%" - } - }, - "77a9f488c18c4487ae107bee7362b643": { - "model_module": "@jupyter-widgets/controls", - "model_name": "FloatProgressModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatProgressModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "ProgressView", - "bar_style": "", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_8689e7f497fa4247b15f9929af81e68f", - "max": 500, - "min": 0, - "orientation": "horizontal", - "style": "IPY_MODEL_bbf5277f6016441baa5a21a8059944d9", - "value": 457 - } - }, - "b66fc8e0b5144229a69c5f2942ab796a": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_814ff8b72e0e4f20877c85ba4ced21e6", - "placeholder": "​", - "style": "IPY_MODEL_c63110ef853d411db16a41cb355324af", - "value": " 457/500 [08:19<00:42, 1.02it/s]" - } - }, - "bdda4512f2ec4290b29bf69d9b4808fe": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "2fb4ef63d0824d36952f860f57e228ea": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "a637e3a3a7144f6db19eb3bbd812722f": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "8689e7f497fa4247b15f9929af81e68f": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "bbf5277f6016441baa5a21a8059944d9": { - "model_module": "@jupyter-widgets/controls", - "model_name": "ProgressStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "ProgressStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "bar_color": null, - "description_width": "" - } - }, - "814ff8b72e0e4f20877c85ba4ced21e6": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "c63110ef853d411db16a41cb355324af": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - } - } - } - }, "cells": [ { "cell_type": "markdown", "metadata": { - "id": "view-in-github", - "colab_type": "text" + "colab_type": "text", + "id": "view-in-github" }, "source": [ - "\"Open" + "\"Open\n" ] }, { "cell_type": "markdown", + "metadata": { + "id": "BCG-8NlVLab8" + }, "source": [ "# 기본 설치\n", "\n", "아래 명령어를 통해 설치할 수 있습니다\n", + "\n", "```python\n", "!pip install pso2keras\n", "```\n", "\n", - "필수 패키지로 tensorflow 가 필요하며, log 분석시에는 tensorboard 가 추가로 필요합니다" - ], - "metadata": { - "id": "BCG-8NlVLab8" - } + "필수 패키지로 tensorflow 가 필요하며, log 분석시에는 tensorboard 가 추가로 필요합니다\n" + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Qd4s8Pu0nYGs" + }, + "outputs": [], "source": [ "import sys\n", "print('python version ', sys.version)\n", @@ -2110,23 +41,18 @@ "# !pip uninstall pso2keras\n", "!pip install --upgrade pip\n", "!pip install pso2keras" - ], - "metadata": { - "id": "Qd4s8Pu0nYGs" - }, - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "markdown", + "metadata": { + "id": "Bs6TLWxLMmEw" + }, "source": [ "# 모델 생성\n", "\n", - "keras 모델을 사용하여 학습하기 때문에 모델을 생성하여 입력을 해주어야 합니다." - ], - "metadata": { - "id": "Bs6TLWxLMmEw" - } + "keras 모델을 사용하여 학습하기 때문에 모델을 생성하여 입력을 해주어야 합니다.\n" + ] }, { "cell_type": "code", @@ -2203,52 +129,19 @@ }, { "cell_type": "markdown", + "metadata": { + "id": "JKVXZC5fNjEr" + }, "source": [ "# 학습\n", "\n", "학습을 위한 particle 개수와 기본 설정이 필요합니다\n", - "loss 는 tensorflow 의 loss 를 활용합니다" - ], - "metadata": { - "id": "JKVXZC5fNjEr" - } + "loss 는 tensorflow 의 loss 를 활용합니다\n" + ] }, { "cell_type": "code", - "source": [ - "model = make_model()\n", - "x_train, y_train = get_data_test()\n", - "\n", - "loss = 'mean_squared_error'\n", - "\n", - "pso_mnist = Optimizer(\n", - " model,\n", - " loss=loss,\n", - " n_particles=500,\n", - " c0=0.35,\n", - " c1=0.8,\n", - " w_min=0.6,\n", - " w_max=1.2,\n", - " negative_swarm=0.1,\n", - " mutation_swarm=0.2,\n", - " particle_min=-5,\n", - " particle_max=5,\n", - ")\n", - "\n", - "best_score = pso_mnist.fit(\n", - " x_train,\n", - " y_train,\n", - " epochs=200,\n", - " save_info=True,\n", - " log=2,\n", - " log_name=\"mnist\",\n", - " save_path=\"./result/mnist\",\n", - " renewal=\"acc\",\n", - " check_point=25,\n", - ")\n", - "\n", - "print(\"Done!\")" - ], + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -2325,11 +218,10 @@ "id": "wXmfci5UKNm4", "outputId": "c5bc9a2f-b949-4dac-e4d1-32942282cabf" }, - "execution_count": null, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz\n", "11490434/11490434 [==============================] - 0s 0us/step\n", @@ -2338,105 +230,2214 @@ ] }, { - "output_type": "display_data", "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "60384954600849c984ec832f1e0ba089", + "version_major": 2, + "version_minor": 0 + }, "text/plain": [ "Initializing Particles: 0%| | 0/500 [00:00 {self.particles_weights[_][0]}") - # self.particles_weights.append(particle_node) # print(f"particles_weights > {self.particles_weights}") # self.particles_weights = np.random.uniform(size=(n_particles, self.particle_depth)) \ - # * self.init_pos + # * self.init_pos # 입력받은 파티클의 개수 * 검색할 차원의 크기 만큼의 균등한 위치를 생성 # self.velocities = [None] * self.n_particles self.velocities = [ - [0 for i in range(self.particle_depth)] for n in range(n_particles)] + [0 for i in range(self.particle_depth)] for n in range(n_particles) + ] for i in tqdm(range(n_particles), desc="init velocities"): # print(i) for index, layer in enumerate(self.init_weights): # print(f"index > {index}") # print(f"layer > {layer.shape}") - self.velocities[i][index] = np.random.rand( - *layer.shape) / 5 - 0.10 + self.velocities[i][index] = np.random.rand(*layer.shape) / 5 - 0.10 # if layer.ndim == 1: # self.velocities[i][index] = np.random.uniform( # size=(layer.shape[0],)) @@ -72,11 +78,10 @@ class PSO(object): # size=(n_particles, self.particle_depth)) # 입력받은 파티클의 개수 * 검색할 차원의 크기 만큼의 속도를 무작위로 초기화 # 최대 사이즈로 전역 최적갑 저장 - global best - self.g_best = self.model.get_weights() # 전역 최적값(최적의 가중치) - self.p_best = self.particles_weights # 각 파티클의 최적값(최적의 가중치) - self.p_best_score = [0 for i in range( - n_particles)] # 각 파티클의 최적값의 점수 - self.g_best_score = 0 # 전역 최적값의 점수(초기화 - 무한대) + self.g_best = self.model.get_weights() # 전역 최적값(최적의 가중치) + self.p_best = self.particles_weights # 각 파티클의 최적값(최적의 가중치) + self.p_best_score = [0 for i in range(n_particles)] # 각 파티클의 최적값의 점수 + self.g_best_score = 0 # 전역 최적값의 점수(초기화 - 무한대) self.g_history = [] self.g_best_score_history = [] self.history = [] @@ -101,22 +106,22 @@ class PSO(object): # print(f"shape > w : {np.shape(w[i])}, v : {np.shape(v[i])}") new_weights[i] = tf.add(weights[i], v[i]) # new_w = tf.add(w, v) # 각 파티클을 랜덤한 속도만큼 진행 - return new_weights # 진행한 파티클들의 위치를 반환 + return new_weights # 진행한 파티클들의 위치를 반환 def _update_velocity(self, weights, v, p_best, c0=0.5, c1=1.5, w=0.75): """ - Update particle velocity + Update particle velocity - Args: - weights (array-like) : 파티클의 현재 가중치 - v (array-like) : 속도 - p_best(array-like) : 각 파티클의 최적의 위치 (최적의 가중치) - c0 (float) : 인지 스케일링 상수 (가중치의 중요도 - 지역) - 지역 관성 - c1 (float) : 사회 스케일링 상수 (가중치의 중요도 - 전역) - 전역 관성 - w (float) : 관성 상수 (현재 속도의 중요도) + Args: + weights (array-like) : 파티클의 현재 가중치 + v (array-like) : 속도 + p_best(array-like) : 각 파티클의 최적의 위치 (최적의 가중치) + c0 (float) : 인지 스케일링 상수 (가중치의 중요도 - 지역) - 지역 관성 + c1 (float) : 사회 스케일링 상수 (가중치의 중요도 - 전역) - 전역 관성 + w (float) : 관성 상수 (현재 속도의 중요도) - Returns: - (array-like) : 각 파티클의 새로운 속도 + Returns: + (array-like) : 각 파티클의 새로운 속도 """ # x = np.array(x) # v = np.array(v) @@ -140,9 +145,9 @@ class PSO(object): new_velocity = [None] * len(weights) for i, layer in enumerate(weights): - new_v = w*v[i] - new_v = new_v + c0*r0*(p_best[i] - layer) - new_v = new_v + c1*r1*(self.g_best[i] - layer) + new_v = w * v[i] + new_v = new_v + c0 * r0 * (p_best[i] - layer) + new_v = new_v + c1 * r1 * (self.g_best[i] - layer) new_velocity[i] = new_v # m2 = tf.multiply(tf.multiply(c0, r0), @@ -176,7 +181,19 @@ class PSO(object): return score - def optimize(self, x_train, y_train, x_test, y_test, maxiter=10, epochs=1, batch_size=32, c0=0.5, c1=1.5, w=0.75): + def optimize( + self, + x_train, + y_train, + x_test, + y_test, + maxiter=10, + epochs=1, + batch_size=32, + c0=0.5, + c1=1.5, + w=0.75, + ): """ Run the PSO optimization process utill the stoping critera is met. Cas for minization. The aim is to minimize the cost function @@ -190,13 +207,18 @@ class PSO(object): for _ in range(maxiter): loss = 0 acc = 1e-10 - for i in tqdm(range(self.n_particles), desc=f"Iter {_}/{maxiter} | acc avg {round(acc/(_+1) ,4)}", ascii=True): + for i in tqdm( + range(self.n_particles), + desc=f"Iter {_}/{maxiter} | acc avg {round(acc/(_+1) ,4)}", + ascii=True, + ): weights = self.particles_weights[i] # 각 파티클 추출 - v = self.velocities[i] # 각 파티클의 다음 속도 추출 - p_best = self.p_best[i] # 결과치 저장할 변수 지정 + v = self.velocities[i] # 각 파티클의 다음 속도 추출 + p_best = self.p_best[i] # 결과치 저장할 변수 지정 # 2. 속도 계산 self.velocities[i] = self._update_velocity( - weights, v, p_best, c0, c1, w) + weights, v, p_best, c0, c1, w + ) # 다음에 움직일 속도 = 최초 위치, 현재 속도, 현재 위치, 최종 위치 # 3. 위치 업데이트 self.particles_weights[i] = self._update_weights(weights, v) @@ -204,12 +226,19 @@ class PSO(object): # Update the besst position for particle i # 내 현재 위치가 내 위치의 최소치보다 작으면 갱신 self.model.set_weights(self.particles_weights[i].copy()) - self.model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size, - verbose=0, validation_data=(x_test, y_test)) + self.model.fit( + x_train, + y_train, + epochs=epochs, + batch_size=batch_size, + verbose=0, + validation_data=(x_test, y_test), + ) self.particles_weights[i] = self.model.get_weights() # 4. 평가 - self.model.compile(loss=self.loss_method, - optimizer='adam', metrics=['accuracy']) + self.model.compile( + loss=self.loss_method, optimizer="adam", metrics=["accuracy"] + ) score = self._get_score(x_test, y_test) # print(score) @@ -224,8 +253,7 @@ class PSO(object): self.g_best_score = score[1] self.g_best = self.particles_weights[i].copy() self.g_history.append(self.g_best) - self.g_best_score_history.append( - self.g_best_score) + self.g_best_score_history.append(self.g_best_score) self.score = score[1] loss = loss + score[0] @@ -240,7 +268,8 @@ class PSO(object): # self.g_history.append(self.g_best) # print(f"{i} particle score : {score[0]}") print( - f"loss avg : {loss/self.n_particles} | acc avg : {acc/self.n_particles} | best loss : {self.g_best_score}") + f"loss avg : {loss/self.n_particles} | acc avg : {acc/self.n_particles} | best loss : {self.g_best_score}" + ) # self.history.append(self.particles_weights.copy()) diff --git a/metacode/pso_meta.py b/metacode/pso_meta.py index 2cfdfe8..b38f623 100644 --- a/metacode/pso_meta.py +++ b/metacode/pso_meta.py @@ -1,5 +1,6 @@ import numpy as np + class PSO(object): """ Class implementing PSO algorithm @@ -16,16 +17,16 @@ class PSO(object): """ self.func = func self.n_particles = n_particles - self.init_pos = init_pos # 검색할 차원 + self.init_pos = init_pos # 검색할 차원 self.particle_dim = len(init_pos) # 검색할 차원의 크기 - self.particles_pos = np.random.uniform(size=(n_particles, self.particle_dim)) \ - * self.init_pos + self.particles_pos = ( + np.random.uniform(size=(n_particles, self.particle_dim)) * self.init_pos + ) # 입력받은 파티클의 개수 * 검색할 차원의 크기 만큼의 균등한 위치를 생성 - self.velocities = np.random.uniform( - size=(n_particles, self.particle_dim)) + self.velocities = np.random.uniform(size=(n_particles, self.particle_dim)) # 입력받은 파티클의 개수 * 검색할 차원의 크기 만큼의 속도를 무작위로 초기화 - self.g_best = init_pos # 최대 사이즈로 전역 최적갑 저장 - global best - self.p_best = self.particles_pos # 모든 파티클의 위치 - particles best + self.g_best = init_pos # 최대 사이즈로 전역 최적갑 저장 - global best + self.p_best = self.particles_pos # 모든 파티클의 위치 - particles best self.g_history = [] self.history = [] @@ -42,24 +43,24 @@ class PSO(object): """ x = np.array(x) # 각 파티클의 위치 v = np.array(v) # 각 파티클의 속도(방향과 속력을 가짐) - new_x = x + v # 각 파티클을 랜덤한 속도만큼 진행 - return new_x # 진행한 파티클들의 위치를 반환 + new_x = x + v # 각 파티클을 랜덤한 속도만큼 진행 + return new_x # 진행한 파티클들의 위치를 반환 def update_velocity(self, x, v, p_best, g_best, c0=0.5, c1=1.5, w=0.75): """ - Update particle velocity + Update particle velocity - Args: - x(array-like): particle current position - v (array-like): particle current velocity - p_best(array-like): the best position found so far for a particle - g_best(array-like): the best position regarding all the particles found so far - c0 (float): the congnitive scaling constant, 인지 스케일링 상수 - c1 (float): the social scaling constant - w (float): the inertia weight, 관성 중량 + Args: + x(array-like): particle current position + v (array-like): particle current velocity + p_best(array-like): the best position found so far for a particle + g_best(array-like): the best position regarding all the particles found so far + c0 (float): the congnitive scaling constant, 인지 스케일링 상수 + c1 (float): the social scaling constant + w (float): the inertia weight, 관성 중량 - Returns: - The updated velocity (array-like). + Returns: + The updated velocity (array-like). """ x = np.array(x) v = np.array(v) @@ -73,7 +74,7 @@ class PSO(object): # 가중치(상수)*속도 + \ # 스케일링 상수*랜덤 가중치*(나의 최적값 - 처음 위치) + \ # 전역 스케일링 상수*랜덤 가중치*(전체 최적값 - 처음 위치) - new_v = w*v + c0*r*(p_best - x) + c1*r*(g_best - x) + new_v = w * v + c0 * r * (p_best - x) + c1 * r * (g_best - x) return new_v def optimize(self, maxiter=200): @@ -90,10 +91,9 @@ class PSO(object): for _ in range(maxiter): for i in range(self.n_particles): x = self.particles_pos[i] # 각 파티클 추출 - v = self.velocities[i] # 랜덤 생성한 속도 추출 - p_best = self.p_best[i] # 결과치 저장할 변수 지정 - self.velocities[i] = self.update_velocity( - x, v, p_best, self.g_best) + v = self.velocities[i] # 랜덤 생성한 속도 추출 + p_best = self.p_best[i] # 결과치 저장할 변수 지정 + self.velocities[i] = self.update_velocity(x, v, p_best, self.g_best) # 다음에 움직일 속도 = 최초 위치, 현재 속도, 현재 위치, 최종 위치 self.particles_pos[i] = self.update_position(x, v) # 현재 위치 = 최초 위치 현재 속도 @@ -106,7 +106,7 @@ class PSO(object): if self.func(self.particles_pos[i]) < self.func(self.g_best): self.g_best = self.particles_pos[i] self.g_history.append(self.g_best) - + self.history.append(self.particles_pos.copy()) # 전체 최소 위치, 전체 최소 벡터 diff --git a/metacode/pso_tf.py b/metacode/pso_tf.py index c7f2bfa..3e52f11 100644 --- a/metacode/pso_tf.py +++ b/metacode/pso_tf.py @@ -12,13 +12,17 @@ import gc import cupy as cp - class PSO(object): """ Class implementing PSO algorithm """ - def __init__(self, model: keras.models, loss_method=keras.losses.MeanSquaredError(), n_particles: int = 5): + def __init__( + self, + model: keras.models, + loss_method=keras.losses.MeanSquaredError(), + n_particles: int = 5, + ): """ Initialize the key variables. @@ -27,44 +31,45 @@ class PSO(object): loss_method : 손실 함수 n_particles(int) : 파티클의 개수 """ - self.model = model # 모델 - self.n_particles = n_particles # 파티클의 개수 - self.loss_method = loss_method # 손실 함수 - model_structure = self.model.to_json() # 모델의 구조 정보 - self.init_weights = self.model.get_weights() # 검색할 차원 - self.particle_depth = len(self.model.get_weights()) # 검색할 차원의 깊이 - self.particles_weights = [None] * n_particles # 파티클의 위치 + self.model = model # 모델 + self.n_particles = n_particles # 파티클의 개수 + self.loss_method = loss_method # 손실 함수 + model_structure = self.model.to_json() # 모델의 구조 정보 + self.init_weights = self.model.get_weights() # 검색할 차원 + self.particle_depth = len(self.model.get_weights()) # 검색할 차원의 깊이 + self.particles_weights = [None] * n_particles # 파티클의 위치 for _ in tqdm(range(self.n_particles), desc="init particles position"): m = keras.models.model_from_json(model_structure) - m.compile(loss=self.loss_method, - optimizer="adam", metrics=["accuracy"]) - self.particles_weights[_] = m.get_weights() + m.compile(loss=self.loss_method, optimizer="adam", metrics=["accuracy"]) + self.particles_weights[_] = m.get_weights() # 입력받은 파티클의 개수 * 검색할 차원의 크기 만큼의 균등한 위치를 생성 self.velocities = [ - [0 for i in range(self.particle_depth)] for n in range(n_particles)] + [0 for i in range(self.particle_depth)] for n in range(n_particles) + ] for i in tqdm(range(n_particles), desc="init velocities"): - + self.init_weights = self.model.get_weights() - w_,s_,l_ = self._encode(self.init_weights) + w_, s_, l_ = self._encode(self.init_weights) w_ = np.random.rand(len(w_)) / 5 - 0.10 - self.velocities[i] = self._decode(w_,s_,l_) + self.velocities[i] = self._decode(w_, s_, l_) # for index, layer in enumerate(self.init_weights): # self.velocities[i][index] = np.random.rand( # *layer.shape) / 5 - 0.10 - # 입력받은 파티클의 개수 * 검색할 차원의 크기 만큼의 속도를 무작위로 초기화 # 최대 사이즈로 전역 최적갑 저장 - global best - self.p_best = self.particles_weights # 각 파티클의 최적값(최적의 가중치) - self.g_best=self.model.get_weights() # 전역 최적값(최적의 가중치) | 초기값은 모델의 가중치 + self.p_best = self.particles_weights # 각 파티클의 최적값(최적의 가중치) + self.g_best = ( + self.model.get_weights() + ) # 전역 최적값(최적의 가중치) | 초기값은 모델의 가중치 # 각 파티클의 최적값의 점수 self.p_best_score = [0 for i in range(n_particles)] # 전역 최적값의 점수(초기화 - 0) self.g_best_score = 0 - + def __del__(self): del self.model del self.n_particles @@ -77,7 +82,7 @@ class PSO(object): del self.p_best_score del self.g_best_score - def _encode(self,weights: list): + def _encode(self, weights: list): # w_gpu = cp.array([]) w_gpu = np.array([]) lenght = [] @@ -88,10 +93,10 @@ class PSO(object): lenght.append(len(w_)) w_gpu = np.append(w_gpu, w_) # w_gpu = cp.append(w_gpu, w_) - + return w_gpu, shape, lenght - def _decode(self,weight, shape, lenght): + def _decode(self, weight, shape, lenght): weights = [] start = 0 for i in range(len(shape)): @@ -105,7 +110,7 @@ class PSO(object): start = end return weights - + def _update_weights(self, weights, v): """ Update particle position @@ -121,30 +126,30 @@ class PSO(object): # v = np.array(v) # 각 파티클의 속도(방향과 속력을 가짐) # new_weights = [0 for i in range(len(weights))] # print(f"weights : {weights}") - encode_w, w_sh, w_len = self._encode(weights = weights) - encode_v, _, _ = self._encode(weights = v) + encode_w, w_sh, w_len = self._encode(weights=weights) + encode_v, _, _ = self._encode(weights=v) new_w = encode_w + encode_v new_weights = self._decode(new_w, w_sh, w_len) - + # for i in range(len(weights)): - # new_weights[i] = tf.add(weights[i], v[i]) + # new_weights[i] = tf.add(weights[i], v[i]) # new_w = tf.add(w, v) # 각 파티클을 랜덤한 속도만큼 진행 - return new_weights # 진행한 파티클들의 위치를 반환 + return new_weights # 진행한 파티클들의 위치를 반환 def _update_velocity(self, weights, v, p_best, c0=0.5, c1=1.5, w=0.75): """ - Update particle velocity + Update particle velocity - Args: - weights (array-like) : 파티클의 현재 가중치 - v (array-like) : 속도 - p_best(array-like) : 각 파티클의 최적의 위치 (최적의 가중치) - c0 (float) : 인지 스케일링 상수 (가중치의 중요도 - 지역) - 지역 관성 - c1 (float) : 사회 스케일링 상수 (가중치의 중요도 - 전역) - 전역 관성 - w (float) : 관성 상수 (현재 속도의 중요도) + Args: + weights (array-like) : 파티클의 현재 가중치 + v (array-like) : 속도 + p_best(array-like) : 각 파티클의 최적의 위치 (최적의 가중치) + c0 (float) : 인지 스케일링 상수 (가중치의 중요도 - 지역) - 지역 관성 + c1 (float) : 사회 스케일링 상수 (가중치의 중요도 - 전역) - 전역 관성 + w (float) : 관성 상수 (현재 속도의 중요도) - Returns: - (array-like) : 각 파티클의 새로운 속도 + Returns: + (array-like) : 각 파티클의 새로운 속도 """ # x = np.array(x) # v = np.array(v) @@ -159,21 +164,25 @@ class PSO(object): # 가중치(상수)*속도 + \ # 스케일링 상수*랜덤 가중치*(나의 최적값 - 처음 위치) + \ # 전역 스케일링 상수*랜덤 가중치*(전체 최적값 - 처음 위치) - - encode_w, w_sh, w_len = self._encode(weights = weights) - encode_v, _, _ = self._encode(weights = v) - encode_p, _, _ = self._encode(weights = p_best) - encode_g, _, _ = self._encode(weights = self.g_best) - - new_v = encode_w * encode_v + c0*r0*(encode_p - encode_w) + c1*r1*(encode_g - encode_w) + + encode_w, w_sh, w_len = self._encode(weights=weights) + encode_v, _, _ = self._encode(weights=v) + encode_p, _, _ = self._encode(weights=p_best) + encode_g, _, _ = self._encode(weights=self.g_best) + + new_v = ( + encode_w * encode_v + + c0 * r0 * (encode_p - encode_w) + + c1 * r1 * (encode_g - encode_w) + ) new_velocity = self._decode(new_v, w_sh, w_len) # new_velocity = [None] * len(weights) # for i, layer in enumerate(weights): - # new_v = w*v[i] - # new_v = new_v + c0*r0*(p_best[i] - layer) - # new_v = new_v + c1*r1*(self.g_best[i] - layer) - # new_velocity[i] = new_v + # new_v = w*v[i] + # new_v = new_v + c0*r0*(p_best[i] - layer) + # new_v = new_v + c1*r1*(self.g_best[i] - layer) + # new_velocity[i] = new_v # new_v = w*v + c0*r0*(p_best - weights) + c1*r1*(g_best - weights) return new_velocity @@ -192,7 +201,17 @@ class PSO(object): return score - def optimize(self, x_, y_, maxiter=10, c0=0.5, c1=1.5, w=0.75, save=False, save_path="./result/history"): + def optimize( + self, + x_, + y_, + maxiter=10, + c0=0.5, + c1=1.5, + w=0.75, + save=False, + save_path="./result/history", + ): """ Run the PSO optimization process utill the stoping critera is met. Cas for minization. The aim is to minimize the cost function @@ -205,17 +224,20 @@ class PSO(object): """ if save: os.makedirs(save_path, exist_ok=True) - day = datetime.datetime.now().strftime('%m-%d-%H-%M') - + day = datetime.datetime.now().strftime("%m-%d-%H-%M") + for _ in range(maxiter): - for i in tqdm(range(self.n_particles), desc=f"Iter {_}/{maxiter} ", ascii=True): + for i in tqdm( + range(self.n_particles), desc=f"Iter {_}/{maxiter} ", ascii=True + ): weights = self.particles_weights[i] # 각 파티클 추출 - v = self.velocities[i] # 각 파티클의 다음 속도 추출 - p_best = self.p_best[i] # 결과치 저장할 변수 지정 + v = self.velocities[i] # 각 파티클의 다음 속도 추출 + p_best = self.p_best[i] # 결과치 저장할 변수 지정 # 2. 속도 계산 self.velocities[i] = self._update_velocity( - weights, v, p_best, c0, c1, w) + weights, v, p_best, c0, c1, w + ) # 다음에 움직일 속도 = 최초 위치, 현재 속도, 현재 위치, 최종 위치 # 3. 위치 업데이트 self.particles_weights[i] = self._update_weights(weights, v) @@ -224,8 +246,9 @@ class PSO(object): self.model.set_weights(self.particles_weights[i]) # self.particles_weights[i] = self.model.get_weights() # 4. 평가 - self.model.compile(loss=self.loss_method, - optimizer='sgd', metrics=['accuracy']) + self.model.compile( + loss=self.loss_method, optimizer="sgd", metrics=["accuracy"] + ) score = self._get_score(x_, y_) if score[1] > self.p_best_score[i]: @@ -234,18 +257,25 @@ class PSO(object): if score[1] > self.g_best_score: self.g_best_score = score[1] self.g_best = self.particles_weights[i] - + if save: - with open(f"{save_path}/{day}_{self.n_particles}_{maxiter}_{c0}_{c1}_{w}.csv",'a')as f: + with open( + f"{save_path}/{day}_{self.n_particles}_{maxiter}_{c0}_{c1}_{w}.csv", + "a", + ) as f: f.write(f"{score[0]}, {score[1]}") if i != self.n_particles - 1: f.write(",") - - if save: - with open(f"{save_path}/{day}_{self.n_particles}_{maxiter}_{c0}_{c1}_{w}.csv",'a')as f: + + if save: + with open( + f"{save_path}/{day}_{self.n_particles}_{maxiter}_{c0}_{c1}_{w}.csv", + "a", + ) as f: f.write("\n") print( - f"loss avg : {score[0]/self.n_particles} | acc avg : {score[1]/self.n_particles} | best score : {self.g_best_score}") + f"loss avg : {score[0]/self.n_particles} | acc avg : {score[1]/self.n_particles} | best score : {self.g_best_score}" + ) gc.collect() # 전체 최소 위치, 전체 최소 벡터 @@ -265,4 +295,4 @@ class PSO(object): """ def best_score(self): - return self.g_best_score \ No newline at end of file + return self.g_best_score diff --git a/metacode/pso_tf_bak.py b/metacode/pso_tf_bak.py index 5dafc83..f625b33 100644 --- a/metacode/pso_tf_bak.py +++ b/metacode/pso_tf_bak.py @@ -12,7 +12,12 @@ class PSO(object): Class implementing PSO algorithm """ - def __init__(self, model: keras.models, loss_method=keras.losses.MeanSquaredError(), n_particles: int = 5): + def __init__( + self, + model: keras.models, + loss_method=keras.losses.MeanSquaredError(), + n_particles: int = 5, + ): """ Initialize the key variables. @@ -21,40 +26,41 @@ class PSO(object): loss_method : 손실 함수 n_particles(int) : 파티클의 개수 """ - self.model = model # 모델 - self.n_particles = n_particles # 파티클의 개수 - self.loss_method = loss_method # 손실 함수 - self.model_structure = self.model.to_json() # 모델의 구조 정보 - self.init_weights = self.model.get_weights() # 검색할 차원 - self.particle_depth = len(self.model.get_weights()) # 검색할 차원의 깊이 - self.particles_weights = [None] * n_particles # 파티클의 위치 + self.model = model # 모델 + self.n_particles = n_particles # 파티클의 개수 + self.loss_method = loss_method # 손실 함수 + self.model_structure = self.model.to_json() # 모델의 구조 정보 + self.init_weights = self.model.get_weights() # 검색할 차원 + self.particle_depth = len(self.model.get_weights()) # 검색할 차원의 깊이 + self.particles_weights = [None] * n_particles # 파티클의 위치 for _ in tqdm(range(self.n_particles), desc="init particles position"): m = keras.models.model_from_json(self.model_structure) - m.compile(loss=self.loss_method, - optimizer="adam", metrics=["accuracy"]) + m.compile(loss=self.loss_method, optimizer="adam", metrics=["accuracy"]) self.particles_weights[_] = m.get_weights() # 입력받은 파티클의 개수 * 검색할 차원의 크기 만큼의 균등한 위치를 생성 self.velocities = [ - [0 for i in range(self.particle_depth)] for n in range(n_particles)] + [0 for i in range(self.particle_depth)] for n in range(n_particles) + ] for i in tqdm(range(n_particles), desc="init velocities"): for index, layer in enumerate(self.init_weights): - self.velocities[i][index] = np.random.rand( - *layer.shape) / 5 - 0.10 + self.velocities[i][index] = np.random.rand(*layer.shape) / 5 - 0.10 # 입력받은 파티클의 개수 * 검색할 차원의 크기 만큼의 속도를 무작위로 초기화 # 최대 사이즈로 전역 최적갑 저장 - global best - self.p_best = self.particles_weights # 각 파티클의 최적값(최적의 가중치) - self.g_best = self.model.get_weights() # 전역 최적값(최적의 가중치) | 초기값은 모델의 가중치 + self.p_best = self.particles_weights # 각 파티클의 최적값(최적의 가중치) + self.g_best = ( + self.model.get_weights() + ) # 전역 최적값(최적의 가중치) | 초기값은 모델의 가중치 # 각 파티클의 최적값의 점수 self.p_best_score = [0 for i in range(n_particles)] # 전역 최적값의 점수(초기화 - 0) self.g_best_score = 0 - self.loss_history = [[] for i in range(n_particles)] # 각 파티클의 손실값 변화 - self.acc_history = [[] for i in range(n_particles)] # 각 파티클의 정확도 변화 - self.g_best_score_history = [] # 전역 최적값의 점수 변화 + self.loss_history = [[] for i in range(n_particles)] # 각 파티클의 손실값 변화 + self.acc_history = [[] for i in range(n_particles)] # 각 파티클의 정확도 변화 + self.g_best_score_history = [] # 전역 최적값의 점수 변화 def _update_weights(self, weights, v): """ @@ -73,22 +79,22 @@ class PSO(object): for i in range(len(weights)): new_weights[i] = tf.add(weights[i], v[i]) # new_w = tf.add(w, v) # 각 파티클을 랜덤한 속도만큼 진행 - return new_weights # 진행한 파티클들의 위치를 반환 + return new_weights # 진행한 파티클들의 위치를 반환 def _update_velocity(self, weights, v, p_best, c0=0.5, c1=1.5, w=0.75): """ - Update particle velocity + Update particle velocity - Args: - weights (array-like) : 파티클의 현재 가중치 - v (array-like) : 속도 - p_best(array-like) : 각 파티클의 최적의 위치 (최적의 가중치) - c0 (float) : 인지 스케일링 상수 (가중치의 중요도 - 지역) - 지역 관성 - c1 (float) : 사회 스케일링 상수 (가중치의 중요도 - 전역) - 전역 관성 - w (float) : 관성 상수 (현재 속도의 중요도) + Args: + weights (array-like) : 파티클의 현재 가중치 + v (array-like) : 속도 + p_best(array-like) : 각 파티클의 최적의 위치 (최적의 가중치) + c0 (float) : 인지 스케일링 상수 (가중치의 중요도 - 지역) - 지역 관성 + c1 (float) : 사회 스케일링 상수 (가중치의 중요도 - 전역) - 전역 관성 + w (float) : 관성 상수 (현재 속도의 중요도) - Returns: - (array-like) : 각 파티클의 새로운 속도 + Returns: + (array-like) : 각 파티클의 새로운 속도 """ # x = np.array(x) # v = np.array(v) @@ -106,9 +112,9 @@ class PSO(object): new_velocity = [None] * len(weights) for i, layer in enumerate(weights): - new_v = w*v[i] - new_v = new_v + c0*r0*(p_best[i] - layer) - new_v = new_v + c1*r1*(self.g_best[i] - layer) + new_v = w * v[i] + new_v = new_v + c0 * r0 * (p_best[i] - layer) + new_v = new_v + c1 * r1 * (self.g_best[i] - layer) new_velocity[i] = new_v # new_v = w*v + c0*r0*(p_best - weights) + c1*r1*(g_best - weights) @@ -141,13 +147,16 @@ class PSO(object): """ for _ in range(maxiter): - for i in tqdm(range(self.n_particles), desc=f"Iter {_}/{maxiter} ", ascii=True): + for i in tqdm( + range(self.n_particles), desc=f"Iter {_}/{maxiter} ", ascii=True + ): weights = self.particles_weights[i] # 각 파티클 추출 - v = self.velocities[i] # 각 파티클의 다음 속도 추출 - p_best = self.p_best[i] # 결과치 저장할 변수 지정 + v = self.velocities[i] # 각 파티클의 다음 속도 추출 + p_best = self.p_best[i] # 결과치 저장할 변수 지정 # 2. 속도 계산 self.velocities[i] = self._update_velocity( - weights, v, p_best, c0, c1, w) + weights, v, p_best, c0, c1, w + ) # 다음에 움직일 속도 = 최초 위치, 현재 속도, 현재 위치, 최종 위치 # 3. 위치 업데이트 self.particles_weights[i] = self._update_weights(weights, v) @@ -156,8 +165,9 @@ class PSO(object): self.model.set_weights(self.particles_weights[i].copy()) # self.particles_weights[i] = self.model.get_weights() # 4. 평가 - self.model.compile(loss=self.loss_method, - optimizer='adam', metrics=['accuracy']) + self.model.compile( + loss=self.loss_method, optimizer="adam", metrics=["accuracy"] + ) score = self._get_score(x_, y_) if score[1] > self.p_best_score[i]: @@ -166,14 +176,14 @@ class PSO(object): if score[1] > self.g_best_score: self.g_best_score = score[1] self.g_best = self.particles_weights[i].copy() - self.g_best_score_history.append( - self.g_best_score) + self.g_best_score_history.append(self.g_best_score) self.loss_history[i].append(score[0]) self.acc_history[i].append(score[1]) print( - f"loss avg : {score[0]/self.n_particles} | acc avg : {score[1]/self.n_particles} | best score : {self.g_best_score}") + f"loss avg : {score[0]/self.n_particles} | acc avg : {score[1]/self.n_particles} | best score : {self.g_best_score}" + ) # 전체 최소 위치, 전체 최소 벡터 return self.g_best, self._get_score(x_, y_) @@ -193,6 +203,7 @@ class PSO(object): def best_score(self): return self.g_best_score + """ Returns: global best score 의 갱신된 값의 변화를 반환 diff --git a/pso/optimizer.py b/pso/optimizer.py index ac912bf..0f3d7c8 100644 --- a/pso/optimizer.py +++ b/pso/optimizer.py @@ -83,30 +83,30 @@ class Optimizer: try: if model is None: raise ValueError("model is None") - if model is not None and not isinstance(model, keras.models.Model): + elif model is not None and not isinstance(model, keras.models.Model): raise ValueError("model is not keras.models.Model") - if loss is None: + elif loss is None: raise ValueError("loss is None") - if n_particles is None: + elif n_particles is None: raise ValueError("n_particles is None") - if n_particles < 1: + elif n_particles < 1: raise ValueError("n_particles < 1") - if c0 < 0 or c1 < 0: + elif c0 < 0 or c1 < 0: raise ValueError("c0 or c1 < 0") - if np_seed is not None: + elif np_seed is not None: np.random.seed(np_seed) - if tf_seed is not None: + elif tf_seed is not None: tf.random.set_seed(tf_seed) - self.random_state = np.random.get_state() - - if random_state is not None: + elif random_state is not None: np.random.set_state(random_state) + self.random_state = np.random.get_state() + model.compile(loss=loss, optimizer="adam", metrics=["accuracy", "mse"]) self.model = model # 모델 구조 self.loss = loss # 손실함수 @@ -116,8 +116,12 @@ class Optimizer: self.c1 = c1 # global rate - 전역 최적값 관성 수치 self.w_min = w_min # 최소 관성 수치 self.w_max = w_max # 최대 관성 수치 - self.negative_swarm = negative_swarm # 최적해와 반대로 이동할 파티클 비율 - 0 ~ 1 사이의 값 - self.mutation_swarm = mutation_swarm # 관성을 추가로 사용할 파티클 비율 - 0 ~ 1 사이의 값 + self.negative_swarm = ( + negative_swarm # 최적해와 반대로 이동할 파티클 비율 - 0 ~ 1 사이의 값 + ) + self.mutation_swarm = ( + mutation_swarm # 관성을 추가로 사용할 파티클 비율 - 0 ~ 1 사이의 값 + ) self.avg_score = 0 # 평균 점수 # self.sigma = 1.0 @@ -136,9 +140,9 @@ class Optimizer: self.particles[i] = Particle( model, self.loss, - negative=True - if i < self.negative_swarm * self.n_particles - else False, + negative=( + True if i < self.negative_swarm * self.n_particles else False + ), mutation=self.mutation_swarm, converge_reset=convergence_reset, converge_reset_patience=convergence_reset_patience,