ixjs-evolution
Version:
A set of evolutionary search algorithms done through IxJS
35 lines (29 loc) • 1.06 kB
JavaScript
var Ix = require('ix');
module.exports = {
gaussian: gaussian
}
/**
* Randomly mutates the individual. The stream coming in better be from a
* crossover operation.
*
* @param {Ix.Enumerable} selectorEnum
* @param {Number} probability
* @return {Ix.Enumerable}
*/
function gaussian(selectorEnum, options) {
return selectorEnum
.select(function(population) {
for (var i = 0; i < population.length; i++) {
var individual = population[i];
for (var j = 0; j < individual.length; j++) {
//Use a gaussian to change the value of the individual
var center = Math.random();
var sigmaBase = 2 * options.sigma * options.sigma;
var partial = Math.pow(Math.E, -1 * center * center / sigmaBase);
var result = (Math.random() > 0.5 ? 1 : -1) * options.heightAdjust * partial;
individual[j] += result;
}
}
return population;
});
}