Generation#

class empulse.optimizers.Generation(population_size=None, crossover_rate=0.8, mutation_rate=0.1, elitism=0.05, verbose=False, logging_fn=<built-in function print>, random_state=None, n_jobs=1)[source]#

A single generation of a Real-coded Genetic Algorithm (RGA).

Read more in the User Guide.

Parameters:
population_sizeint or None, default=None

Number of individuals in the population. If None, population size is set to 10 * n_dim.

crossover_ratefloat, default=0.8

Probability of crossover. Must be in [0, 1].

mutation_ratefloat, default=0.1

Probability of mutation. Must be in [0, 1].

elitismfloat, default=0.05

Fraction of the population that is considered elite. Must be in [0, 1].

verbosebool, default=False

If True, print status messages.

logging_fncallable, default=print

Function to use for logging.

random_stateint or None, default=None

Random seed.

n_jobsint or None, default=1

Number of jobs to run in parallel. If -1, use all available processors. If None, use 1 processor.

Attributes:
namestr

Name of the optimizer.

populationndarray, shape (population_size, n_dim)

Current population.

population_sizeint

Number of individuals in the population.

crossover_ratefloat

Probability of crossover.

mutation_ratefloat

Probability of mutation.

elitismfloat

Fraction of the population that is considered elite.

verbosebool

If True, print status messages.

logging_fncallable

Function to use for logging.

rngRandomState

Random state object.

n_jobsint

Number of jobs to run in parallel. If -1, use all available processors. If None, use 1 processor.

fx_bestlist

List of best fitness values.

fitnessndarray, shape (population_size,)

Fitness values of the current population.

resultOptimizeResult

Result of the optimization.

lower_boundsndarray, shape (n_dim,)

Lower bounds of the search space.

upper_boundsndarray, shape (n_dim,)

Upper bounds of the search space.

delta_boundsndarray, shape (n_dim,)

Difference between upper and lower bounds.

n_dimint

Number of dimensions.

_n_mating_pairsint

Number of mating pairs.

elite_poollist

List of elite individuals.

optimize(objective, bounds)[source]#

Optimize the objective function.

Parameters:
objectiveCallable

Objective function to optimize. Should be of signature objective(weights) -> float.

boundslist[tuple[float, float]]

List of tuples of lower and upper bounds for each weight.

Yields:
selfGeneration

Current instance of the optimizer.