Loading...
Searching...
No Matches
pot::ActiveGPPotential Class Referencefinal

#include <gpr/potentials/ActiveGPPotential.h>

Inheritance diagram for pot::ActiveGPPotential:

Public Types

using Config = ActiveGPConfig

Public Member Functions

 ActiveGPPotential (std::shared_ptr< gpr::neb::ActiveLearningSession > session, std::shared_ptr< rgpot::PotentialBase > oracle, Config config=Config())
std::tuple< double, rgpot::types::AtomMatrix, double > operator() (const rgpot::types::AtomMatrix &positions, const std::vector< int > &atmtypes, const std::array< std::array< double, 3 >, 3 > &box) override
std::uint64_t modelState () const noexcept
long oracleCalls () const noexcept
long trainingSize () const noexcept
void incorporate ()
 Host-declared incorporation boundary.
ActiveGP & surrogate () noexcept

Detailed Description

The learning surrogate as an rgpot potential wrapping an rgpot potential.

ActiveGP already carries the learn-on-the-fly semantics, but it takes its oracle as a raw callback and answers on a raw-pointer signature, so only a caller written against gpridge can hold it. This states the same object in rgpot's own contract: it consumes a PotentialBase as the oracle and IS a PotentialBase to whoever holds it, which is what lets a host compose it – eOn selecting a backend, ASE through the rgpot bindings – without knowing a Gaussian process is involved.

The third element of the returned tuple is the posterior energy standard deviation in eV, the uncertainty scale operator() already documents. ActiveGP gates on the energy variance and writes zero to that channel whenever the oracle answered, so a zero there marks a ground-truth call rather than a confident prediction: a host reading it as confidence has the meaning backwards.

PotType has no arm for a surrogate, and minting one is a change to the shared potentials schema rather than to this file, so the type reports UNKNOWN until that lands. Hosts dispatch on the object, not on the tag.

Definition at line 38 of file ActiveGPPotential.h.

Member Typedef Documentation

◆ Config

Constructor & Destructor Documentation

◆ ActiveGPPotential()

pot::ActiveGPPotential::ActiveGPPotential ( std::shared_ptr< gpr::neb::ActiveLearningSession > session,
std::shared_ptr< rgpot::PotentialBase > oracle,
Config config = Config() )
Parameters
sessionthe model this surrogate learns into.
oracleground truth; held for the surrogate's lifetime.
configvariance gates, force certification, and refit cadence.

Definition at line 58 of file ActiveGPPotential.cpp.

61 : rgpot::PotentialBase(rgpot::PotType::UNKNOWN),
62 oracle_(std::move(oracle)),
63 surrogate_(std::move(session), wrapOracle(oracle_), config)
64{
65 if (!oracle_) {
66 throw std::invalid_argument(
67 "ActiveGPPotential needs an oracle to learn from");
68 }
69}

Member Function Documentation

◆ incorporate()

void pot::ActiveGPPotential::incorporate ( )
inline

Host-declared incorporation boundary.

Definition at line 74 of file ActiveGPPotential.h.

75 {
76 surrogate_.incorporate();
77 }

◆ modelState()

std::uint64_t pot::ActiveGPPotential::modelState ( ) const
inlinenodiscardnoexcept

Surface epoch; changes only when an incorporation moved the posterior, so a host may key a cache on it.

Definition at line 58 of file ActiveGPPotential.h.

59 {
60 return surrogate_.modelState();
61 }

◆ operator()()

std::tuple< double, rgpot::types::AtomMatrix, double > pot::ActiveGPPotential::operator() ( const rgpot::types::AtomMatrix & positions,
const std::vector< int > & atmtypes,
const std::array< std::array< double, 3 >, 3 > & box )
override

Energy, forces, and posterior energy standard deviation (eV); zero marks an answer that came from the oracle.

Definition at line 72 of file ActiveGPPotential.cpp.

75{
76 const std::size_t n = positions.rows();
77 if (atmtypes.size() != n) {
78 throw std::invalid_argument(
79 "ActiveGPPotential: one atomic number per row of positions");
80 }
81
82 std::vector<double> flat_pos(n * 3);
83 for (std::size_t a = 0; a < n; ++a)
84 for (std::size_t d = 0; d < 3; ++d)
85 flat_pos[a * 3 + d] = positions(a, d);
86
87 std::array<double, 9> flat_box{};
88 for (std::size_t r = 0; r < 3; ++r)
89 for (std::size_t c = 0; c < 3; ++c)
90 flat_box[r * 3 + c] = box[r][c];
91
92 std::vector<double> flat_forces(n * 3, 0.0);
93 double energy = 0.0;
94 double variance = 0.0;
95
96 const int rc = surrogate_.force(static_cast<long>(n), flat_pos.data(),
97 atmtypes.data(), flat_forces.data(),
98 &energy, &variance, flat_box.data());
99 if (rc != 0) {
100 throw std::runtime_error(
101 "ActiveGPPotential: oracle failed and the posterior was not "
102 "resolved enough to answer without it");
103 }
104
105 rgpot::types::AtomMatrix forces(n, 3);
106 for (std::size_t a = 0; a < n; ++a)
107 for (std::size_t d = 0; d < 3; ++d)
108 forces(a, d) = flat_forces[a * 3 + d];
109
110 // force() gates on the energy variance and reports zero when the
111 // oracle answered; the scale operator() publishes is a standard
112 // deviation, so take the root and let the zero through as it is.
113 const double sigma = variance > 0.0 ? std::sqrt(variance) : 0.0;
114 return {energy, forces, sigma};
115}
double variance(const Weights &w, const Matrix &covariance)

◆ oracleCalls()

long pot::ActiveGPPotential::oracleCalls ( ) const
inlinenodiscardnoexcept

Definition at line 63 of file ActiveGPPotential.h.

64 {
65 return surrogate_.oracleCalls();
66 }

◆ surrogate()

ActiveGP & pot::ActiveGPPotential::surrogate ( )
inlinenoexcept

The acquisition channel, kept on the concrete type: PotentialBase declares no batch entry point, so a host reaching for band-wide argmax-variance selection holds this type rather than the base.

Definition at line 82 of file ActiveGPPotential.h.

83 {
84 return surrogate_;
85 }

◆ trainingSize()

long pot::ActiveGPPotential::trainingSize ( ) const
inlinenodiscardnoexcept

Definition at line 68 of file ActiveGPPotential.h.

69 {
70 return surrogate_.trainingSize();
71 }

The documentation for this class was generated from the following files: