<commit_before>class Genegen {

	constructor(seed,fitness,copy,crossover,mutate)
	{
		this.fitness = fitness;
		this.seed = seed;
		this.mutate = mutate;
		this.mutationType = slideMutate;
		this.select1 = this.Tournament2;
		this.select2 = this.Reproduction;
		this.optimize = this.Optimize;
		this.generation = null;
		this.crossover = crossover;
		this.copy = copy;

		this.size = 40;
		this.crossoverRate = 0; //0..1
		this.mutation = 1; //0..1
		this.iterations = 10000;
		this.timer = 4000;
		this.fittestPercentageAlwaysSurvives = 1; //0..1
		this.fittestEntities = [];
		this.entities = [];
		this.fitnessText = document.getElementById("fitness");
	}

	Optimize(a, b) {
		return a >= b;
	}

	Tournament2(pop) {
		var n = pop.length;
		var a = pop[Math.floor(Math.random() * n)];
		var b = pop[Math.floor(Math.random() * n)];
		return this.Optimize(a.fitness, b.fitness) ? a.entity : b.entity;
	}

	Tournament3 (pop) {
		var n = pop.length;
		var a = pop[Math.floor(Math.random()*n)];
		var b = pop[Math.floor(Math.random()*n)];
		var c = pop[Math.floor(Math.random()*n)];
		var best = this.Optimize(a.fitness, b.fitness) ? a : b;
		best = this.Optimize(best.fitness, c.fitness) ? best : c;
		return best.entity;
	}

	Fittest (pop) {
		return pop[0].entity;
	}

	Random (pop) {
		return pop[Math.floor(Math.random() * pop.length)].entity;
	}

	Reproduction(pop) {
		return [this.select1.call(this, pop), this.select1.call(this, pop)];
	}

	Start () {

		var i;

		// seed the population
		for (i=0;i<this.size;++i)  {
			this.entities.push(this.seed());
		}

		for (i=0;i<this.iterations;++i) {

			// Wait a while
			setTimeout(Iterate.bind(this), this.timer * (i+1))

		}
	}
}

function Iterate(){
	let self = this;
	function mutateOrNot(entity) {
		// applies mutation based on mutation probability
		return Math.random() <= self.mutation && self.mutate ? self.mutate(entity,self.mutationType) : entity;
	}

	// score and sort
	let pop = this.entities
		.map(function (entity) {<commit_msg>Added a better Roulete Function<commit_after>class Genegen {

	constructor(seed,fitness,copy,crossover,mutate)
	{
		this.fitness = fitness;
		this.seed = seed;
		this.mutate = mutate;
		this.mutationType = slideMutate;
		this.select1 = this.Tournament2;
		this.select2 = this.Reproduction;
		this.optimize = this.Optimize;
		this.generation = null;
		this.crossover = crossover;
		this.copy = copy;

		this.size = 40;
		this.crossoverRate = 0; //0..1
		this.mutation = 1; //0..1
		this.iterations = 10000;
		this.timer = 4000;
		this.fittestPercentageAlwaysSurvives = 1; //0..1
		this.fittestEntities = [];
		this.entities = [];
		this.fitnessText = document.getElementById("fitness");
	}

	Optimize(a, b) {
		return a >= b;
	}

	Tournament2(pop) {
		var n = pop.length;
		var a = pop[Math.floor(Math.random() * n)];
		var b = pop[Math.floor(Math.random() * n)];
		return this.Optimize(a.fitness, b.fitness) ? a.entity : b.entity;
	}

	Tournament3 (pop) {
		var n = pop.length;
		var a = pop[Math.floor(Math.random()*n)];
		var b = pop[Math.floor(Math.random()*n)];
		var c = pop[Math.floor(Math.random()*n)];
		var best = this.Optimize(a.fitness, b.fitness) ? a : b;
		best = this.Optimize(best.fitness, c.fitness) ? best : c;
		return best.entity;
	}

	Fittest (pop) {
		return pop[0].entity;
	}

	Random (pop) {
		return pop[Math.floor(Math.random() * pop.length)].entity;
	}

	Reproduction(pop) {
		return [this.select1.call(this, pop), this.select1.call(this, pop)];
	}

	RouletteReproduction(pop) {

		console.log("Reproduce");
		var tickets = [];
		let sum = 0;
		// normalize
		let minScore = null;
		for(let p in pop){
			let fitness = pop[p].fitness;
			if(minScore == null) {minScore = fitness;}
			if(pop[p].fitness < minScore){minScore = fitness;}
			sum += fitness;
		}

		sum += -(pop.length * minScore);
		let percentage = 100/sum;
		for(let p in pop){
			for(let i = 0;i < ((pop[p].fitness - minScore) * percentage);i++){
				console.log(((pop[p].fitness - minScore) * percentage));
				tickets.push(pop[p]);
			}
		}

		return [this.select1.call(this, tickets), this.select1.call(this, tickets)];
	}

	Start () {

		var i;

		// seed the population
		for (i=0;i<this.size;++i)  {
			this.entities.push(this.seed());
		}

		for (i=0;i<this.iterations;++i) {

			// Wait a while
			setTimeout(Iterate.bind(this), this.timer * (i+1))

		}
	}
}

function Iterate(){
	let self = this;
	function mutateOrNot(entity) {
		// applies mutation based on mutation probability
		return Math.random() <= self.mutation && self.mutate ? self.mutate(entity,self.mutationType) : entity;
	}

	// score and sort
	let pop = this.entities
		.map(function (entity) {
{'fraction_non_alphanumeric': 0.16798970178073375, 'fraction_numerical': 0.014803690195237074, 'mean_word_length': 3.414772727272727, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4526661', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1767, 'n_words': 356}