elixir_evaluator_bridge (faber_neuroevolution v1.2.4)

View Source

Bridge module for calling Elixir evaluators from Erlang.

This module implements the neuroevolution_evaluator behaviour and provides a bridge to call Elixir evaluator modules from the Erlang neuroevolution_server.

Usage

Configure neuroevolution_server with this module as the evaluator. Set evaluator_module to elixir_evaluator_bridge and provide elixir_module and elixir_options in evaluator_options.

The Elixir module must export: - evaluate/2 - Takes (IndividualMap, Options), returns ok tuple or error

Summary

Functions

Calculate fitness from metrics.

Evaluate an individual using an Elixir module.

Types

fitness/0

-type fitness() :: float() | undefined.

generation/0

-type generation() :: non_neg_integer().

genome/0

-type genome() ::
          #genome{connection_genes ::
                      [#connection_gene{innovation :: pos_integer() | undefined,
                                        from_id :: term(),
                                        to_id :: term(),
                                        weight :: float(),
                                        enabled :: boolean()}],
                  input_count :: non_neg_integer(),
                  hidden_count :: non_neg_integer(),
                  output_count :: non_neg_integer()}.

individual/0

-type individual() ::
          #individual{id :: individual_id(),
                      network :: network(),
                      genome :: genome() | undefined,
                      parent1_id :: individual_id() | undefined,
                      parent2_id :: individual_id() | undefined,
                      fitness :: fitness(),
                      metrics :: metrics(),
                      generation_born :: generation(),
                      birth_evaluation :: non_neg_integer(),
                      max_age :: pos_integer(),
                      is_survivor :: boolean(),
                      is_offspring :: boolean()}.

individual_id/0

-type individual_id() :: term().

metrics/0

-type metrics() :: map().

network/0

-type network() :: term().

Functions

calculate_fitness(Metrics)

-spec calculate_fitness(map()) -> float().

Calculate fitness from metrics.

This is used when fitness needs to be computed from raw metrics. The Elixir evaluator typically returns fitness directly in the metrics map.

evaluate(Individual, Options)

-spec evaluate(individual(), map()) -> {ok, individual()} | {error, term()}.

Evaluate an individual using an Elixir module.

The Options map must contain: - elixir_module: The Elixir module atom (e.g., 'Elixir.MyApp.Evaluator') - elixir_options: Options to pass to the Elixir evaluator (optional) - games: Number of evaluation games/episodes (optional, passed to Elixir) - notify_pid: PID to notify of progress (optional)