Diffusion Evolution¶
DiffusionEvolution ¶
DiffusionEvolution(population_size: int, solution: Solution, num_generations: int = 128, fitness_mapping: Callable = fitness_mapping_energy, alpha_schedule: Callable = cosine_schedule, num_latent_dims: int | None = None, fitness_shaping_fn: Callable = identity_fitness_shaping_fn, metrics_fn: Callable = metrics_fn)
Bases: PopulationBasedAlgorithm
Diffusion Evolution.
Treats the generations as the steps of a reverse diffusion process. ask maps
the stored fitness to weights with fitness_mapping, estimates a denoised
target for every member as a weighted average of the stored population and
moves the members towards it with a DDIM step from params.alphas. tell
replaces the stored population and fitness with the evaluated candidates.
Parameters:
-
population_size(int) –Number of candidate solutions sampled and evaluated per generation.
-
solution(Solution) –Example solution PyTree. Only its structure and leaf shapes are used: they set the number of search dimensions and how flat search vectors are unravelled into the PyTrees returned by
ask. -
num_generations(int, default:128) –Number of entries of the alpha schedule stored in the default params.
askreads the entries atgeneration_counterandgeneration_counter + 1. -
fitness_mapping(Callable, default:fitness_mapping_energy) –Function mapping the stored fitness to non-negative weights, where a higher weight marks a better member.
-
alpha_schedule(Callable, default:cosine_schedule) –Function called as
alpha_schedule(num_step=...)that returns the array of alphas, e.g.cosine_schedule,ddim_scheduleorddpm_schedule. Its output is reversed before it is stored in the default params. -
num_latent_dims(int | None, default:None) –If given,
initdraws a random Gaussian matrix that projects the population to this many dimensions; the distances between members that enter the weighted average are computed in that latent space. If None, distances are computed in the search space. -
fitness_shaping_fn(Callable, default:identity_fitness_shaping_fn) –Function
(population, fitness, state, params) -> shaped_fitnessapplied to the raw fitness intellbefore the algorithm update. Seeevosax.core.fitness_shaping. -
metrics_fn(Callable, default:metrics_fn) –Function
(key, population, fitness, state, params) -> metricsevaluated intell; its output is returned alongside the new state.
References
default_params
property
¶
Default hyperparameters of the algorithm.
Returns a Params dataclass. Use params.replace(...) to override
individual hyperparameters before passing it to init, ask and tell.
init ¶
Initialize the algorithm state from an evaluated population.
Parameters:
-
key(Array) –PRNG key.
-
population(Population) –Initial population, a PyTree with the structure of
solutionand a leading population axis on every leaf. -
fitness(Fitness) –Raw fitness of the initial population. Lower is better. NaN values mark failed evaluations and never become the best solution.
-
params(Params) –Algorithm hyperparameters, e.g.
default_params.
Returns:
-
State–The initial algorithm state.
ask ¶
Ask for a population of candidate solutions to evaluate.
Parameters:
-
key(Array) –PRNG key.
-
state(Any) –Current algorithm state.
-
params(Any) –Algorithm hyperparameters.
Returns:
-
tuple[Population, Any]–A tuple
(population, state).populationis a PyTree with the structure ofsolutionand a leading axis of sizepopulation_size.
tell ¶
tell(key: Array, population: Population, fitness: Fitness, state: Any, params: Any) -> tuple[Any, Metrics]
Update the algorithm state with the fitness of a population.
Parameters:
-
key(Array) –PRNG key.
-
population(Population) –Population returned by
ask. -
fitness(Fitness) –Fitness of each population member, shape
(population_size,). Lower is better. NaN values mark failed evaluations and never become the best solution. -
state(Any) –Algorithm state returned by
ask. -
params(Any) –Algorithm hyperparameters.
Returns:
-
tuple[Any, Metrics]–A tuple
(state, metrics)with the updated state and the output ofmetrics_fn.
get_best_solution ¶
Return the best member of the stored population as a solution PyTree.
This is the member with the lowest shaped fitness in the current
population; the best solution seen over the whole run is kept in
state.best_solution. Unlike state.best_solution, this does not skip
NaN fitness values.
get_population ¶
Return the stored population as a PyTree with a leading population axis.