DarwinPy


NameDarwinPy JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryA evolutionary computation module
upload_time2023-05-08 13:53:23
maintainer
docs_urlNone
authorPius Arhanbhunde
requires_python
licenseMIT License
keywords evolution
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DarwinPy

 ## Introduction
DarwinPy is a Python-based evolutionary computation module that makes it easy to implement evolutionary methods such as genetic algorithms and evolutionary strategies with only a few lines of code.

## Installing DarwinPy
DarwinPy can be installed with the command `pip install DarwinPy`.

## Classes in DarwinPy
Genetics Classes (`DarwinPy.Genetics.Genetics`)

**Methods:**
* `setSearchSpace(search_space)`: Sets the `search_space` attribute of the DarwinPy object.
* `setChromosomeLength(chromosome_length)`: Sets the `chromosome_length` attribute of the DarwinPy object.
* `setPopulationSize(population_size)`: Sets the `population_size` attribute of the DarwinPy object.
* `setChromosomeMatrix(search_space)`: Sets the `chromosome_matrix` attribute of the DarwinPy object.
* `getChromosomeMatrix()`: Returns the `chromosome_matrix` attribute, which is a NumPy array.
* `getSearchSpace()`: Returns the `search_space` attribute, which is a tuple.
* `populate()`: Initializes the `chromosome_matrix` attribute with initial values or gene population.
* `select(fitness_vector)`: Selects mating pairs based on the fitness.
* `crossover(crossover_rate)`: Mates selected pairs and updates the `chromosome_matrix` attribute.
* `mutate(mutation_rate)`: Mutates the `chromosome_matrix` attribute of the DarwinPy object.
* `evolve(fitness_vector, mutation_rate, crossover_rate)`: Performs a complete genetic algorithm cycle, which includes selection, crossover, and mutation.

| Identifier | Type      |
|------------|-----------|
| `setSearchSpace`      | `None`     |
| `setChromosomeLength` | `None`     |
| `setPopulationSize`   | `None`     |
| `setChromosomeMatrix` | `None`     |
| `getChromosomeMatrix` | `numpy.array` |
| `getSearchSpace`      | `tuple`    |
| `populate`            | `None`     |
| `select`              | `None`     |
| `crossover`           | `None`     |
| `mutate`              | `None`     |
| `evolve`              | `None`     |

**Attributes:**
* `chromosome_length`: The length of each chromosome in the DarwinPy object.
* `population_size`: The size of the population in the DarwinPy object.
* `search_space`: The search space for the genetic algorithm, which is a tuple with an upper and lower bound.
* `chromosome_matrix`: The array of chromosomes in the DarwinPy object.
* `pair_list`: The list of mating pairs.
* `data_type`: The data type in which the genetic algorithm is bounded.

| Identifier           | Type          |
|----------------------|---------------|
| `chromosome_length`   | `int`         |
| `population_size`     | `int`         |
| `search_space`        | `tuple`       |
| `chromosome_matrix`   | `numpy.array` |
| `pair_list`           | `list`        |
| `data_type`           | `type`        |

## A Sample DarwinPy implementation
```python

import DarwinPy
import numpy as np

def hammingDist(goal, matrix):
    result = []
    for i in range(len(matrix)):
        temp = 0.
        for j in range(len(goal)):
            if goal[j] == matrix[i][j]:
                temp += 1.
        result.append(temp)
    return result


if __name__ == "__main__":
    mouse_population = 5
    mutation_rate = 0.5
    search_space = (0,1)
    goal = np.array([1,0,1,1,0,1,1, 0,1,1,0],int)
    chromosome_length = len(goal)

    mouse_species = DarwinPy.Genetics.Genetics(chromosome_length,
    mouse_population, (0,1), int)
    print(f"mouse species instantiated:\n {mouse_species}")

    print("the goal:\n {}".format(goal))

    mouse_species.populate()
    print(f"get mouse matrix(GA):\n {mouse_species.getChromosomeMatrix()}")


    fitness_vector = np.array(
    hammingDist(goal,mouse_species.getChromosomeMatrix()),
    float)

    print(f"get fitness vector: {fitness_vector}")

    is_goal = False
    gen = 1
    while is_goal == False:
        print(f"Generation #{gen}\n")
        gen += 1
        mouse_species.evolve(fitness_vector,
        mutation_rate, 0.5)
        print(f"get mouse matrix(GA):\n {mouse_species.getChromosomeMatrix()}")
        fitness_vector = np.array(
        hammingDist(goal,mouse_species.getChromosomeMatrix()),
        float)

        print(f"get fitness vector: {fitness_vector}")
        if chromosome_length in fitness_vector:
            is_goal = True
```


Change Log
==========

