{"id":16563720,"url":"https://github.com/nathsou/darwin","last_synced_at":"2025-03-21T11:32:45.598Z","repository":{"id":33983727,"uuid":"77268892","full_name":"nathsou/Darwin","owner":"nathsou","description":"Flexible genetic algorithm implementation in TypeScript.","archived":false,"fork":false,"pushed_at":"2023-03-04T03:05:02.000Z","size":1297,"stargazers_count":28,"open_issues_count":12,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-19T09:07:43.929Z","etag":null,"topics":["algorithms","darwin","evolution","genetic","genetic-algorithm","typescript"],"latest_commit_sha":null,"homepage":"https://nathsou.github.io/Darwin/SmartEaters/","language":"TypeScript","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/nathsou.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}},"created_at":"2016-12-24T06:06:44.000Z","updated_at":"2024-05-24T17:12:48.000Z","dependencies_parsed_at":"2023-12-19T11:06:07.456Z","dependency_job_id":null,"html_url":"https://github.com/nathsou/Darwin","commit_stats":{"total_commits":53,"total_committers":3,"mean_commits":"17.666666666666668","dds":0.5849056603773585,"last_synced_commit":"2e6e45c4814fc84b32557a24e2d572cd8b38a250"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathsou%2FDarwin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathsou%2FDarwin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathsou%2FDarwin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathsou%2FDarwin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathsou","download_url":"https://codeload.github.com/nathsou/Darwin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221814961,"owners_count":16885086,"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":["algorithms","darwin","evolution","genetic","genetic-algorithm","typescript"],"created_at":"2024-10-11T20:42:07.924Z","updated_at":"2024-10-28T10:05:03.772Z","avatar_url":"https://github.com/nathsou.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM Package][npm]][npm-url]\n[![Build Size][build-size]][build-size-url]\n\n# Darwin\n\nFlexible genetic algorithm implementation in TypeScript.\n\n## Installation\n\n```bash\nnpm install charles.darwin\n```\n\nDarwin is compatible with ES6 modules\n\n### Demos\n\n- [Smart Eaters](https://nathsou.github.io/Darwin/SmartEaters/) inspired by [Mat Buckland](http://www.ai-junkie.com/ann/evolved/nnt1.html)\n- [Typing Monkeys](https://nathsou.github.io/Darwin/TypingMonkeys/) inspired by [Daniel Shiffman](http://natureofcode.com/book/chapter-9-the-evolution-of-code/)\n- [Traveling Salesman](https://nathsou.github.io/Darwin/TSP/)\n- [Text Deblurring](https://nathsou.github.io/Darwin/DeblurText/)\n\n## Usage\n\nOne must first choose a way of encoding the desired behavior as an array of some type (a chromosome) and of evaluating the fitness of any such chromosome.\n\nFor instance the 'Typing Monkeys' demo tries to evolve towards a target string, the fitness is simply the number of correct characters present in the randomly generated string.\n\nOn the other hand, the 'Smart Eaters' demo evolves the weights and biases of an artificial neural network, the fitness of an 'Eater' is the number of nutriments it eats in one generation (2000 ticks).\n\n```typescript\n  const population = new Darwin\u003cT\u003e({\n    populationSize: number,\n    chromosomeLength: number,\n    randomGene: () =\u003e T,\n    crossoverRate?: number = 0.7,\n    mutationRate?: number = 1 / populationSize,\n    crossoverMethod?: CrossoverFunction\u003cT\u003e = crossoverMethod.singlePoint,\n    mutationMethod?: MutationFunction\u003cT\u003e = mutationMethod.flip,\n    eliteCount?: number = Math.ceil(populationSize / 25),\n    eliteCopies?: number = 1,\n    randomNumber?: () =\u003e number = Math.random\n  });\n```\n\nThe constructor of the Darwin class initializes a population of random chromosomes, we can now assign a score (or fitness) to each of those chromosomes based on their genes represented by an array of the type returned by the randomGene function :\n\n```typescript\n  for (const chromo of population.getPopulation()) {\n    chromo.setFitness(evalFitness(chromo.getGenes()));\n  }\n\n  // shorthand:\n  population.updateFitness(genes =\u003e evalFitness(genes));\n```\n\nA new generation can then be generated by calling the mate() method:\n\n```typescript\n  population.mate();\n```\n\nTo observe the evolution of the population, one can call:\n\n```typescript\n  const {\n    fittest,\n    fittestIndex,\n    averageFitness,\n    totalFitness\n  } = population.updateStats();\n```\n\n[npm]: https://img.shields.io/npm/v/charles.darwin\n[npm-url]: https://www.npmjs.com/package/charles.darwin\n[build-size]: https://badgen.net/bundlephobia/minzip/charles.darwin\n[build-size-url]: https://bundlephobia.com/result?p=charles.darwin","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathsou%2Fdarwin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathsou%2Fdarwin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathsou%2Fdarwin/lists"}