Jido.Evolve.Mutation behaviour (Jido Evolve v1.0.0)

Copy Markdown View Source

Behaviour for mutation strategies.

Mutation introduces variation into the population by modifying entities in various ways.

Summary

Callbacks

Mutate an entity.

Mutate an entity with feedback from previous evaluations.

Calculate mutation strength based on generation number.

Types

entity()

@type entity() :: term()

feedback()

@type feedback() :: map()

opts()

@type opts() :: keyword()

Callbacks

mutate(entity, opts)

@callback mutate(entity(), opts()) :: {:ok, entity()} | {:error, term()}

Mutate an entity.

The mutation should introduce variation while preserving the general structure of the entity.

Options

  • :rate - Mutation rate (0.0 to 1.0), defaults to 0.1
  • :strength - Mutation strength (0.0 to 1.0), defaults to 0.5

Examples

def mutate(entity, opts) do
  rate = Keyword.get(opts, :rate, 0.1)
  # Apply mutations based on rate
  {:ok, mutated_entity}
end

mutate_with_feedback(entity, feedback, opts)

(optional)
@callback mutate_with_feedback(entity(), feedback(), opts()) ::
  {:ok, entity()} | {:error, term()}

Mutate an entity with feedback from previous evaluations.

This allows for more intelligent mutations that take into account what has worked well in the past.

mutation_strength(integer)

(optional)
@callback mutation_strength(integer()) :: float()

Calculate mutation strength based on generation number.

This allows for adaptive mutation rates that change over time, typically starting high for exploration and decreasing for exploitation.