Jido.Evolve.State (Jido Evolve v1.0.0)

Copy Markdown View Source

Represents the state of an evolutionary algorithm at a given generation.

This structure tracks the current population, their fitness scores, and metadata about the evolution process.

Summary

Functions

Calculate diversity of the current population.

Create a new state from attributes.

Create a new initial state from a population and config.

Create a new state, raising on validation errors.

Update the population and advance the generation counter.

Add metadata to the state.

Check if termination criteria are met.

Update the state with new fitness scores.

Types

t()

@type t() :: %Jido.Evolve.State{
  average_score: number(),
  best_entity: nil | nil | any(),
  best_score: number(),
  config: %Jido.Evolve.Config{
    checkpoint_interval: nil | nil | integer(),
    crossover_rate: number(),
    crossover_strategy: atom(),
    elitism_rate: number(),
    evaluation_timeout: integer() | :infinity,
    generations: integer(),
    max_concurrency: integer(),
    metrics_enabled: boolean(),
    mutation_rate: number(),
    mutation_strategy: atom(),
    population_size: integer(),
    random_seed: nil | nil | integer(),
    selection_pressure: number(),
    selection_strategy: atom(),
    termination_criteria: [
      max_generations: integer(),
      target_fitness: number(),
      no_improvement: integer()
    ],
    tournament_size: integer()
  },
  diversity: number(),
  fitness_history: [number()],
  generation: integer(),
  metadata: map(),
  population: [any()],
  scores: map()
}

Functions

calculate_diversity(state)

@spec calculate_diversity(t()) :: t()

Calculate diversity of the current population.

This is useful for monitoring convergence and maintaining diversity.

new(attrs)

@spec new(map() | keyword()) :: {:ok, t()} | {:error, term()}

Create a new state from attributes.

new(population, config)

@spec new([any()], Jido.Evolve.Config.t()) :: t()

Create a new initial state from a population and config.

Examples

iex> config = Jido.Evolve.Config.new!()
iex> state = Jido.Evolve.State.new(["a", "b", "c"], config)
iex> state.population
["a", "b", "c"]

new!(attrs)

@spec new!(map() | keyword()) :: t()

Create a new state, raising on validation errors.

next_generation(state, new_population)

@spec next_generation(t(), [any()]) :: t()

Update the population and advance the generation counter.

put_metadata(state, key, value)

@spec put_metadata(t(), atom() | String.t(), term()) :: t()

Add metadata to the state.

terminated?(state)

@spec terminated?(t()) :: boolean()

Check if termination criteria are met.

update_scores(state, scores)

@spec update_scores(t(), map()) :: t()

Update the state with new fitness scores.

This recalculates the best entity, best score, and average score.