gpridge.policy ============== .. py:module:: gpridge.policy .. autoapi-nested-parse:: Training policies for the accelerated searches. A policy decides whether a search calls the true potential, which measured rows enter the training set, and whether the hyperparameters are refit. ``None`` leaves every decision with the engine. :class:`DefaultPolicy` asks the same questions and returns the engine's answers. Classes ------- .. autoapisummary:: gpridge.policy.DefaultPolicy gpridge.policy.SizeCapPolicy gpridge.policy.DistanceDedupPolicy gpridge.policy.VarianceThresholdPolicy gpridge.policy.FreezeHyperparametersPolicy Functions --------- .. autoapisummary:: gpridge.policy.farthest_point_indices Module Contents --------------- .. py:function:: farthest_point_indices(rows, max_size) Indices of a farthest-point subset, in the original order. Row 0 stays. Each later row is the one whose Euclidean distance to the nearest kept row is largest. Ties take the lowest index. ``max_size`` is at least 1. A set that is already small enough is returned unchanged. .. py:class:: DefaultPolicy The engine's own answers, as a policy object. .. py:method:: should_call_oracle(state) .. py:method:: select_training_points(candidates, current_set) .. py:method:: should_retrain_hyperparameters(state) .. py:method:: should_rebuild_factor(state) .. py:method:: retain_training_rows(rows) .. py:class:: SizeCapPolicy(max_size) Keep at most ``max_size`` training rows. New rows are admitted. The stored set is then reduced to ``max_size`` by :func:`farthest_point_indices`. ``max_size`` is an integer of at least 1. .. py:attribute:: max_size .. py:method:: retain_training_rows(rows) .. py:class:: DistanceDedupPolicy(min_distance) Drop a candidate closer than ``min_distance`` to a kept row. The distance is the Euclidean norm of the flat position difference, in the same length unit as the coordinates. A candidate is kept when that distance is greater than or equal to ``min_distance``, measured against the current training set and against candidates accepted earlier in the same call. ``min_distance`` is finite and positive. .. py:attribute:: min_distance .. py:method:: select_training_points(candidates, current_set) .. py:class:: VarianceThresholdPolicy(variance_threshold) Call the oracle only when the posterior energy variance is high. ``variance_threshold`` is the energy variance, in eV^2, above which a call the engine already wants is allowed. A variance that is not finite (no posterior yet) defers to the engine. A call the engine declined is not forced. The comparison is strict: a variance equal to the threshold does not call. .. py:attribute:: variance_threshold .. py:method:: should_call_oracle(state) .. py:class:: FreezeHyperparametersPolicy(freeze_after_oracle_calls) Stop hyperparameter optimisation after ``freeze_after_oracle_calls``. While ``state.oracle_calls`` is strictly below that count, a refit the engine already wants still runs. At the count, and after it, the search factors the model at the hyperparameters it already has. Zero freezes before the first fit: the seeded hyperparameters are kept and no optimiser run is started. A refit the engine declined stays declined. ``freeze_after_oracle_calls`` is an integer of at least 0. .. py:attribute:: freeze_after_oracle_calls .. py:method:: should_retrain_hyperparameters(state)