slim main files

slim_gsgp.main_gp

This script runs the StandardGP algorithm on various datasets and configurations, logging the results for further analysis.

slim_gsgp.main_gp.gp(X_train: Tensor, y_train: Tensor, X_test: Tensor | None = None, y_test: Tensor | None = None, dataset_name: str | None = None, pop_size: int = 100, n_iter: int = 1000, p_xo: float = 0.8, elitism: bool = True, n_elites: int = 1, max_depth: int | None = 17, init_depth: int = 6, log_path: str | None = None, seed: int = 74, log_level: int = 1, verbose: int = 1, minimization: bool = True, fitness_function: str = 'rmse', initializer: str = 'rhh', n_jobs: int = 1, prob_const: float = 0, tree_functions: list = ['add', 'subtract', 'multiply', 'divide'], tree_constants: list = [2.0, 3.0, 4.0, 5.0, -1.0], tournament_size: int = 2, test_elite: bool = True)[source]

Main function to execute the StandardGP algorithm on specified datasets

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

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

  • X_test ((torch.Tensor), optional) – Testing input data.

  • y_test ((torch.Tensor), optional) – Testing output data.

  • dataset_name (str, optional) – Dataset name, for logging purposes

  • pop_size (int, optional) – The population size for the genetic programming algorithm (default is 100).

  • n_iter (int, optional) – The number of iterations for the genetic programming algorithm (default is 100).

  • p_xo (float, optional) – The probability of crossover in the genetic programming algorithm. Must be a number between 0 and 1 (default is 0.8).

  • elitism (bool, optional) – Indicate the presence or absence of elitism.

  • n_elites (int, optional) – The number of elites.

  • max_depth (int, optional) – The maximum depth for the GP trees.

  • init_depth (int, optional) – The depth value for the initial GP trees population.

  • log_path (str, optional) – The path where is created the log directory where results are saved. Defaults to os.path.join(os.getcwd(), “log”, “gp.csv”)

  • seed (int, optional) – Seed for the randomness

  • log_level (int, optional) – Level of detail to utilize in logging.

  • verbose (int, optional) – Level of detail to include in console output.

  • minimization (bool, optional) – If True, the objective is to minimize the fitness function. If False, maximize it (default is True).

  • fitness_function (str, optional) – The fitness function used for evaluating individuals (default is from gp_solve_parameters).

  • initializer (str, optional) – The strategy for initializing the population (e.g., “grow”, “full”, “rhh”).

  • n_jobs (int, optional) – Number of parallel jobs to run (default is 1).

  • prob_const (float, optional) – The probability of a constant being chosen rather than a terminal in trees creation (default: 0.2).

  • tree_functions (list, optional) – List of allowed functions that can appear in the trees. Check documentation for the available functions.

  • tree_constants (list, optional) – List of constants allowed to appear in the trees.

  • tournament_size (int, optional) – Tournament size to utilize during selection. Only applicable if using tournament selection. (Default is 2)

  • test_elite (bool, optional) – Whether to test the elite individual on the test set after each generation.

Returns:

Returns the best individual at the last generation.

Return type:

Tree

slim_gsgp.main_gsgp

This script runs the StandardGSGP algorithm on various datasets and configurations, logging the results for further analysis.

slim_gsgp.main_gsgp.gsgp(X_train: Tensor, y_train: Tensor, X_test: Tensor | None = None, y_test: Tensor | None = None, dataset_name: str | None = None, pop_size: int = 100, n_iter: int = 1000, p_xo: float = 0.0, elitism: bool = True, n_elites: int = 1, init_depth: int = 8, ms_lower: float = 0, ms_upper: float = 1, log_path: str | None = None, seed: int = 74, log_level: int = 1, verbose: int = 1, reconstruct: bool = False, fitness_function: str = 'rmse', initializer: str = 'rhh', minimization: bool = True, prob_const: float = 0.2, tree_functions: list = ['add', 'subtract', 'multiply', 'divide'], tree_constants: list = [2.0, 3.0, 4.0, 5.0, -1.0], n_jobs: int = 1, tournament_size: int = 2, test_elite: bool = True)[source]

Main function to execute the Standard GSGP algorithm on specified datasets

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

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

  • X_test ((torch.Tensor), optional) – Testing input data.

  • y_test ((torch.Tensor), optional) – Testing output data.

  • dataset_name (str, optional) – Dataset name, for logging purposes

  • pop_size (int, optional) – The population size for the genetic programming algorithm (default is 100).

  • n_iter (int, optional) – The number of iterations for the genetic programming algorithm (default is 100).

  • p_xo (float, optional) – The probability of crossover in the genetic programming algorithm. Must be a number between 0 and 1 (default is 0.8).

  • elitism (bool, optional) – Indicate the presence or absence of elitism.

  • n_elites (int, optional) – The number of elites.

  • init_depth (int, optional) – The depth value for the initial GP trees population.

  • ms_lower (float, optional) – Lower bound for mutation rates (default is 0).

  • ms_upper (float, optional) – Upper bound for mutation rates (default is 1).

  • log_path (str, optional) – The path where is created the log directory where results are saved.

  • seed (int, optional) – Seed for the randomness

  • log_level (int, optional) – Level of detail to utilize in logging.

  • verbose (int, optional) – Level of detail to include in console output.

  • reconstruct (bool, optional) – Whether to store the structure of individuals. More computationally expensive, but allows usage outside the algorithm.

  • minimization (bool, optional) – If True, the objective is to minimize the fitness function. If False, maximize it (default is True).

  • fitness_function (str, optional) – The fitness function used for evaluating individuals (default is from gp_solve_parameters).

  • initializer (str, optional) – The strategy for initializing the population (e.g., “grow”, “full”, “rhh”).

  • n_jobs (int, optional) – Number of parallel jobs to run (default is 1).

  • prob_const (float, optional) – The probability of a constant being chosen rather than a terminal in trees creation (default: 0.2).

  • tree_functions (list, optional) – List of allowed functions that can appear in the trees. Check documentation for the available functions.

  • tree_constants (list, optional) – List of constants allowed to appear in the trees.

  • tournament_size (int, optional) – Tournament size to utilize during selection. Only applicable if using tournament selection. (Default is 2)

  • test_elite (bool, optional) – Whether to test the elite individual on the test set after each generation.

Returns:

Returns the best individual at the last generation.

Return type:

Tree

slim_gsgp.main_slim