checkpoint_manager (faber_neuroevolution v1.2.4)
View SourceNetwork Checkpoint Manager.
This module provides network checkpointing capabilities for saving and loading evolved networks at key milestones during training.
Checkpoint Triggers
Networks are saved at configurable milestones: fitness_record - When a new best fitness is achieved generation_interval - Every N generations evaluation_interval - Every N evaluations
Storage Format
Each checkpoint is stored as an Erlang term file containing: Network binary (from network_evaluator:to_binary/1) Metadata (fitness, generation, timestamp, etc.) Configuration used during training
Summary
Functions
Generate a checkpoint filename from metadata. Format: REASON-genN-fitF-TIMESTAMP.checkpoint Uses dashes as separators since reason names may contain underscores.
Delete a specific checkpoint.
Get the current checkpoint directory.
Initialize the checkpoint manager with a configuration. Creates the checkpoint directory if it doesn't exist.
List all checkpoints in the default directory.
List all checkpoints in the specified directory. Returns a list of maps with metadata and filename for each checkpoint.
Load the checkpoint with the best fitness.
Load the checkpoint with the best fitness from a specific directory.
Load a checkpoint from a file.
Load the most recent checkpoint.
Load the most recent checkpoint from a specific directory.
Parse checkpoint information from a filename. Extracts reason, generation, fitness, and timestamp from the filename. Format: REASON-genN-fitF-TIMESTAMP.checkpoint
Prune old checkpoints, keeping only the most recent N per reason. Options: max_per_reason - Maximum checkpoints to keep per reason (default: 20) keep_best - Always keep the best fitness checkpoint (default: true)
Save a checkpoint with the given individual and metadata.
Save a checkpoint with additional options. Options: checkpoint_dir - Override the default directory compress - true (default) or false
Set the checkpoint directory.
Types
-type checkpoint() :: #{individual := individual(), metadata := checkpoint_metadata()}.
-type checkpoint_metadata() :: #{reason := checkpoint_reason(), fitness := float(), generation := non_neg_integer(), total_evaluations := non_neg_integer(), individual_id := term(), timestamp := non_neg_integer(), config => map()}.
-type checkpoint_reason() ::
fitness_record | generation_interval | evaluation_interval | manual | pre_mutation |
training_complete.
-type fitness() :: float() | undefined.
-type generation() :: non_neg_integer().
-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()}.
-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()}.
-type individual_id() :: term().
-type metrics() :: map().
-type network() :: term().
Functions
-spec checkpoint_filename(checkpoint_metadata(), file:filename()) -> file:filename().
Generate a checkpoint filename from metadata. Format: REASON-genN-fitF-TIMESTAMP.checkpoint Uses dashes as separators since reason names may contain underscores.
-spec delete_checkpoint(file:filename()) -> ok | {error, term()}.
Delete a specific checkpoint.
-spec get_checkpoint_dir() -> file:filename().
Get the current checkpoint directory.
Initialize the checkpoint manager with a configuration. Creates the checkpoint directory if it doesn't exist.
-spec list_checkpoints() -> [map()].
List all checkpoints in the default directory.
List all checkpoints in the specified directory. Returns a list of maps with metadata and filename for each checkpoint.
-spec load_best_fitness() -> {ok, individual(), checkpoint_metadata()} | {error, no_checkpoints | term()}.
Load the checkpoint with the best fitness.
-spec load_best_fitness(map()) -> {ok, individual(), checkpoint_metadata()} | {error, no_checkpoints | term()}.
Load the checkpoint with the best fitness from a specific directory.
-spec load_checkpoint(file:filename()) -> {ok, individual(), checkpoint_metadata()} | {error, term()}.
Load a checkpoint from a file.
-spec load_latest() -> {ok, individual(), checkpoint_metadata()} | {error, no_checkpoints | term()}.
Load the most recent checkpoint.
-spec load_latest(map()) -> {ok, individual(), checkpoint_metadata()} | {error, no_checkpoints | term()}.
Load the most recent checkpoint from a specific directory.
-spec parse_checkpoint_filename(file:filename()) -> {ok, map()} | {error, invalid_format}.
Parse checkpoint information from a filename. Extracts reason, generation, fitness, and timestamp from the filename. Format: REASON-genN-fitF-TIMESTAMP.checkpoint
-spec prune_checkpoints(map()) -> {ok, non_neg_integer()} | {error, term()}.
Prune old checkpoints, keeping only the most recent N per reason. Options: max_per_reason - Maximum checkpoints to keep per reason (default: 20) keep_best - Always keep the best fitness checkpoint (default: true)
-spec save_checkpoint(individual(), checkpoint_metadata()) -> ok | {error, term()}.
Save a checkpoint with the given individual and metadata.
-spec save_checkpoint(individual(), checkpoint_metadata(), map()) -> ok | {error, term()}.
Save a checkpoint with additional options. Options: checkpoint_dir - Override the default directory compress - true (default) or false
-spec set_checkpoint_dir(file:filename()) -> ok | {error, term()}.
Set the checkpoint directory.