API¶
Documentation of main public modules.
-
class
tengp.
Parameters
(n_inputs, n_outputs, n_rows, n_columns, function_set, fitness_of_invalid=inf, use_tensors=False, max_back=None, cf_individual=False)[source]¶ Contains construction parameters for CGP individual.
-
__init__
(n_inputs, n_outputs, n_rows, n_columns, function_set, fitness_of_invalid=inf, use_tensors=False, max_back=None, cf_individual=False)[source]¶ Creates Parameters object.
Parameters: - n_inputs (int) – Number of input nodes (i.e. attributes)
- n_outputs (int) – Number of output nodes
- n_rows (int) – Number of rows
- n_columns (int) – Number of columns
- function_set (FunctionSet) – instance of FunctionSet class
- fitness_of_invalid (number) – penalty fitness assigned to individual producing error
- use_tensors (bool) – if true, CGP works with tensors instead of numpy arrays
- max_back (bool) – number of previous nodes (including inputs) to which node can connect. When set to None, not limit is imposed.
- cf_individual (bool) – if set to True, cost function recieves ground truth and an individual object as an argument. Otherwise it recieves ground truth and input transformed by individual.
Returns: Parameters class instance.
-
-
tengp.
simple_es
(X, y, cost_function, params, target_fitness=None, population_size=5, evaluations=5000, random_state=None, mutation='point', mutation_probability=0.25, verbose=False, log=None, seed_individual=None)[source]¶ Optimize a CGP system using a simple evolutionary strategy.
Parameters: - X (numpy.ndarray) – input data, number of columns have to match the n_inputs parameter of Parameters object
- y (numpy.ndarray) – target output data, number of columns have to match the n_outputs parameter of Parameters object
- cost_function (callable) – cost function to minimize. It has two arguments (y_true, y_pred), where y_true is target output data and y_pred is output of CGP individual
- params (Parameters) – instance of Parameters class
- target_fitness (number or None) – fitness, at which evolution will stop. If None, it is not considered
- population_size (int) – size of population including parent
- evaluations (int) – maximum number of cost function evaluations
- random_state (int) – seed for random number generator
- mutation (string) – type of mutation to use, accept values ‘point’, ‘active’, ‘single’, ‘probabilistic’
- mutation_probability (float) – probability of mutating a given gene ( used only when mutation argument is set to ‘probabilistic’
- verbose (bool) – if True, outputs evolution info every 100 generations
- log (list) – if provided with a list, best fitness of each generation is stored here
- seed_individual (Individual) – if provided with instance of Individual class, the initial population is created according to this object - parent of first generation.
Returns: List of individuals, the last generation of evolution
-
class
tengp.individual.
NPIndividual
(genes, bounds, params)[source]¶ -
transform
(X)[source]¶ Transforms the input data with expression encoded in individual.
Parameters: X (array-like) – 2D Numpy array, or tensor (if use_tensors was set to true in Parameters) Returns: Transformed data. If use_tensors was set to true, then list containing output tensors is returned. Otherwise Numpy array is returned.
-