optigen


Nameoptigen JSON
Version 0.0.7 PyPI version JSON
download
home_page
SummaryGenetic algorithms framework
upload_time2023-09-13 16:32:35
maintainer
docs_urlNone
authorShadowFlameFox
requires_python
license
keywords python genetic natural selection algorithms optimation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Getting Started

OptiGen: A Python Genetic Algorithm Library

OptiGen is a Python library that simplifies the implementation of genetic algorithms for solving optimization problems. It provides a set of classes and functions to create, evolve, and evaluate populations of potential solutions.

## Installation
To use OptiGen, you can install it using pip:


`pip install optigen`

## Example Usage
Here's an example of how to use OptiGento evolve a population to match a predefined output pattern:

```
from OptiGen import next_generation, Phenotype

if __name__ == "__main__":

    training_data = Training_Data()

    phenotypes = []

    output = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    thresh_hold = 0.99
    population_size = 100
    mutation_rate = 0.001
    max_generations = 1000

    for __ in range(population_size):
        phenotype = Phenotype(len(output),[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
        for x in range(len(phenotype.result)):
            if phenotype.result[x] == output[x]:
                phenotype.fitness += 1 / len(output)
        phenotypes.append([phenotype.fitness, phenotype.result])
    phenotypes.sort(reverse=True)
    print(f"Generation 0: Best score: { phenotypes[0]}")
    training_data.original_data.append(phenotypes[0][0])

    for gen in range(max_generations):
        next_phenotypes = next_generation(phenotypes, mutation_rate).new_generation
        phenotypes = []
        for x in next_phenotypes:
            phenotype = Phenotype(len(output), x.result)
            for y in range(len(phenotype.result)):
                if phenotype.result[y] == output[y]:
                    phenotype.fitness += 1 / len(output)
            phenotypes.append([phenotype.fitness, phenotype.result])
        phenotypes.sort(reverse=True)

        print(f"Generation {gen + 1}: Best score: {phenotypes[0][0]} Result: {phenotypes[0][1]}")
        training_data.original_data.append(phenotypes[0][0])
        if phenotypes[0][0] >= thresh_hold:
            break
    training_data.show_graph()
```
Full Documentation: [GitHub](https://github.com/ShadowFlameFox/OptiGen/wiki/Documentation)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "optigen",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,genetic,natural selection,algorithms,optimation",
    "author": "ShadowFlameFox",
    "author_email": "<shadow_flame_fox@web.de>",
    "download_url": "https://files.pythonhosted.org/packages/c0/26/c11d0a9f03044a163fb29b168e19ea84de3bd572378b3bfdbc97a2e0ac76/optigen-0.0.7.tar.gz",
    "platform": null,
    "description": "# Getting Started\r\n\r\nOptiGen: A Python Genetic Algorithm Library\r\n\r\nOptiGen is a Python library that simplifies the implementation of genetic algorithms for solving optimization problems. It provides a set of classes and functions to create, evolve, and evaluate populations of potential solutions.\r\n\r\n## Installation\r\nTo use OptiGen, you can install it using pip:\r\n\r\n\r\n`pip install optigen`\r\n\r\n## Example Usage\r\nHere's an example of how to use OptiGento evolve a population to match a predefined output pattern:\r\n\r\n```\r\nfrom OptiGen import next_generation, Phenotype\r\n\r\nif __name__ == \"__main__\":\r\n\r\n    training_data = Training_Data()\r\n\r\n    phenotypes = []\r\n\r\n    output = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\r\n\r\n    thresh_hold = 0.99\r\n    population_size = 100\r\n    mutation_rate = 0.001\r\n    max_generations = 1000\r\n\r\n    for __ in range(population_size):\r\n        phenotype = Phenotype(len(output),[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])\r\n        for x in range(len(phenotype.result)):\r\n            if phenotype.result[x] == output[x]:\r\n                phenotype.fitness += 1 / len(output)\r\n        phenotypes.append([phenotype.fitness, phenotype.result])\r\n    phenotypes.sort(reverse=True)\r\n    print(f\"Generation 0: Best score: { phenotypes[0]}\")\r\n    training_data.original_data.append(phenotypes[0][0])\r\n\r\n    for gen in range(max_generations):\r\n        next_phenotypes = next_generation(phenotypes, mutation_rate).new_generation\r\n        phenotypes = []\r\n        for x in next_phenotypes:\r\n            phenotype = Phenotype(len(output), x.result)\r\n            for y in range(len(phenotype.result)):\r\n                if phenotype.result[y] == output[y]:\r\n                    phenotype.fitness += 1 / len(output)\r\n            phenotypes.append([phenotype.fitness, phenotype.result])\r\n        phenotypes.sort(reverse=True)\r\n\r\n        print(f\"Generation {gen + 1}: Best score: {phenotypes[0][0]} Result: {phenotypes[0][1]}\")\r\n        training_data.original_data.append(phenotypes[0][0])\r\n        if phenotypes[0][0] >= thresh_hold:\r\n            break\r\n    training_data.show_graph()\r\n```\r\nFull Documentation: [GitHub](https://github.com/ShadowFlameFox/OptiGen/wiki/Documentation)\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Genetic algorithms framework",
    "version": "0.0.7",
    "project_urls": null,
    "split_keywords": [
        "python",
        "genetic",
        "natural selection",
        "algorithms",
        "optimation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a4efd87169e67cdce7b2ba69d860825aa6785107a1a3f1ca432f73a8353df660",
                "md5": "74a46edcb5517871e99c5ec2d16325ba",
                "sha256": "8b5a984c4ccdbca4afe831bffb664f5479f467e96db8d9f9ea298cbfdaf6b853"
            },
            "downloads": -1,
            "filename": "optigen-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "74a46edcb5517871e99c5ec2d16325ba",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 4995,
            "upload_time": "2023-09-13T16:32:33",
            "upload_time_iso_8601": "2023-09-13T16:32:33.276581Z",
            "url": "https://files.pythonhosted.org/packages/a4/ef/d87169e67cdce7b2ba69d860825aa6785107a1a3f1ca432f73a8353df660/optigen-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c026c11d0a9f03044a163fb29b168e19ea84de3bd572378b3bfdbc97a2e0ac76",
                "md5": "50cc85fc0beadb1d018c337c529ff052",
                "sha256": "175c9678d23096069bae0223ca542980e6493fafab84b4ad66f5fad8559e9b11"
            },
            "downloads": -1,
            "filename": "optigen-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "50cc85fc0beadb1d018c337c529ff052",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3321,
            "upload_time": "2023-09-13T16:32:35",
            "upload_time_iso_8601": "2023-09-13T16:32:35.969525Z",
            "url": "https://files.pythonhosted.org/packages/c0/26/c11d0a9f03044a163fb29b168e19ea84de3bd572378b3bfdbc97a2e0ac76/optigen-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-13 16:32:35",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "optigen"
}
        
Elapsed time: 0.11117s