Typenetic - Genetic algorithm for Typescript
Table of Contents
Installation
-
Install module:
npm install typenetic --save
-
You need to set these options in
tsconfig.json
file in your project:
Example usage
-
Create
GeneticOperators.ts
file:; -
Create
index.ts
file:;;// create population;// evolve population;
Decorators
Signature | Description |
---|---|
@Selection(size?: number) |
Selection operator, which task is to select elities from population. If size provided, then decorated function result will be sliced: result.slice(0, size) (useful in eg. tournament selection). |
@Crossover() |
Crossover operator is responsible for crossing two units. |
@Mutation() |
Mutation operator randomly modify genes in the unit. |
Genetic operators examples
Selection
Tournament selection
Tournament selection chooses best units from population, based on unit's fitness.
;
Crossover
Single point
In single point crossover, one point, randomly chosen is used to split parents and create new unit with genes from first parent before chosen point and with genes from second parent, beyond chosen point.
;
Mutation
Mutation operator randolmy modify genes of units. The probability of mutation depends on mutation rate.
;