# Natural Selection
```
,(*
@@
*@ @@% *@
*@ @@ %@ @
@@/ @@ @@ @@
@@@(,@( @/ @@@@@@@&@@@@@
@ @& @@ /@@@#
/@ @@ ,@@ @@
,@@ @@ @@ @
%@@@ @@ @@@@@@@@@@@@@
,, @ @@ @@ &@@@
%@@ @@ &@@ @@
@%@@ &@@ @
,@,%@@
@@@@@@
_ _
_ __ __ _| |_ _ _ _ __ __ _| |
| '_ \ / _` | __| | | | '__/ _` | |
| | | | (_| | |_| |_| | | | (_| | |
|_| |_|\__,_|\__|\__,_|_| \__,_|_|
_ _ _
___ ___| | ___ ___| |_(_) ___ _ __
/ __|/ _ \ |/ _ \/ __| __| |/ _ \| '_ \
\__ \ __/ | __/ (__| |_| | (_) | | | |
|___/\___|_|\___|\___|\__|_|\___/|_| |_|
by Zipfian Science
```
Python tools for creating and running Evolutionary Algorithm (EA) experiments by [Zipfian Science](https://zipfian.science/).
* For documentation, see [docs](https://docs.zipfian.science/natural-selection/index.html).
* Source on [GitHub](https://github.com/Zipfian-Science/natural-selection).
* For history, see [changelog](https://docs.zipfian.science/natural-selection/changelog.html#changelog-page)
## Install
```shell script
$ pip install natural-selection
```
## And use
```python
from natural_selection.genetic_algorithms import Gene, Chromosome, Individual, Island
from natural_selection.genetic_algorithms.utils.random_functions import random_int, random_gaussian
# Create a gene
g_1 = Gene(name="test_int", value=3, gene_max=10, gene_min=1, randomise_function=random_int)
g_2 = Gene(name="test_real", value=0.5, gene_max=1.0, gene_min=0.1, randomise_function=random_gaussian)
# Add a list of genes to a genome
gen = Chromosome([g_1, g_2])
# Next, create an individual to carry these genes and evaluate them
fitness_function = lambda island, individual, x, y: individual.chromosome[0].value * x + individual.chromosome[0].value * y
adam = Individual(fitness_function, name="Adam", chromosome=gen)
# Now we can create an island for running the evolutionary process
# Notice the fitness function parameters are given here.
params = dict()
params['x'] = 0.5
params['y'] = 0.2
isolated_island = Island(function_params=params)
# Using a single individual, we can create a new population
isolated_island.initialise(adam, population_size=5)
# And finally, we let the randomness of life do its thing: optimise
best_individual = isolated_island.evolve(n_generations=5)
# After running for a few generations, we have an individual with the highest fitness
fitness = best_individual.fitness
genes = best_individual.chromosome
for gene in genes:
print(gene.name, gene.value)
```
## Release
- Date: 2023-01-25
- Version: 0.2.30
Raw data
{
"_id": null,
"home_page": "",
"name": "natural-selection",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "GENETIC ALGORITHMS,EVOLUTIONARY ALGORITHMS",
"author": "Zipfian Science",
"author_email": "about@zipfian.science",
"download_url": "https://files.pythonhosted.org/packages/a4/6d/d209f9985acd0377b8f74f6cfd4ab5039dcf2a974c0f4d4eb3fb73225884/natural_selection-0.2.30.tar.gz",
"platform": null,
"description": "# Natural Selection\n```\n ,(* \n @@ \n*@ @@% *@ \n*@ @@ %@ @ \n @@/ @@ @@ @@ \n @@@(,@( @/ @@@@@@@&@@@@@ \n @ @& @@ /@@@# \n /@ @@ ,@@ @@ \n ,@@ @@ @@ @ \n %@@@ @@ @@@@@@@@@@@@@ \n ,, @ @@ @@ &@@@ \n %@@ @@ &@@ @@\n @%@@ &@@ @\n ,@,%@@ \n @@@@@@ \n _ _ \n _ __ __ _| |_ _ _ _ __ __ _| |\n| '_ \\ / _` | __| | | | '__/ _` | |\n| | | | (_| | |_| |_| | | | (_| | |\n|_| |_|\\__,_|\\__|\\__,_|_| \\__,_|_| \n _ _ _ \n ___ ___| | ___ ___| |_(_) ___ _ __ \n/ __|/ _ \\ |/ _ \\/ __| __| |/ _ \\| '_ \\ \n\\__ \\ __/ | __/ (__| |_| | (_) | | | |\n|___/\\___|_|\\___|\\___|\\__|_|\\___/|_| |_|\n \nby Zipfian Science \n```\nPython tools for creating and running Evolutionary Algorithm (EA) experiments by [Zipfian Science](https://zipfian.science/).\n\n* For documentation, see [docs](https://docs.zipfian.science/natural-selection/index.html).\n* Source on [GitHub](https://github.com/Zipfian-Science/natural-selection).\n* For history, see [changelog](https://docs.zipfian.science/natural-selection/changelog.html#changelog-page)\n## Install\n\n```shell script\n$ pip install natural-selection\n```\n\n## And use\n\n```python\nfrom natural_selection.genetic_algorithms import Gene, Chromosome, Individual, Island\nfrom natural_selection.genetic_algorithms.utils.random_functions import random_int, random_gaussian\n\n# Create a gene\ng_1 = Gene(name=\"test_int\", value=3, gene_max=10, gene_min=1, randomise_function=random_int)\ng_2 = Gene(name=\"test_real\", value=0.5, gene_max=1.0, gene_min=0.1, randomise_function=random_gaussian)\n\n# Add a list of genes to a genome\ngen = Chromosome([g_1, g_2])\n\n# Next, create an individual to carry these genes and evaluate them\nfitness_function = lambda island, individual, x, y: individual.chromosome[0].value * x + individual.chromosome[0].value * y\nadam = Individual(fitness_function, name=\"Adam\", chromosome=gen)\n\n# Now we can create an island for running the evolutionary process\n# Notice the fitness function parameters are given here.\nparams = dict()\nparams['x'] = 0.5\nparams['y'] = 0.2\nisolated_island = Island(function_params=params)\n\n# Using a single individual, we can create a new population\nisolated_island.initialise(adam, population_size=5)\n\n# And finally, we let the randomness of life do its thing: optimise\nbest_individual = isolated_island.evolve(n_generations=5)\n\n# After running for a few generations, we have an individual with the highest fitness\nfitness = best_individual.fitness\ngenes = best_individual.chromosome\n\nfor gene in genes:\n print(gene.name, gene.value)\n```\n\n## Release\n\n- Date: 2023-01-25\n- Version: 0.2.30",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Tools for running evolutionary algorithm experiments",
"version": "0.2.30",
"split_keywords": [
"genetic algorithms",
"evolutionary algorithms"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a46dd209f9985acd0377b8f74f6cfd4ab5039dcf2a974c0f4d4eb3fb73225884",
"md5": "61f330b2c18cef4f3ad5d999bd7ffd6a",
"sha256": "3ff7e55774d481685d9fafeb68aab985473a38294c3996072397950e66861235"
},
"downloads": -1,
"filename": "natural_selection-0.2.30.tar.gz",
"has_sig": false,
"md5_digest": "61f330b2c18cef4f3ad5d999bd7ffd6a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 40780,
"upload_time": "2023-01-25T00:21:09",
"upload_time_iso_8601": "2023-01-25T00:21:09.241962Z",
"url": "https://files.pythonhosted.org/packages/a4/6d/d209f9985acd0377b8f74f6cfd4ab5039dcf2a974c0f4d4eb3fb73225884/natural_selection-0.2.30.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-25 00:21:09",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "natural-selection"
}