<commit_before>/* Copyright 2014 <NAME>
 *
 * Source file for base problem class
 */

#include "problem.hpp"

Problem::Problem(const double dn,
		 const double dx,
		 const double rn,
		 const double rx,
		 const bool z,
		 const double g,
		 const double f,
		 const double d,
		 const double h,
		 const int c,
		 const long i) : domain_min(dn),
				 domain_max(dx),
				 range_min(rn),
				 range_max(rx),
				 minimize(z),
				 range_dis(dn, dx),
				 delta_dis(-d, d),
				 goal(g),
				 filter(f),
				 delta(d),
				 chance(h),
				 constant(c),
				 iterations(i) {};

double Problem::fitness(const Individual * subject) const {
  // Scales problem value [min, max] to double [0, 1] with 1 being max fitness
  double sum = this->problem(subject);
  double fitness = ((sum - range_min) / (range_max - range_min)); // normalize
  if (minimize) fitness = 1. - fitness; // inverse if trying to minimize
  return fitness;
}

const Individual * Problem::potential() const {
  Individual * potential = new Individual(domain_min, domain_max, range_dis);
  return potential;
}

const Individual * Problem::mutate(const Individual * subject) {
  const double delta = delta_dis(rg->gen);
  const Individual * mutated = subject->mutate(delta, chance);
  return mutated;
}
<commit_msg>Scaling problem delta to range per Terry's advice<commit_after>/* Copyright 2014 <NAME>
 *
 * Source file for base problem class
 */

#include <cmath>

#include "problem.hpp"

Problem::Problem(const double dn,
		 const double dx,
		 const double rn,
		 const double rx,
		 const bool z,
		 const double g,
		 const double f,
		 const double d,
		 const double h,
		 const int c,
		 const long i) : domain_min(dn),
				 domain_max(dx),
				 range_min(rn),
				 range_max(rx),
				 minimize(z),
				 range_dis(dn, dx),
				 delta_dis(-d*(std::abs(dn) + std::abs(dx))/2,
					   d*(std::abs(dn) + std::abs(dx))/2),
				 goal(g),
				 filter(f),
				 delta(d),
				 chance(h),
				 constant(c),
				 iterations(i) {};

double Problem::fitness(const Individual * subject) const {
  // Scales problem value [min, max] to double [0, 1] with 1 being max fitness
  double sum = this->problem(subject);
  double fitness = ((sum - range_min) / (range_max - range_min)); // normalize
  if (minimize) fitness = 1. - fitness; // inverse if trying to minimize
  return fitness;
}

const Individual * Problem::potential() const {
  Individual * potential = new Individual(domain_min, domain_max, range_dis);
  return potential;
}

const Individual * Problem::mutate(const Individual * subject) {
  const double delta = delta_dis(rg->gen);
  const Individual * mutated = subject->mutate(delta, chance);
  return mutated;
}

{'fraction_non_alphanumeric': 0.12658227848101267, 'fraction_numerical': 0.006701414743112435, 'mean_word_length': 3.3691056910569106, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 12, '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': '6218367', 'n_tokens_mistral': 974, 'n_tokens_neox': 795, 'n_words': 269}