{"_id":"@amplifi-labs/genets","_rev":"4-4e4ddfe673b650bd9dd6c1699e21353a","name":"@amplifi-labs/genets","dist-tags":{"latest":"0.0.5"},"versions":{"0.0.1":{"name":"@amplifi-labs/genets","version":"0.0.1","description":"Set of tools for optimizations based on genetic algorithms","main":"dist/main.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","run-example":"ts-node example.ts","build":"tsc"},"keywords":["AI","genetic","algorithms","async","TypeScript"],"author":{"name":"Paulo Rieck @ Amplifi Labs"},"license":"MIT","devDependencies":{"@types/fparser":"^2.0.0","@types/node":"^20.2.3","ts-node":"^10.9.1","typescript":"^5.0.4"},"dependencies":{"fparser":"^2.0.2"},"types":"./dist/main.d.ts","gitHead":"ea4dea42655c06f4a53bf5eccdd3f5db7e27f1e8","_id":"@amplifi-labs/genets@0.0.1","_nodeVersion":"19.8.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-buRjik+B9dDaZtf1oF6rD3WHm697XDni8cjeuNM1dybZ8Ktrc+ygTmhWvmEqYaT1HrqzOIKudnUKQwUEiWq/IQ==","shasum":"0bad7e0e2f615b10a98d8a2d81acd3c31d452088","tarball":"https://registry.npmjs.org/@amplifi-labs/genets/-/genets-0.0.1.tgz","fileCount":23,"unpackedSize":26879,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEYUiXCJhxiwkDRcgNzq1cFBsznSler8HVG8Mg2+QkENAiB8Aa27LHtqnW2g6Nm4sdon03D7bY9Ls2NfY8OP2IyMDw=="}]},"_npmUser":{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"},"directories":{},"maintainers":[{"name":"gtodesco","email":"gabriel.todesco97@gmail.com"},{"name":"roberio","email":"ranv87@gmail.com"},{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/genets_0.0.1_1685121490223_0.955746542579039"},"_hasShrinkwrap":false},"0.0.2":{"name":"@amplifi-labs/genets","version":"0.0.2","description":"Set of tools for optimizations based on genetic algorithms","main":"dist/main.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","run-example":"ts-node example.ts","build":"tsc"},"keywords":["AI","genetic","algorithms","async","TypeScript"],"author":{"name":"Paulo Rieck @ Amplifi Labs"},"license":"MIT","devDependencies":{"@types/fparser":"^2.0.0","@types/node":"^20.2.3","ts-node":"^10.9.1","typescript":"^5.0.4"},"dependencies":{"fparser":"^2.0.2"},"licenseText":"MIT License\n\nCopyright (c) 2023 Amplifi-Labs\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@amplifi-labs/genets@0.0.2","dist":{"shasum":"ccf25b3282d3a6a8f23683df689a0dac5e4f45bd","integrity":"sha512-YXkWKuyASdnl/1WSt8mIARa9K83/IXRP0JN/9ULGUyBxQUyCXocA1FBECkGpbLsfW2vVcE6ZHOf/tiNd6vLK/g==","tarball":"https://registry.npmjs.org/@amplifi-labs/genets/-/genets-0.0.2.tgz","fileCount":27,"unpackedSize":42486,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDKlKwadtLXNSNNOBPcdsaR0FcYEWh1tGI9w/r8xamwpQIgHbSGxjbcubcX754nO6uQVSEf4RgXIEEJsXm94cvNko8="}]},"_npmUser":{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"},"directories":{},"maintainers":[{"name":"gtodesco","email":"gabriel.todesco97@gmail.com"},{"name":"roberio","email":"ranv87@gmail.com"},{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/genets_0.0.2_1685130880748_0.4833806736450026"},"_hasShrinkwrap":false},"0.0.3":{"name":"@amplifi-labs/genets","version":"0.0.3","description":"Set of tools for optimizations based on genetic algorithms","main":"dist/main.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","run-example":"ts-node example.ts","build":"tsc"},"keywords":["AI","genetic","algorithms","async","TypeScript"],"author":{"name":"Paulo Rieck @ Amplifi Labs"},"license":"MIT","devDependencies":{"@types/fparser":"^2.0.0","@types/node":"^20.2.3","ts-node":"^10.9.1","typescript":"^5.0.4"},"dependencies":{"fparser":"^2.0.2"},"licenseText":"MIT License\n\nCopyright (c) 2023 Amplifi-Labs\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@amplifi-labs/genets@0.0.3","dist":{"shasum":"64a9a7a60579847d7ebf3932fb86256ab3cf0877","integrity":"sha512-4SF/Ck7sBSf8whKsYaQliNdFMA34eDgIgxTZ3kQGOkSAJRNfowJwC23K3wYM5X6G3AvLapBG4OFn3txdQCDJ1Q==","tarball":"https://registry.npmjs.org/@amplifi-labs/genets/-/genets-0.0.3.tgz","fileCount":27,"unpackedSize":43189,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIH2gBm6RSSvBPRJi1/uoeYcH6dJ0j2NUvLpxXtGJGYcEAiEAyr08XXhmgJStBrY6yday1qxJn/qh6t9yF5Y8Z6SZp+w="}]},"_npmUser":{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"},"directories":{},"maintainers":[{"name":"gtodesco","email":"gabriel.todesco97@gmail.com"},{"name":"roberio","email":"ranv87@gmail.com"},{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/genets_0.0.3_1685131625315_0.5934090939683536"},"_hasShrinkwrap":false},"0.0.4":{"name":"@amplifi-labs/genets","version":"0.0.4","description":"Set of tools for optimizations based on genetic algorithms","main":"dist/main.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","run-example":"ts-node example.ts","build":"tsc"},"keywords":["AI","genetic","algorithms","async","TypeScript"],"author":{"name":"Paulo Rieck @ Amplifi Labs"},"license":"MIT","devDependencies":{"@types/fparser":"^2.0.0","@types/node":"^20.2.3","ts-node":"^10.9.1","typescript":"^5.0.4"},"dependencies":{"fparser":"^2.0.2"},"licenseText":"MIT License\n\nCopyright (c) 2023 Amplifi-Labs\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"@amplifi-labs/genets@0.0.4","dist":{"shasum":"dc5d668c35aaf98d3384b964e3d114399158b8f6","integrity":"sha512-IwIzXKTMNKLaObC8Ap/ZfcszDPGuRvw8iawEVWpNHOHnDq5OFeMIw7gTGN94BOqcUyidf4vkq/2PBa+9N+nFhQ==","tarball":"https://registry.npmjs.org/@amplifi-labs/genets/-/genets-0.0.4.tgz","fileCount":27,"unpackedSize":47422,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFV9ylqmY9kadq2BLrwcEDhU1Q7ORgbWhnffpFHdXaZKAiBqqsfto//Wd3p75k+B74BywRcyHp0szsayG8SnFKv/Zw=="}]},"_npmUser":{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"},"directories":{},"maintainers":[{"name":"gtodesco","email":"gabriel.todesco97@gmail.com"},{"name":"roberio","email":"ranv87@gmail.com"},{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/genets_0.0.4_1685371350900_0.7495981119772956"},"_hasShrinkwrap":false},"0.0.5":{"name":"@amplifi-labs/genets","version":"0.0.5","description":"Set of tools for optimizations based on genetic algorithms","main":"dist/main.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","run-example":"ts-node example.ts","build":"tsc"},"keywords":["AI","genetic","algorithms","async","TypeScript"],"author":{"name":"Paulo Rieck @ Amplifi Labs"},"license":"MIT","devDependencies":{"@types/fparser":"^2.0.0","@types/node":"^20.2.3","ts-node":"^10.9.1","typescript":"^5.0.4"},"dependencies":{"fparser":"^2.0.2"},"_id":"@amplifi-labs/genets@0.0.5","gitHead":"3b065581b00496e005aa115ef63f40ac31f9daf1","types":"./dist/main.d.ts","_nodeVersion":"20.5.0","_npmVersion":"9.8.0","dist":{"integrity":"sha512-rIDs/4dYumFF6l4J4ORAisPabye/bOoZIXyKI1YS5MH11ymFK744ET5FHmV8mybhFaV0QyTwK4NNbc/1DB8omg==","shasum":"533e6480f82a4ef82438822dee2cb56f06586fe7","tarball":"https://registry.npmjs.org/@amplifi-labs/genets/-/genets-0.0.5.tgz","fileCount":25,"unpackedSize":1214364,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAexXnD5aMiGWdEseCm4PmnUFQIsHnNgssCPLrAn6u2vAiBG5H5zHRoAMOGt+mpxzxIPDWsxbpsRTmw6FfQ39+m8iA=="}]},"_npmUser":{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"},"directories":{},"maintainers":[{"name":"gtodesco","email":"gabriel.todesco97@gmail.com"},{"name":"roberio","email":"ranv87@gmail.com"},{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/genets_0.0.5_1690983660222_0.010251992328748072"},"_hasShrinkwrap":false}},"time":{"created":"2023-05-26T17:18:10.170Z","0.0.1":"2023-05-26T17:18:10.393Z","modified":"2023-08-02T13:41:00.686Z","0.0.2":"2023-05-26T19:54:40.905Z","0.0.3":"2023-05-26T20:07:05.532Z","0.0.4":"2023-05-29T14:42:31.048Z","0.0.5":"2023-08-02T13:41:00.578Z"},"maintainers":[{"name":"gtodesco","email":"gabriel.todesco97@gmail.com"},{"name":"roberio","email":"ranv87@gmail.com"},{"name":"paulo.rieck_amplifi","email":"paulo.rieck@amplifilabs.com"}],"description":"Set of tools for optimizations based on genetic algorithms","keywords":["AI","genetic","algorithms","async","TypeScript"],"author":{"name":"Paulo Rieck @ Amplifi Labs"},"license":"MIT","readme":"![](https://raw.githubusercontent.com/Amplifi-Labs/GeneTS/main/assets/GeneTS_Banner.png)\n\n# GeneTS\nTypescript Swiss Army Knife for [Genetic Algorithms](https://en.wikipedia.org/wiki/Genetic_algorithm)\n\nWhile searching for up to date libraries that fully supports [TypeScript](https://www.typescriptlang.org)/types and based on a modern approach, nothing was found. This library goal is to fill this gap.\n\nFor now this is a very basic implementation and improvements will be implemented. Feal free to help us to make it better!\n\n# Glossary\n\n## Genetic Algorithms\n\nIt's a [Numerical Analysis](https://en.wikipedia.org/wiki/Numerical_analysis) for solving optimization problems. It is based on the natural concept of evolution. The same concepts of natural selection are applied to improve a population of individuals based on predefined criteria, i.e. a mathematical equation. Is it commonly applied to find maximums or minimums that fits better on predefined conditions. It makes totally sense to use Genetic Algorithms when the number of variables is high, making it hard (or even impossible) to solve the maximum (or minimum) of an equation by analytical methods.\n\n## Gene\n\nIs the basic numerical representation of o bit. The number of bits represents the precision of the final solution. In other words, the more genes you have, the better the precision. But also, the more genes you have, more CPU power is consumed to run the optimization problem.\n\n## Chromosome\n\nChromosomes are formed by the genes. The chromosome is a binary representation of a floating (or integer in some cases) number after normalized under a specific domain/interval. As a general rule, the number of chromosomes in an individual is defined by the number of variables in your problem.\n\n## Individual\n\nIndividuals are composed by a set of chromosomes. An individual represents one set of variables that are tested against a predefined condition, i.e. a multi-variable formula.\n\n## Population\n\nPopulations are made from a combination of individuals. Each chromosome of an individual is transformed into a floating point number. Those numbers are then applied into the equations. The individuals that better fits the mathematical equation will survive to reproduce and create the next generation. This next generation will reproduce again and this loop of optimization will run until a predefined condition is established. The individual that fits the best this new generation will most likely be the closest to the ideal numerical result.\n\n## Interval\n\nThe interval determines the domain of the analysis. In other words, if you specify the domain as [-10, 10], the chromosomes (binary array) will be converted to a number in this domain. For example, if we take in consideration a chromosome with 2 bits, this chromosome can represent 4 different states: '00', '01', '10', 'and '11'. Converting it to a floating point number, '00' will mean -10, '01' will represent -3.3333..., '10' will represent +3.3333, and finally '11' would represent +10. Notice that the precision if this domain [-10, 10] represented by 4 different possible genetic combination has a precision of 6.6666, which is pretty bad. If we consider 2 more genes for the chromosome (4 bits), the precision will be 1.25. And if we have 8 bits/genes of the precision of the solution will be 0.078125. So, a general rule is, the greater the interval/domain, the bigger needs to be the number of genes.\n\n## Crossover\n\nThe more iterations you have in your solution, the bigger is the population homogeneity. And this might be bad. Let's say you have a polynomial equation with many humps. It's very possible that the results will get concentrated on a false maximum and produce a result that doesn't corresponds to the true maximum on a given domain. To avoid that Genetic Algorithms apply two different concepts, both also found in nature: crossover and mutation. \n\nCrossover represents the error of having a gene (or a segment of a chromosome) that should come from the father, coming from the mother instead.\n\n## Mutation\n\nMutation in the other hand is simply the swap of a gene, i.e. 0 becoming 1 or vice-versa.\n\n# Code sample\n\nHow to run this example?\n\n## Clone git repository\n\n~~~\ngit clone https://github.com/Amplifi-Labs/GeneTS && cd GeneTS\n~~~\n\n## Install dependencies\n\n~~~\nyarn install\n~~~\n\nOR\n\n~~~\nnpm install\n~~~\n## Run the example\n\n~~~\nyarn run-example\n~~~\n\nOR\n\n~~~\nnpm run run-example\n~~~\n\n## Example code\n\n~~~\nimport {\n  Interval,\n  normalizedIndividual,\n  processIndividualResult,\n  buildMathParameters,\n  createInitialPopulation,\n  processNewGeneration,\n  testPopulation,\n  shuffle,\n  calculatePopulationAverageResult,\n  calculateConvergence,\n} from \"./src/main\";\n\nconst init = new Date();\n\nlet population = createInitialPopulation({\n  size: 200,\n  numberOfChromosomes: 3,\n  numberOfGenes: 16,\n});\n\nconst mutations = {\n  crossoverChances: 0.01,\n  mutationChanges: 0.01,\n};\n\nconst formula = 'a + b^2 - c^4';\nconst interval: Interval = [-10, 10];\n\nlet normalizedChampion: number[] = [];\n\nlet convergence = 100;\nlet previousPopulationAverageResult: number | undefined;\n\nfor (\n  let i = 0;\n  i < 50 && convergence > 0.000000001;\n  i += 1\n) {\n  population = processNewGeneration({population, ...mutations});\n  population = testPopulation({population, formula, interval});\n  const champion = population[0];\n\n  /* Show results for champion */\n  normalizedChampion = normalizedIndividual({individual: champion, interval });\n  const championParameters = buildMathParameters({individual: normalizedChampion});\n  const result = processIndividualResult({formula, parameters: championParameters});\n  const populationAverageResult = calculatePopulationAverageResult({population, formula, interval});\n  if (previousPopulationAverageResult) {\n    convergence = calculateConvergence({a: populationAverageResult, b: previousPopulationAverageResult})\n  }\n\n  console.log('----------------------------------------------------');\n  console.log(\n    `generation: ${i},\\n`+\n    `result for champion: ${result},\\n`+\n    `convergence: ${convergence},\\n`+\n    `populationAverageResult: ${populationAverageResult}`\n  );\n  /* ------------------------- */\n\n  population = shuffle(population);\n\n  previousPopulationAverageResult = populationAverageResult;\n}\n\nconsole.log('time to process:', new Date().getTime() - init.getTime(), 'ms');\nconsole.log('normalizedChampion:', normalizedChampion);\n~~~\n\n# Amplifi Labs\n\nAmplifi Labs is a software boutique located in the USA, North Carolina. We create applications for a vast number of cases, including mobile and web. We have a highly capable team, that is able to work with highly complex problems, including Natural Language Processing, Machine Learning, Genetic Algorithms and more!\n\nIf you need any help on implementing such kind of computer program, please, don't hesitate to contact us!\n","readmeFilename":"README.md"}