{"id":22895896,"url":"https://github.com/daniel-lima-lopez/real-valued-genetic-algorithm","last_synced_at":"2025-03-31T23:39:04.511Z","repository":{"id":225541914,"uuid":"766209285","full_name":"daniel-lima-lopez/Real-Valued-Genetic-Algorithm","owner":"daniel-lima-lopez","description":"In this repository it is implemented a real-valued genetic algorithm in python","archived":false,"fork":false,"pushed_at":"2024-06-26T00:33:23.000Z","size":838,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T01:45:41.986Z","etag":null,"topics":["genetic-algorithm","genetic-algorithms","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daniel-lima-lopez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-02T16:27:02.000Z","updated_at":"2024-08-09T16:18:59.000Z","dependencies_parsed_at":"2024-06-26T01:48:57.198Z","dependency_job_id":"c0e987f5-bc96-4b4c-8105-0de1d24e5a7a","html_url":"https://github.com/daniel-lima-lopez/Real-Valued-Genetic-Algorithm","commit_stats":null,"previous_names":["daniel-lima-lopez/real-valued-genetic-algorithm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-lima-lopez%2FReal-Valued-Genetic-Algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-lima-lopez%2FReal-Valued-Genetic-Algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-lima-lopez%2FReal-Valued-Genetic-Algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-lima-lopez%2FReal-Valued-Genetic-Algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daniel-lima-lopez","download_url":"https://codeload.github.com/daniel-lima-lopez/Real-Valued-Genetic-Algorithm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246558117,"owners_count":20796696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["genetic-algorithm","genetic-algorithms","python"],"created_at":"2024-12-13T23:32:38.534Z","updated_at":"2025-03-31T23:39:04.485Z","avatar_url":"https://github.com/daniel-lima-lopez.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Real-Valued-Genetic-Algorithm\nIn this repository it is implemented a real-valued genetic algorithm in python to minimize objective functions. All operators are implemented into a single class  to facilitate the understanding of the algorithm c:\n\n## Method description\nThe implemented algorithm consists of three operators: binary tournament, crossover and mutation. Which imitates the natural selection mechanism.\n\nGiven an objective function $f=f(x_1,x_2,\\dots,x_n):R^n\\rightarrow R$ to be minimized, denominated fitness. The algorithm stars defining a random set of solutions, which evolve through each generation (iteration) of the algorithm. On each generation, the set of solutions are compared on random binary tournaments to identify the most salients. Then, a recombination process (crossover) combine the information of the solutions. Finally, solutions have a little mutation probability to expand the explored information. The next generation is formed with the most salient solution of this process and some the best solution of the current generation.\n\n## Instalation\nClone this repository:\n```bash\ngit clone git@github.com:daniel-lima-lopez/Real-Valued-Genetic-Algorithm.git\n```\n\n## Example\nWithin the same directory, we can import the algorithm as follows:\n```python\nfrom GenAlg import RealGA\nGA = RealGA(nv=2, f=fitness)\n```\nwhere $nv$ is the number of variables in the fitness function $f$.\n\nFor example for the function:\n$$f(x,y)=x\\cdot e^{-(x^2+y^2)} $$\nThe following code minimize the function considering this as a problem of 2 variables (`nv=2`), a poblation of 10 individuals (`ni=10`), a mutation probability of $10\\%$ (`pm=1/10`) and restrinting the varaibles domain in the set $[-5.0,5.0]$:\n```python\nfrom GenAlg import RealGA\n\n# fitness function\ndef f(xs):\n    fs = []\n    for xi in xs:\n        fs.append(xi[0]*np.exp(-(xi[0]**2+xi[1]**2)))\n    return fs\n\n# algorithm\nGA = RealGA(nv=2, ni=10, f=f, pm=1/10, ri=-5.0, rf=5.0)\n\n# evolution process\nbests, best_fs = test.train_estb(gens=50)\n\n```\nThe console prints the evolution of the algorithm:\n```bash\nGeneracion: 1\nFit promedio : -0.009436005576237246\nFit minimo ([-0.36725049  1.06116519]): -0.10407373725213666\n\nGeneracion: 2\nFit promedio : 0.003707735133523954\nFit minimo ([-0.36725049  1.06116519]): -0.10407373725213666\n.\n.\n.\nGeneracion: 49\nFit promedio : -0.3816207840035485\nFit minimo ([-0.63125048 -0.04682561]): -0.42285652398462925\n\nGeneracion: 50\nFit promedio : -0.4187185638687967\nFit minimo ([-0.63125048 -0.04682561]): -0.42285652398462925\n\n```\nThe next figure shows the fitness function on the left size. On the reight side, it is presented the minimization of the fitness function on 10 diferent experiments.\n![Experiment 2](imgs/exp2.png)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-lima-lopez%2Freal-valued-genetic-algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel-lima-lopez%2Freal-valued-genetic-algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-lima-lopez%2Freal-valued-genetic-algorithm/lists"}