0.0.1 (10/10/2021)
------------------
- First Release



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "DarwinPy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "evolution",
    "author": "Pius Arhanbhunde",
    "author_email": "pjacks419@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cf/fe/9efe02fbb23a701897d7d0fb39fb1295bec9642ebeca42160530f702d821/DarwinPy-0.0.2.tar.gz",
    "platform": null,
    "description": "# DarwinPy\n\n ## Introduction\nDarwinPy is a Python-based evolutionary computation module that makes it easy to implement evolutionary methods such as genetic algorithms and evolutionary strategies with only a few lines of code.\n\n## Installing DarwinPy\nDarwinPy can be installed with the command `pip install DarwinPy`.\n\n## Classes in DarwinPy\nGenetics Classes (`DarwinPy.Genetics.Genetics`)\n\n**Methods:**\n* `setSearchSpace(search_space)`: Sets the `search_space` attribute of the DarwinPy object.\n* `setChromosomeLength(chromosome_length)`: Sets the `chromosome_length` attribute of the DarwinPy object.\n* `setPopulationSize(population_size)`: Sets the `population_size` attribute of the DarwinPy object.\n* `setChromosomeMatrix(search_space)`: Sets the `chromosome_matrix` attribute of the DarwinPy object.\n* `getChromosomeMatrix()`: Returns the `chromosome_matrix` attribute, which is a NumPy array.\n* `getSearchSpace()`: Returns the `search_space` attribute, which is a tuple.\n* `populate()`: Initializes the `chromosome_matrix` attribute with initial values or gene population.\n* `select(fitness_vector)`: Selects mating pairs based on the fitness.\n* `crossover(crossover_rate)`: Mates selected pairs and updates the `chromosome_matrix` attribute.\n* `mutate(mutation_rate)`: Mutates the `chromosome_matrix` attribute of the DarwinPy object.\n* `evolve(fitness_vector, mutation_rate, crossover_rate)`: Performs a complete genetic algorithm cycle, which includes selection, crossover, and mutation.\n\n| Identifier | Type      |\n|------------|-----------|\n| `setSearchSpace`      | `None`     |\n| `setChromosomeLength` | `None`     |\n| `setPopulationSize`   | `None`     |\n| `setChromosomeMatrix` | `None`     |\n| `getChromosomeMatrix` | `numpy.array` |\n| `getSearchSpace`      | `tuple`    |\n| `populate`            | `None`     |\n| `select`              | `None`     |\n| `crossover`           | `None`     |\n| `mutate`              | `None`     |\n| `evolve`              | `None`     |\n\n**Attributes:**\n* `chromosome_length`: The length of each chromosome in the DarwinPy object.\n* `population_size`: The size of the population in the DarwinPy object.\n* `search_space`: The search space for the genetic algorithm, which is a tuple with an upper and lower bound.\n* `chromosome_matrix`: The array of chromosomes in the DarwinPy object.\n* `pair_list`: The list of mating pairs.\n* `data_type`: The data type in which the genetic algorithm is bounded.\n\n| Identifier           | Type          |\n|----------------------|---------------|\n| `chromosome_length`   | `int`         |\n| `population_size`     | `int`         |\n| `search_space`        | `tuple`       |\n| `chromosome_matrix`   | `numpy.array` |\n| `pair_list`           | `list`        |\n| `data_type`           | `type`        |\n\n## A Sample DarwinPy implementation\n```python\n\nimport DarwinPy\nimport numpy as np\n\ndef hammingDist(goal, matrix):\n    result = []\n    for i in range(len(matrix)):\n        temp = 0.\n        for j in range(len(goal)):\n            if goal[j] == matrix[i][j]:\n                temp += 1.\n        result.append(temp)\n    return result\n\n\nif __name__ == \"__main__\":\n    mouse_population = 5\n    mutation_rate = 0.5\n    search_space = (0,1)\n    goal = np.array([1,0,1,1,0,1,1, 0,1,1,0],int)\n    chromosome_length = len(goal)\n\n    mouse_species = DarwinPy.Genetics.Genetics(chromosome_length,\n    mouse_population, (0,1), int)\n    print(f\"mouse species instantiated:\\n {mouse_species}\")\n\n    print(\"the goal:\\n {}\".format(goal))\n\n    mouse_species.populate()\n    print(f\"get mouse matrix(GA):\\n {mouse_species.getChromosomeMatrix()}\")\n\n\n    fitness_vector = np.array(\n    hammingDist(goal,mouse_species.getChromosomeMatrix()),\n    float)\n\n    print(f\"get fitness vector: {fitness_vector}\")\n\n    is_goal = False\n    gen = 1\n    while is_goal == False:\n        print(f\"Generation #{gen}\\n\")\n        gen += 1\n        mouse_species.evolve(fitness_vector,\n        mutation_rate, 0.5)\n        print(f\"get mouse matrix(GA):\\n {mouse_species.getChromosomeMatrix()}\")\n        fitness_vector = np.array(\n        hammingDist(goal,mouse_species.getChromosomeMatrix()),\n        float)\n\n        print(f\"get fitness vector: {fitness_vector}\")\n        if chromosome_length in fitness_vector:\n            is_goal = True\n```\n\n\nChange Log\n==========\n\n0.0.1 (10/10/2021)\n------------------\n- First Release\n\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A evolutionary computation module",
    "version": "0.0.2",
    "project_urls": null,
    "split_keywords": [
        "evolution"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cffe9efe02fbb23a701897d7d0fb39fb1295bec9642ebeca42160530f702d821",
                "md5": "ee64c998fdb2e535a05decbe6442a54d",
                "sha256": "8700b53cc12d778aa927227bbf22981f2963d0f86b93a2564043180405fc5e41"
            },
            "downloads": -1,
            "filename": "DarwinPy-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ee64c998fdb2e535a05decbe6442a54d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6589,
            "upload_time": "2023-05-08T13:53:23",
            "upload_time_iso_8601": "2023-05-08T13:53:23.022782Z",
            "url": "https://files.pythonhosted.org/packages/cf/fe/9efe02fbb23a701897d7d0fb39fb1295bec9642ebeca42160530f702d821/DarwinPy-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-08 13:53:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "darwinpy"
}
        
Elapsed time: 0.08966s