Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s-soltys/genetic-optimization
A simple genetic optimization library for TypeScript.
https://github.com/s-soltys/genetic-optimization
Last synced: about 2 months ago
JSON representation
A simple genetic optimization library for TypeScript.
- Host: GitHub
- URL: https://github.com/s-soltys/genetic-optimization
- Owner: s-soltys
- License: mit
- Created: 2017-03-29T12:31:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-03-30T08:23:56.000Z (over 7 years ago)
- Last Synced: 2024-10-04T01:35:14.415Z (3 months ago)
- Language: TypeScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Genetic optimization
[![Build Status](https://travis-ci.org/s-soltys/genetic-optimization.svg?branch=master)](https://travis-ci.org/s-soltys/genetic-optimization)A simple library used to find an optimal solution to a problem.
### How to install
```
npm install --save genetic-optimization
```### How to use
Example implementation of a simple exponential math function:
```typescript
import { Optimizer } from "genetic-optimization";// the optimized exponential function
let expFn = (x: number) => -Math.pow(x - expectedSolution, 2);
let expectedSolution = 25;// construct the optimizer
let optimizer = new Optimizer({
evaluate: expFn,
crossover: (a, b) => (a+b)/2 + (Math.random()-0.5)/4,
endCondition: (input, score, generation) => generation === 10
});// generate initial population
let population = new Array(5000);
for (let i = 0; i < population.length; i++){
population[i] = (Math.random() - 0.5) * 100;
}// run the optimization algorithm
let foundSolution = optimizer.findOptimal(population);// assert solution
expect(foundSolution).toBeCloseTo(expectedSolution, 1);
```