decc


Namedecc JSON
Version 0.2.2 PyPI version JSON
download
home_page
SummaryCooperative Co-evolutionary Differential Evolution algorithms in Python.
upload_time2023-09-17 23:31:01
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords decc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # decc: Cooperative Co-evolutionary Differential Evolution

Cooperative Co-evolutionary Differential Evolution algorithms in Python with NumPy. 

This repository provides simple implementations for some CC-based DE algorithms. All the implementations are from scratch using NumPy, they might slightly differ from the original papers.

# Quick Start

The `decc` library works with two entities:

- `Problem` represents a minimization problem (objective function, dimensionality and bounds).
  - The objective function must receives a matrix as input (each row represents a solution) and produce a matrix as output (each row is the objective value for the respective solution).
- `Optimizer` represents a DE algorithm for solving a minimization problem.
  - Maximization of a real function `g` is equivalent to minimize `-g`.

In order to use an optimizer, you must first define a problem. Currently, there are two optimizer available: (i) [**DECC**](src/decc/optimizers/decc.py) (also known as CCDE), with the variants **DECC-O** and **DECC-H**; and (ii) [**DECC-G**](src/decc/optimizers/decc_g.py). A basic example is found below:

```python
import numpy as np

from decc import Problem
from decc.optimizers.decc import DECCOptimizer
from decc.optimizers.decc_g import DECCGOptimizer

def objective(x: np.ndarray) -> np.ndarray:
    # The Sphere function is a common
    #   benchmark for optimizers
    return np.sum(x ** 2, axis=-1)


# First, we must define the problem
problem = Problem(objective,
                  dims=100,
                  lower_bound=-100.0,
                  upper_bound=100.0)

# Then, we can instantiate the optimizers
F = 0.5
CR = 0.8
seed = 42
max_fn = int(1e5)
pop_size = 50
decc_h = DECCOptimizer(problem,
                       seed,
                       pop_size,
                       grouping='halve',
                       F=F,
                       CR=CR,
                       max_fn=max_fn)
decc_o = DECCOptimizer(problem,
                       seed,
                       pop_size,
                       grouping='dims',
                       F=F,
                       CR=CR,
                       max_fn=max_fn)
decc_g = DECCGOptimizer(problem,
                        seed,
                        pop_size,
                        n_subproblems=max(1, problem.dims // 4),
                        sansde_evaluations=max_fn // 3,
                        de_evaluations=max_fn // 5,
                        F=F,
                        CR=CR,
                        max_fn=max_fn)

# Lastly, we can optimize the objective and
#   retrieve the results.
for optimizer in [decc_o, decc_h, decc_g]:
    result = optimizer.optimize()
    print(f'{optimizer}: {result["best_fitness"]}')

# DECC-O: 1.638248431845568e-05
# DECC-H: 0.0006988301174715161
# DECC-G: 1.5340782547163752e-10
```

# Roadmap

