Active sampling helper methods

melissa.server.deep_learning.active_learning.main module defines methods useful for performing active sampling parameter generation, checkpointing, triggering resampling events.

make_parameter_sampler(sampler_t, non_breed_sampler_t=None, sliding_window_size=None, **kwargs)

Creates and returns an instance of a parameter sampler based on the specified sampler type.

This method supports predefined sampler types from ParameterSamplerType and custom sampler classes derived from ExperimentBreeder. It can also handle the creation of breeding samplers, with optional configurations for non-breeding samplers and sliding window size for breeding.

Parameters:
  • sampler_t (Union[ParameterSamplerType, Type[T]]):
    • ParameterSamplerType: An enum value representing a predefined parameter sampler type (DEFAULT_BREED only).
    • Type[T]: A custom sampler class that should inherit from ExperimentBreeder or a subclass of it.
  • non_breed_sampler_t (Optional[ParameterSamplerType]): The sampler type used for non-breeding simulations. Defaults to RANDOM_UNIFORM, if not specified.
  • sliding_window_size (Optional[int]): The size of the sliding window for breeding (only relevant when using breeding samplers). Must be specified when using breeding algorithms.
  • kwargs: Additional keyword arguments passed to the constructor of the chosen sampler.
Returns:
  • ExperimentBreeder: An instance of the selected parameter sampler.
Raises:
  • NotImplementedError: If the provided sampler_t is not a valid ParameterSamplerType or a subclass of ExperimentBreeder.
  • AssertionError: If a breeding sampler is selected and sliding_window_size is not provided.

get_current_parameters()

Retrieves the current parameters from the active parameter sampler.

This method checks if a parameter sampler (__SAMPLER) is active and, if so, calls its get_current_parameters method to fetch the current parameter values, If no active sampler is present, it returns None.

Returns
  • Optional[NDArray]: The current parameters as a NumPy array (if a sampler is active) None if no sampler is set.

get_breeding_status_per_parameter()

Retrieves the breeding status of each parameter in the active parameter sampler.

This method checks if the active parameter sampler is an instance of DefaultBreeder. If so, it calls the get_breeding_status_per_parameter method from the DefaultBreeder instance to get the breeding status of each parameter. If no active sampler or an incompatible sampler is present, it returns None.

Returns
  • Optional[NDArray[np.bool_]]: An array indicating the breeding status (True for bred, False for non-bred) of each parameter if a DefaultBreeder is active, or None if no compatible sampler is set.

trigger_sampling(**kwargs)

Triggers the active sampling process to update parameters based on the given arguments.

This method checks if a resampling event is already in progress. If not, it triggers the active sampling process by calling the _update_parameters method with the provided keyword arguments. It also sets a resample event flag to prevent overlapping sampling events. In case of an error during sampling, the exception is logged, and subsequent triggers are disabled.

Parameters
  • **kwargs: Keyword arguments passed to the _update_parameters method.
Returns
  • bool: if sampling was successfully triggered.
Raises
  • ActiveSamplingError: If any error occurs during the sampling process.

get_sampler()

Returns the current sampler instance of ExperimentBreeder.

checkpoint_state()

Calls checkpointing method of the sampler to store the parameters as well as other breed statistics.

restart_from_checkpoint()

Calls to load from checkpointing method of the sampler that stores the parameters as well as other breed statistics.

get_resampling_event()

Returns the threading.Event associated with resampling triggers.

_update_parameters(**kwargs)

Updates the parameters in the active parameter sampler.

This method checks if there is an active parameter sampler (__SAMPLER). If so, it resets the index of the sampler, retrieves the next set of parameters using the next_parameters method, and then updates the parameters using set_parameters if new parameters are provided.

Parameters
  • **kwargs: Keyword arguments passed to the next_parameters method.

set_tb_logger(tb_logger)

Assign the existing TensorboardLogger object for logging information while breeding.

exception()

Returns exception to be raised from the server.

__free()

Deallocate the sampler.