Training policy¶
A training policy is an object passed to gp_minimize, gp_neb and
run_ocineb, or to AtomicDimer.set_training_policy. None is the
engine. The methods that exist are called. A missing method keeps the
engine’s decision for that question. An object with none of the five
methods raises InvalidArgumentError before the search starts.
A method that raises, or that returns a value of the wrong type, raises
InvalidArgumentError carrying the Python message. The search does not
abort the process.
Methods¶
should_call_oracle(state) returns a bool. False skips a call the engine
was about to make.
select_training_points(candidates, current_set) returns a sequence of
ints. Those candidates are stored. candidates is a sequence of
PolicyCandidate. current_set is a sequence of position vectors.
should_retrain_hyperparameters(state) returns a bool. False factors the
model at the hyperparameters it already has.
should_rebuild_factor(state) returns a bool. It is read only when the
hyperparameters are not refit. False appends to the factor when that is
legal.
retain_training_rows(rows) returns a sequence of ints. The training set
is rewritten to those rows. The identity list, every index in order, does
not rewrite it.
PolicyState¶
kind is minimize, neb, oci_neb or dimer.
role is unspecified, initial_design, acquisition, trust_exit,
convergence_check or dimer_midpoint.
iteration, oracle_calls, training_size, hyperparameter_refits and
image_index are ints. iteration is the inner surrogate step count for
minimize (shared across oracle and hyperparameter-retraining hooks) and the
outer iteration index for neb, oci_neb, and dimer.
image_index is -1 when the decision is not about one image.
posterior_variance and force_variance are floats, in eV^2 and
eV^2/Angstrom^2. A value that is not finite means the search has no
posterior for this decision.
trust_radius and distance_to_training are lengths in the coordinate
unit.
engine_would_call_oracle, engine_would_retrain and
engine_would_rebuild_factor are the decision the engine would take.
within_trust and surrogate_proposes_stop are bools.
positions is a copy of the candidate coordinates, or an empty vector.
hyperparameters is a copy of the packed hyperparameters, or an empty
vector. The live model is not exposed.
Recipes¶
gpridge.SizeCapPolicy(max_size),
gpridge.DistanceDedupPolicy(min_distance),
gpridge.VarianceThresholdPolicy(variance_threshold) and
gpridge.FreezeHyperparametersPolicy(freeze_after_oracle_calls)
implement the four recipes. The parameter names and the inequalities are
in the how-to.
gpridge.DefaultPolicy returns the engine flags and the identity index
lists.
import math
from gpridge import VarianceThresholdPolicy
from gpridge.policy import farthest_point_indices
class State:
engine_would_call_oracle = True
posterior_variance = float("nan")
assert VarianceThresholdPolicy(1.0).should_call_oracle(State())
State.posterior_variance = 1.0
assert not VarianceThresholdPolicy(1.0).should_call_oracle(State())
State.posterior_variance = 1.0 + 1e-12
assert VarianceThresholdPolicy(1.0).should_call_oracle(State())
rows = [[0.0], [0.2], [1.0], [1.0]]
assert farthest_point_indices(rows, 2) == [0, 2]
assert math.isfinite(VarianceThresholdPolicy(0.0).variance_threshold)