compute¶
Not agent-based computation functions for Neuroevolution fitting.
- cneuromax.fitting.neuroevolution.utils.compute.compute_generation_results(generation_results, generation_results_batch, fitnesses_and_num_env_steps_batch, agents_batch, num_pops)[source]¶
Fills the
generation_results
array with results.Extracts the fitnesses & number of environment steps from
fitnesses_and_num_env_steps_batch
, computes the pickled agent sizes and stores all of this information ingeneration_results
.- Parameters:
generation_results (
ndarray
[Shape
[Pop_size, Num_pops, [fitness, num_env_steps, serialized_agent_size]],dtype
[float32
]] |None
) – An array maintained solely by the primary process (secondary processes have this variable set toNone
) containing several pieces of information about the results of a given generation. The 3rd dimension contains the following information at the following indices: 0) Agent fitness, 1) Number of environment steps taken by the agent during the evaluation, 2) Size of the agent when serialized.generation_results_batch (
ndarray
[Shape
[Len_agents_batch, Num_pops, [fitness, num_env_steps, serialized_agent_size]],dtype
[float32
]]) – A sub-array ofgeneration_results
maintained by the process calling this function.fitnesses_and_num_env_steps_batch (
ndarray
[Shape
[Len_agents_batch, Num_pops, [fitness, num_env_steps]],dtype
[float32
]]) – The output values of the evaluation performed inevaluate_on_cpu()
orevaluate_on_gpu()
on the agents maintained by the process calling this function.agents_batch (
list
[list
[BaseAgent
]]) – A 2D list of agents maintained by the process calling this function.
- Return type:
- cneuromax.fitting.neuroevolution.utils.compute.compute_save_points(output_dir, total_num_gens, save_interval, *, save_first_gen)[source]¶
Compute generations at which to save the state.
- Parameters:
output_dir (
str
) – Seeoutput_dir
.total_num_gens (
int
) – Seetotal_num_gens
.save_interval (
int
) – Seesave_interval
.save_first_gen (
bool
) – Seesave_first_gen
.
- Return type:
- Returns:
- The largest previous number of generations and
a list of generations at which to save the state.
- cneuromax.fitting.neuroevolution.utils.compute.compute_start_time_and_seeds(generation_results, curr_gen, num_pops, pop_size, *, pop_merge)[source]¶
Compute the start time and seeds for the current generation.
Fetches the start time and generates the seeds for the current generation. If
pop_merge
isTrue
, the seeds are shared between the populations.- Parameters:
generation_results (
ndarray
[Shape
[Pop_size, Num_pops, [fitness, num_env_steps, serialized_agent_size]],dtype
[float32
]] |None
) – Seegeneration_results
.
- Return type:
tuple
[float
|None
,ndarray
[Shape
[Pop_size, Num_pops],dtype
[uint32
]] |None
]- Returns:
- The start time for the current generation,
- cneuromax.fitting.neuroevolution.utils.compute.compute_total_num_env_steps_and_process_fitnesses(generation_results, total_num_env_steps, curr_gen, start_time, *, pop_merge)[source]¶
Processes the generation results.
- Parameters:
generation_results (
ndarray
[Shape
[Pop_size, Num_pops, [fitness, num_env_steps, serialized_agent_size]],dtype
[float32
]] |None
) – Seegeneration_results
.total_num_env_steps (
Optional
[int
]) – The total number of environment steps taken by all agents during the entire experiment. This variable is maintained solely by the primary process (secondary processes set this toNone
).start_time (
float
|None
) – Generation start time.
- Return type:
- Returns:
The updated total number of environment steps.