slim_gsgp.algorithms.GP

slim_gsgp.algorithms.GP.gp

Genetic Programming (GP) module.

class slim_gsgp.algorithms.GP.gp.GP(pi_init, initializer, selector, mutator, crossover, find_elit_func, p_m=0.2, p_xo=0.8, pop_size=100, seed=0, settings_dict=None)[source]

Bases: object

evolve_population(population, ffunction, max_depth, depth_calculator, elitism, X_train, y_train, n_jobs=1)[source]

Evolve the population for one iteration (generation).

Parameters:
  • population (Population) – The current population of individuals to evolve.

  • ffunction (function) – Fitness function used to evaluate individuals.

  • max_depth (int) – Maximum allowable depth for trees in the population.

  • depth_calculator (Callable) – Function used to calculate the depth of trees.

  • elitism (bool) – Whether to use elitism, i.e., preserving the best individuals across generations.

  • X_train (torch.Tensor) – Input training data features.

  • y_train (torch.Tensor) – Target values for the training data.

  • n_jobs (int, optional) – Number of parallel jobs to use with the joblib library (default is 1).

Returns:

  • Population – The evolved population after one generation.

  • float – The start time of the evolution process.

log_generation(generation, population, elapsed_time, log, log_path, run_info)[source]

Log the results for the current generation.

Parameters:
  • generation (int) – Current generation (iteration) number.

  • population (Population) – Current population.

  • elapsed_time (float) – Time taken for the process.

  • log (int) – Logging level.

  • log_path (str) – Path to save logs.

  • run_info (list) – Information about the current run.

Returns:

None

solve(X_train, X_test, y_train, y_test, curr_dataset, n_iter=20, elitism=True, log=0, verbose=0, test_elite=False, log_path=None, run_info=None, max_depth=None, ffunction=None, n_elites=1, depth_calculator=None, n_jobs=1)[source]

Execute the Genetic Programming algorithm.

Parameters:
  • X_train (torch.Tensor) – Training data features.

  • X_test (torch.Tensor) – Test data features.

  • y_train (torch.Tensor) – Training data labels.

  • y_test (torch.Tensor) – Test data labels.

  • curr_dataset (str) – Current dataset name.

  • n_iter (int, optional) – Number of iterations. Default is 20.

  • elitism (bool, optional) – Whether to use elitism. Default is True.

  • log (int, optional) – Logging level. Default is 0.

  • verbose (int, optional) – Verbosity level. Default is 0.

  • test_elite (bool, optional) – Whether to evaluate elite individuals on test data. Default is False.

  • log_path (str, optional) – Path to save logs. Default is None.

  • run_info (list, optional) – Information about the current run. Default is None.

  • max_depth (int, optional) – Maximum depth of the tree. Default is None.

  • ffunction (function, optional) – Fitness function. Default is None.

  • n_elites (int, optional) – Number of elites. Default is 1.

  • depth_calculator (function, optional) – Function to calculate tree depth. Default is None.

  • n_jobs (int, optional) – The number of jobs for parallel processing. Default is 1.