4.5.0 • Published 8 years ago
enome v4.5.0
enome
A Genome generation and evolution library
Note: This library is still in the early stages of development, and should not be considered producion-ready.
This library is written in TypeScript, and I recommend using it with a TypeScript project.
What is enome?
enome is a javascript/typescript library that allows you to asynchronously (using rxjs) evolve any kind of object you can think of.
enome has three main parts to its evolution system.
Organism:- an
Organismis just an object that contains agenotypeand aphenotypeand has the ability to interact with anEnvironment.- a
genotype, in this case, is aGenome, which contains genetic information that you use to create aphenotype. - a
phenotype, in this case, is whatever kind of object you would like to evolve.
- a
Organismsrecord data as they are interacting with theEnvironment.- Once the
Organismhas done a specified number ofinteractions, it evaluates itself based on the data it collected and sends the evaluation to thePopulation, which will decide how to evolve the organism. - You specify the function that determines the
fitnessof theOrganismbased on its data.
- Once the
- an
Environment:- an
Environmentis essentially just an asynchronous state container. - You interact with an
Environmentby sendingIStateUpdatesto itsstateproperty. - an
Environmentmay have multipleOrganismsinteracting with it at a time. Environmentshave aninteractionRateproperty which you can set that limits how often it acceptsIStateUpdates(think of it like a frame rate).Environmentsdeal with multiple asynchronous sources of incomingIStateUpdatesby buffering them over time based on theinteractionRateand then randomly choosing between them. TheEnvironmentwill only accept state updates that are based on the currentstate, otherwise state updates could happen out of order (think of it like an asynchronous way of having a shared order of events even though everything is happening out of order, technically).
- an
PopulationPopulationspopulate environments with organisms.Populationsare also in charge of determining howOrganismsevolve.- when a
Populationreceives an evaluation, it looks at thefitnessand determines what it wants to do with thegenotype.Populationscan update the genotype in the following ways:Reproducewill mix the genomes of the top organisms in the population based on fitness. (You can specify the percentage of organisms that qualifies as "top", which lets you determine whether you want to refine what is already working well or find new solutions)Mutatewill give each value in the Genome's sequence a chance to mutate and has two different mutation methods to choose from.subwill substitute the value for a new randomly generated one.avgwill average the value with a new randomly generated one.
Randomizewill replace the genome with a new randomly generated one (using the same options).Keepwill just send the organism back into the environment. This is good for when you get a genotype with a very good fitness and you don't want it to be mutated which has the possibility of making it worse.
- By default,
Populationswill choose between the different update methods randomly based on an array of weights that you provide.
- when a
Underlying the evolution system are Genomes and Genes:
Genome:- A
Genomeis just a container for genetic information, or asequence. - At its heart, a
sequenceis just an array of numbers between 0 and 1. - When created, the
Genometakes thatsequenceand producesGenesfrom it. Genomeprovides thegproperty which allows you to get the nextGenein the list, so you can consume them one by one in a queue-like manner.
- A
Gene:- A
Geneis just a container for avaluebetween 0 and 1. Genesgive you methods that interpolate their value into a value that it useful when creating thephenotype.for instance, say your phenotype is a first and last name:
interface Name { first: string; last: string; } interface NameOptions extends IGenomeOptions { firstMinLength: number; firstMaxLength: number; lastMinLength: number; lastMaxLength: number; } public createPhenotype(genome: Genome<NameOptions>): Name { // determine length of first name const firstLength = genome.g.int( genome.options.firstMinLength, genome.options.firstMaxLength ); // determine length of last name const lastLength = genome.g.int( genome.options.lastMinLength, genome.options.lastMaxLength ); //create first name const first = _.range(firstLength) .map(i => genome.g.letter()) .reduce((first, letter) => `${first}${letter}`) // create last name const last = _.range(lastLength) .map(i => genome.g.letter()) .reduce((last, letter) => `${last}${letter}`) return { first, last }; }
- A
How enome generates Genomes:
- Generates a
sequenceofvaluesbetween 0 and 1. - Groups those
valuesintoGenesby averaging them together- This results in the
Genomebeing less sensitive tomutation - The sensitivity is customizable by varying the number of
valuesthat go into eachGene
- This results in the
- Groups those
Genesinto aGenomeGenomeexposes a property calledgthat allows you to get the nextGenein theGenome.- This allows you to pass the
Genomearound, consuming itsGenesas you need them.
- This allows you to pass the
Install instructions
npm install enome4.5.0
8 years ago
4.4.5
8 years ago
4.4.4
8 years ago
4.4.3
8 years ago
4.4.2
8 years ago
4.4.1
8 years ago
4.4.0
8 years ago
4.3.0
8 years ago
4.2.0
8 years ago
4.1.1
8 years ago
4.1.0
8 years ago
4.0.0
8 years ago
2.3.0
8 years ago
2.2.0
8 years ago
2.1.1
8 years ago
2.0.0
8 years ago
1.1.0
8 years ago
1.0.4
8 years ago
1.0.3
8 years ago
1.0.2
8 years ago
1.0.1
8 years ago
1.0.0
8 years ago