cotengra.experimental.hyper_pe ============================== .. py:module:: cotengra.experimental.hyper_pe .. autoapi-nested-parse:: Hyper optimization using parallel evolution with ranked sigma assignment. Classes ------- .. autoapisummary:: cotengra.experimental.hyper_pe.HyperPESampler cotengra.experimental.hyper_pe.PEOptLib Module Contents --------------- .. py:class:: HyperPESampler(space, seed=None, population_size=8, sigma_min=0.01, sigma_max=0.5, elite_migrate_prob=0.0, differential_prob=0.0, patience=None, exponential_param_power=None) A parallel evolution optimizer operating in raw ``[-1, 1]`` space. Multiple workers each maintain their own solution. Perturbation scales (sigmas) are distributed across an evenly spaced range and reassigned by rank after each generation: the best-scoring worker gets the lowest sigma (exploit) and the worst gets the highest (explore). :param space: The search space for a single contraction method. :type space: dict[str, dict] :param seed: Random seed. :type seed: None or int, optional :param population_size: The number of parallel workers. When ``"auto"`` it is chosen based on the mapped parameter dimension. :type population_size: int or "auto", optional :param sigma_min: The smallest perturbation scale (assigned to the best worker). :type sigma_min: float, optional :param sigma_max: The largest perturbation scale (assigned to the worst worker). :type sigma_max: float, optional :param elite_migrate_prob: Probability each generation of copying the best worker's solution to the worst worker's slot. :type elite_migrate_prob: float, optional :param differential_prob: Per-sample probability of using a differential perturbation (``x_best - x_rand``) instead of Gaussian noise. :type differential_prob: float, optional :param patience: If a worker has not improved for this many generations, re-randomize its solution. ``None`` or ``0`` disables. :type patience: int or None, optional :param exponential_param_power: Passed through to the shared parameter mapping for ``FLOAT_EXP`` parameters. :type exponential_param_power: float, optional .. py:attribute:: rng .. py:attribute:: params .. py:attribute:: ndim .. py:attribute:: population_size :value: 8 .. py:attribute:: sigma_min :value: 0.01 .. py:attribute:: sigma_max :value: 0.5 .. py:attribute:: elite_migrate_prob :value: 0.0 .. py:attribute:: differential_prob :value: 0.0 .. py:attribute:: patience :value: None .. py:attribute:: _solutions .. py:attribute:: _scores .. py:attribute:: _stagnation :value: [0, 0, 0, 0, 0, 0, 0, 0] .. py:attribute:: _sigmas .. py:attribute:: _trial_counter :value: 0 .. py:attribute:: _generation :value: None .. py:attribute:: _trial_map .. py:method:: _make_sigmas() Create geometrically spaced sigmas from sigma_min to sigma_max. .. py:method:: _sample_candidate(worker_idx, noise=None) Perturb a worker's current solution with its assigned sigma. .. py:method:: _sample_generation() Start a new generation with one trial per worker. .. py:method:: _extend_generation(worker_idx=None, noise=None) Append one more trial to the current generation. .. py:method:: ask() Return the next candidate from the current generation. If all prepared candidates have been issued, grow the generation by one more sample. .. py:method:: tell(trial_number, score) Record a completed trial and update workers if the generation is complete. For each trial, if it scores better than (or equal to) its worker's current best, the worker adopts the new solution. Then sigmas are reassigned by rank: best worker gets lowest sigma, worst gets highest. .. py:class:: PEOptLib Bases: :py:obj:`cotengra.experimental.hyper.HyperOptLib` Hyper-optimization using parallel evolution with ranked sigmas. .. py:method:: setup(methods, space, optimizer=None, population_size='auto', sigma_min=0.01, sigma_max=0.5, elite_migrate_prob=0.5, differential_prob=0.5, patience=8, method_exploration=1.0, method_temperature=1.0, exponential_param_power=None, seed=None, **kwargs) Initialize PE optimizers for each contraction method. :param methods: The contraction methods to optimize over. :type methods: list[str] :param space: The per-method hyperparameter search space. :type space: dict[str, dict[str, dict]] :param optimizer: The parent optimizer. Used to size the initial population large enough for parallel pre-dispatch. :type optimizer: HyperOptimizer, optional :param population_size: The number of parallel workers for each method. :type population_size: int or "auto", optional :param sigma_min: Smallest perturbation scale (for the best-ranked worker). :type sigma_min: float, optional :param sigma_max: Largest perturbation scale (for the worst-ranked worker). :type sigma_max: float, optional :param elite_migrate_prob: Probability of copying best solution to worst worker. :type elite_migrate_prob: float, optional :param differential_prob: Per-sample probability of differential perturbation. :type differential_prob: float, optional :param patience: Generations without improvement before restart. :type patience: int or None, optional :param method_exploration: Exploration strength for the LCB-based method chooser. :type method_exploration: float, optional :param method_temperature: Noise temperature for the LCB-based method chooser. :type method_temperature: float, optional :param exponential_param_power: Passed to the shared parameter mapping for ``FLOAT_EXP``. :type exponential_param_power: float, optional :param seed: Random seed. :type seed: None or int, optional .. py:method:: get_setting() Choose a contraction method, then request its next setting. .. py:method:: report_result(setting, trial, score) Report a completed trial back to the method chooser and PE.