- Add support for `DECC-DG`;
- Add support for `DECC-gDG`;
- Improve documentation;
- Add unit tests;
- Add validation benchmark functions from the original papers;

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "decc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "decc",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/ef/1a/145f9b0bc3b159ba41e3256e13e0d0ea44e5778b129396f6b9b5383efd61/decc-0.2.2.tar.gz",
    "platform": null,
    "description": "# decc: Cooperative Co-evolutionary Differential Evolution\n\nCooperative Co-evolutionary Differential Evolution algorithms in Python with NumPy. \n\nThis repository provides simple implementations for some CC-based DE algorithms. All the implementations are from scratch using NumPy, they might slightly differ from the original papers.\n\n# Quick Start\n\nThe `decc` library works with two entities:\n\n- `Problem` represents a minimization problem (objective function, dimensionality and bounds).\n  - The objective function must receives a matrix as input (each row represents a solution) and produce a matrix as output (each row is the objective value for the respective solution).\n- `Optimizer` represents a DE algorithm for solving a minimization problem.\n  - Maximization of a real function `g` is equivalent to minimize `-g`.\n\nIn order to use an optimizer, you must first define a problem. Currently, there are two optimizer available: (i) [**DECC**](src/decc/optimizers/decc.py) (also known as CCDE), with the variants **DECC-O** and **DECC-H**; and (ii) [**DECC-G**](src/decc/optimizers/decc_g.py). A basic example is found below:\n\n```python\nimport numpy as np\n\nfrom decc import Problem\nfrom decc.optimizers.decc import DECCOptimizer\nfrom decc.optimizers.decc_g import DECCGOptimizer\n\ndef objective(x: np.ndarray) -> np.ndarray:\n    # The Sphere function is a common\n    #   benchmark for optimizers\n    return np.sum(x ** 2, axis=-1)\n\n\n# First, we must define the problem\nproblem = Problem(objective,\n                  dims=100,\n                  lower_bound=-100.0,\n                  upper_bound=100.0)\n\n# Then, we can instantiate the optimizers\nF = 0.5\nCR = 0.8\nseed = 42\nmax_fn = int(1e5)\npop_size = 50\ndecc_h = DECCOptimizer(problem,\n                       seed,\n                       pop_size,\n                       grouping='halve',\n                       F=F,\n                       CR=CR,\n                       max_fn=max_fn)\ndecc_o = DECCOptimizer(problem,\n                       seed,\n                       pop_size,\n                       grouping='dims',\n                       F=F,\n                       CR=CR,\n                       max_fn=max_fn)\ndecc_g = DECCGOptimizer(problem,\n                        seed,\n                        pop_size,\n                        n_subproblems=max(1, problem.dims // 4),\n                        sansde_evaluations=max_fn // 3,\n                        de_evaluations=max_fn // 5,\n                        F=F,\n                        CR=CR,\n                        max_fn=max_fn)\n\n# Lastly, we can optimize the objective and\n#   retrieve the results.\nfor optimizer in [decc_o, decc_h, decc_g]:\n    result = optimizer.optimize()\n    print(f'{optimizer}: {result[\"best_fitness\"]}')\n\n# DECC-O: 1.638248431845568e-05\n# DECC-H: 0.0006988301174715161\n# DECC-G: 1.5340782547163752e-10\n```\n\n# Roadmap\n\n- Add support for `DECC-DG`;\n- Add support for `DECC-gDG`;\n- Improve documentation;\n- Add unit tests;\n- Add validation benchmark functions from the original papers;\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Cooperative Co-evolutionary Differential Evolution algorithms in Python.",
    "version": "0.2.2",
    "project_urls": {
        "Github": "https://github.com/moesio-f/decc"
    },
    "split_keywords": [
        "decc"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "875cd642d4e9fe1f5720be4183f2410fa90e05559861fbfc0c5114b6a42bbf45",
                "md5": "968d96b4ac15f037029204308d85e1d6",
                "sha256": "72440d463195db81ec1ae28280684663df88ef55cf245d46f025164dbe8806e8"
            },
            "downloads": -1,
            "filename": "decc-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "968d96b4ac15f037029204308d85e1d6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19308,
            "upload_time": "2023-09-17T23:30:59",
            "upload_time_iso_8601": "2023-09-17T23:30:59.248091Z",
            "url": "https://files.pythonhosted.org/packages/87/5c/d642d4e9fe1f5720be4183f2410fa90e05559861fbfc0c5114b6a42bbf45/decc-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ef1a145f9b0bc3b159ba41e3256e13e0d0ea44e5778b129396f6b9b5383efd61",
                "md5": "6f373b397df353e0dee33870a00351a4",
                "sha256": "71907be25c7f213d831ad4cb7d08d50ff57e273d636b9d2b2656b1f9eec1679e"
            },
            "downloads": -1,
            "filename": "decc-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "6f373b397df353e0dee33870a00351a4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 14243,
            "upload_time": "2023-09-17T23:31:01",
            "upload_time_iso_8601": "2023-09-17T23:31:01.145997Z",
            "url": "https://files.pythonhosted.org/packages/ef/1a/145f9b0bc3b159ba41e3256e13e0d0ea44e5778b129396f6b9b5383efd61/decc-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-17 23:31:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "moesio-f",
    "github_project": "decc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "decc"
}
        
Elapsed time: 0.43232s