Loading...
Searching...
No Matches
gpr::htst Namespace Reference

Classes

class  EvaluationRecord
struct  Half
struct  Options
struct  SearchRequest

Typedefs

using GradientOracle
using SearchHalves = std::array<std::optional<Half>, 3>

Enumerations

enum class  Kind { Minimum = 0 , Saddle = 1 }
enum class  Status { Ok = 0 , NotConverged = 1 , WrongIndex = 2 , Unavailable = 3 }
enum class  Source {
  Refined = 0 , Measured = 1 , Stencil = 2 , Surrogate = 3 ,
  Conditioned = 4
}
enum class  Mode { Refined = 0 , Measured = 1 , Surrogate = 2 }
 Which Hessian a search's half is built from. More...

Functions

Options geometryOptions (const Options &options, const AtomsConfiguration &atoms, Eigen::Index dof)
Half fromHessian (const Eigen::MatrixXd &hessian, const Eigen::VectorXd &x, Kind kind, const Options &options)
 The half of an exact Hessian in the units of its coordinates.
Half measured (const GradientOracle &oracle, const Eigen::VectorXd &x, Kind kind, const Options &options)
 Full central difference of the oracle gradient: 2 d calls.
Half surrogate (GaussianProcessRegression &gp, const Eigen::VectorXd &x, Kind kind, const Options &options)
Half refined (GaussianProcessRegression &gp, const GradientOracle &oracle, const Eigen::VectorXd &x, Kind kind, const Options &raw_options)
SearchRequest & searchRequest ()
 This thread's request; it persists until it is assigned again.
SearchRequest takeSearchRequest ()
void validateSearchRequest (const SearchRequest &request, const AtomsConfiguration &atoms, Eigen::Index dof)
SearchHalves & lastSearchHalves ()
 The halves of the last search on this thread.
Half searchHalf (const EvaluationRecord &record, const Eigen::VectorXd &x, Kind kind, const InputParameters &params, const AtomsConfiguration &atoms, const GradientOracle &oracle, const SearchRequest &request, const Eigen::MatrixXd *stencil_hessian)
InputParameters searchParameters ()
Half minimumHalf (const EvaluationRecord &record, const Eigen::VectorXd &x, const AtomsConfiguration &atoms, const GradientOracle &oracle, const SearchRequest &request)
 The minimizer's half at its result x: searchHalf with searchParameters().
Eigen::MatrixXd stencilHessian (const Eigen::MatrixXd &positions, const Eigen::MatrixXd &gradients, double step)
SearchHalves bandHalves (const EvaluationRecord &record, const Eigen::VectorXd &initial, const Eigen::VectorXd &final_state, const Eigen::VectorXd &climbing, const Eigen::MatrixXd &stencil_positions, const Eigen::MatrixXd &stencil_gradients, double stencil_step, const InputParameters &params, const AtomsConfiguration &atoms, const GradientOracle &oracle, const SearchRequest &request)
constexpr double evAngstromAmuOmega () noexcept

Typedef Documentation

◆ GradientOracle

Initial value:
std::function<Eigen::VectorXd(const Eigen::VectorXd& position)>

Definition at line 114 of file HarmonicPrefactor.h.

◆ SearchHalves

using gpr::htst::SearchHalves = std::array<std::optional<Half>, 3>

Reactant, saddle and product, indexed as gpr_htst_point_t. An empty slot is a point the search did not compute.

Definition at line 173 of file HarmonicPrefactor.h.

Enumeration Type Documentation

◆ Kind

enum class gpr::htst::Kind
strong

Harmonic transition-state theory in the Vineyard form: nu = prod_i nu_i(minimum) / prod'_i nu_i(saddle), nu_i = omega_i / (2 pi), omega_i^2 the eigenvalues of the mass-weighted Hessian on the vibrational complement of the projected rigid motions, the primed product over the real saddle modes. Each stationary point contributes one half, ln_sum = sum_i ln nu_i over its real modes, so a search that finds one point reports its half and ln nu = ln_sum(minimum) - ln_sum(saddle).

Enumerator
Minimum 
Saddle 

Definition at line 29 of file HarmonicPrefactor.h.

◆ Mode

enum class gpr::htst::Mode
strong

Which Hessian a search's half is built from.

Enumerator
Refined 
Measured 
Surrogate 

Definition at line 145 of file HarmonicPrefactor.h.

◆ Source

enum class gpr::htst::Source
strong
Enumerator
Refined 
Measured 
Stencil 
Surrogate 
Conditioned 

Definition at line 46 of file HarmonicPrefactor.h.

46 {
47 Refined = 0,
48 Measured = 1,
49 Stencil = 2,
50 Surrogate = 3,
51 Conditioned = 4,
52};

◆ Status

enum class gpr::htst::Status
strong
Enumerator
Ok 
NotConverged 

The refinement spent its measurement budget with the change of ln_sum or the estimated spread above the tolerance.

WrongIndex 

The number of negative modes is not the kind's (0 or 1), or a mode is singular: exact and scale-aware near-zero eigenvalues are neither sign.

Unavailable 

No Hessian: the model has no analytic mean Hessian or a measurement failed. Also a spectrum whose eigenvalues, frequencies or sums leave the normal double range.

Definition at line 31 of file HarmonicPrefactor.h.

Function Documentation

◆ bandHalves()

SearchHalves gpr::htst::bandHalves ( const EvaluationRecord & record,
const Eigen::VectorXd & initial,
const Eigen::VectorXd & final_state,
const Eigen::VectorXd & climbing,
const Eigen::MatrixXd & stencil_positions,
const Eigen::MatrixXd & stencil_gradients,
double stencil_step,
const InputParameters & params,
const AtomsConfiguration & atoms,
const GradientOracle & oracle,
const SearchRequest & request )

The halves of a band: its endpoints as minima, and the stencil center with its measured Hessian as the saddle when the search measured one, the climbing image otherwise.

Definition at line 737 of file HarmonicPrefactor.cpp.

744{
745 SearchHalves halves;
746 halves[0] = searchHalf(record, initial, Kind::Minimum, params, atoms,
747 oracle, request);
748 const Eigen::MatrixXd stencil =
749 stencil_positions.rows() == initial.size()
750 ? stencilHessian(stencil_positions, stencil_gradients, stencil_step)
751 : Eigen::MatrixXd();
752 if (stencil.size() > 0)
753 halves[1] = searchHalf(record, stencil_positions.col(0), Kind::Saddle,
754 params, atoms, oracle, request, &stencil);
755 else if (climbing.size() == initial.size())
756 halves[1] = searchHalf(record, climbing, Kind::Saddle, params, atoms,
757 oracle, request);
758 halves[2] = searchHalf(record, final_state, Kind::Minimum, params, atoms,
759 oracle, request);
760 return halves;
761}
Eigen::MatrixXd stencilHessian(const Eigen::MatrixXd &positions, const Eigen::MatrixXd &gradients, double step)
std::array< std::optional< Half >, 3 > SearchHalves
Half searchHalf(const EvaluationRecord &record, const Eigen::VectorXd &x, Kind kind, const InputParameters &params, const AtomsConfiguration &atoms, const GradientOracle &oracle, const SearchRequest &request, const Eigen::MatrixXd *stencil_hessian)

◆ evAngstromAmuOmega()

double gpr::htst::evAngstromAmuOmega ( )
inlinenodiscardconstexprnoexcept

Definition at line 76 of file HarmonicPrefactor.h.

77{
78 // sqrt(eV / (Angstrom^2 amu)) in rad/s.
79 return 9.82269385e13;
80}

◆ fromHessian()

Half gpr::htst::fromHessian ( const Eigen::MatrixXd & hessian,
const Eigen::VectorXd & x,
Kind kind,
const Options & options )

The half of an exact Hessian in the units of its coordinates.

Definition at line 300 of file HarmonicPrefactor.cpp.

302{
303 validate(x, options);
304 (void)coordinateMasses(x, options);
305 if (hessian.rows() != x.size() || hessian.cols() != x.size() ||
306 !hessian.allFinite())
307 throw std::invalid_argument("HTST needs a finite d x d Hessian");
308 Half half = summarize(spectrum(hessian, x, options), x, kind, options, 0.0);
310 if (half.status != Status::Unavailable) {
311 half.converged = true;
312 std::fill(half.measured.begin(), half.measured.end(), 1);
313 half.n_measured = static_cast<int>(half.measured.size());
314 }
315 return half;
316}
@ x
Definition Enums.h:28
std::vector< int > measured
1 for a mode at least 99% inside the measured directions.

◆ geometryOptions()

Options gpr::htst::geometryOptions ( const Options & options,
const AtomsConfiguration & atoms,
Eigen::Index dof )

Frozen atoms anchor the system, so neither translations nor rotations are projected. A periodic cell keeps translations and drops rotations. This is the rule physicalCurvatureBasis already uses. When options.masses is empty and atoms carries atomic_masses, movingAtomicMasses validates and selects the moving atoms' masses.

Apply geometry-derived projection and mass rules from atoms to options: frozen atoms disable translation and rotation projection, a periodic MIC cell disables rotation projection while keeping translations, and empty options.masses inherits atoms.atomic_masses.

Definition at line 278 of file HarmonicPrefactor.cpp.

280{
281 Options out = options;
282 const bool anchored = atoms.atoms_froz_active.positions.size() > 0 ||
283 atoms.atoms_froz_inactive.positions.size() > 0 ||
284 (atoms.is_frozen.array() == FROZEN_ATOM).any();
285 if (anchored) {
286 out.project_translation = false;
287 out.project_rotation = false;
288 } else if (gpr::geometry::cellIsMicLattice(atoms.cell)) {
289 out.project_rotation = false;
290 }
291 if (out.masses.size() == 0 && atoms.atomic_masses.size() > 0) {
292 if (dof <= 0 || dof % 3 != 0)
293 throw std::invalid_argument(
294 "HTST needs one positive mass per atom of the coordinates");
295 out.masses = optim::movingAtomicMasses(atoms, dof / 3);
296 }
297 return out;
298}
@ FROZEN_ATOM
Definition Enums.h:36
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
bool cellIsMicLattice(const double cell[9]) noexcept
Nonzero ASE 3x3 that is not the 25 A vacuum convention.
Definition MinImage.h:56
Eigen::VectorXd movingAtomicMasses(const gpr::AtomsConfiguration &config, Eigen::Index n_moving)
AtomsPositionAndType atoms_froz_inactive
Info on inactive frozen atoms.
Definition Structures.h:843
FieldMatrixU8 is_frozen
Indicates whether atom is frozen or not.
Definition Structures.h:834
AtomsPositionAndType atoms_froz_active
Info on active frozen atoms.
Definition Structures.h:841
Eigen::VectorXd atomic_masses
Per-atom input masses; empty selects unit masses.
Definition Structures.h:838

◆ lastSearchHalves()

SearchHalves & gpr::htst::lastSearchHalves ( )

The halves of the last search on this thread.

Definition at line 563 of file HarmonicPrefactor.cpp.

564{
565 thread_local SearchHalves halves;
566 return halves;
567}

◆ measured()

Half gpr::htst::measured ( const GradientOracle & oracle,
const Eigen::VectorXd & x,
Kind kind,
const Options & options )

Full central difference of the oracle gradient: 2 d calls.

Definition at line 318 of file HarmonicPrefactor.cpp.

320{
321 validate(x, options);
322 (void)coordinateMasses(x, options);
323 const Eigen::Index dof = x.size();
324 Eigen::MatrixXd hessian(dof, dof);
325 for (Eigen::Index j = 0; j < dof; ++j)
326 hessian.col(j) = centralAction(oracle, x, Eigen::VectorXd::Unit(dof, j),
327 options.fd_step);
328 Half half = fromHessian(hessian, x, kind, options);
329 half.oracle_calls = static_cast<int>(2 * dof);
330 return half;
331}
Half fromHessian(const Eigen::MatrixXd &hessian, const Eigen::VectorXd &x, Kind kind, const Options &options)
The half of an exact Hessian in the units of its coordinates.
double fd_step
Central-difference step of each oracle Hessian action.

◆ minimumHalf()

Half gpr::htst::minimumHalf ( const EvaluationRecord & record,
const Eigen::VectorXd & x,
const AtomsConfiguration & atoms,
const GradientOracle & oracle,
const SearchRequest & request )

The minimizer's half at its result x: searchHalf with searchParameters().

Definition at line 691 of file HarmonicPrefactor.cpp.

694{
695 return searchHalf(record, x, Kind::Minimum, searchParameters(), atoms,
696 oracle, request);
697}
InputParameters searchParameters()

◆ refined()

Half gpr::htst::refined ( GaussianProcessRegression & gp,
const GradientOracle & oracle,
const Eigen::VectorXd & x,
Kind kind,
const Options & options )

Start from the GP posterior-mean Hessian and replace it, direction by direction, by oracle Hessian actions (2 calls each) along the mode with the largest estimated ln nu spread, until ln_sum settles. An empty oracle is surrogate().

Definition at line 339 of file HarmonicPrefactor.cpp.

341{
342 const Options options =
343 geometryOptions(raw_options, gp.getAtomsConfig(), x.size());
344 validate(x, options);
345 (void)coordinateMasses(x, options);
346 const Eigen::Index dof = x.size();
347 Eigen::MatrixXd fixed_hessian;
348 if (gp.findConditionedHessian(x, fixed_hessian)) {
349 Half half = fromHessian(fixed_hessian, x, kind, options);
351 return half;
352 }
353 std::vector<Eigen::MatrixXd> hessians;
354 const auto report =
355 posterior::meanHessians(gp, x.transpose(), {}, hessians);
356 if (!report.ok()) {
358 throw std::invalid_argument(report.message);
359 return unavailableHalf(kind,
361 dof, options.omega_scale, report.message);
362 }
363 if (hessians.empty())
364 return unavailableHalf(
365 kind, oracle ? Source::Refined : Source::Surrogate, dof,
366 options.omega_scale, "posterior returned no Hessian");
367 const Eigen::MatrixXd surrogate_hessian = hessians[0];
368 posterior::DerivativeOptions variance_options;
369 variance_options.variance_step = options.variance_step;
370
371 Eigen::MatrixXd S(dof, 0), W(dof, 0);
372 Eigen::MatrixXd corrected = surrogate_hessian;
373 int calls = 0;
374 double previous = std::numeric_limits<double>::quiet_NaN();
375 Half half;
376 for (int round = 0;; ++round) {
377 const Spectrum s = spectrum(corrected, x, options);
378 const Eigen::Index modes = s.eigenvalues.size();
379 // No vibrational complement leaves an empty spectrum. summarize
380 // reports that; reducing the empty vector is undefined.
381 if (modes == 0 || !s.finite || !s.eigenvalues.allFinite()) {
382 half = summarize(s, x, kind, options, 0.0);
383 half.n_measured = static_cast<int>(S.cols());
384 half.oracle_calls = calls;
385 half.source = oracle ? Source::Refined : Source::Surrogate;
386 break;
387 }
388 const int budget =
389 options.max_measured > 0
390 ? std::min<int>(options.max_measured, static_cast<int>(modes))
391 : static_cast<int>(modes);
392
393 // Unmeasured part of each mode and the GP spread of its curvature.
394 Eigen::MatrixXd outside = s.directions;
395 if (S.cols() > 0) outside -= S * (S.transpose() * s.directions);
396 Eigen::VectorXd spread = Eigen::VectorXd::Zero(modes);
397 std::vector<int> inside(static_cast<std::size_t>(modes), 0);
398 std::vector<Eigen::Index> open;
399 for (Eigen::Index i = 0; i < modes; ++i) {
400 const double total = s.directions.col(i).squaredNorm();
401 const double out = outside.col(i).squaredNorm();
402 if (out <= 0.01 * total) inside[static_cast<std::size_t>(i)] = 1;
403 if (out > 1e-16 * total) open.push_back(i);
404 }
405 const double zero_cut = zeroCutoff(s, dof);
406 double ln_sum_std = 0.0;
407 if (!open.empty()) {
408 const Eigen::Index count = static_cast<Eigen::Index>(open.size());
409 // Unit query directions keep the variance in range for any mass
410 // scale; var(o^T H o) = norm(o)^4 var(u^T H u) for o = norm(o) u.
411 Eigen::MatrixXd block(count, dof);
412 Eigen::VectorXd norms(count);
413 for (Eigen::Index k = 0; k < count; ++k) {
414 const auto column =
415 outside.col(open[static_cast<std::size_t>(k)]);
416 norms(k) = column.stableNorm();
417 block.row(k) = (column / norms(k)).transpose();
418 }
419 std::vector<Eigen::VectorXd> variance;
421 gp, x.transpose(), {block}, variance_options, variance);
422 if (!status.ok()) {
423 half = summarize(s, x, kind, options, 0.0);
424 half.measured = inside;
425 half.n_measured = static_cast<int>(S.cols());
426 half.oracle_calls = calls;
427 half.source = oracle ? Source::Refined : Source::Surrogate;
428 half.status = Status::Unavailable;
429 half.message = status.message;
430 break;
431 }
432 const Eigen::VectorXd& diagonal = variance[0];
433 // sqrt(var_i) / (2 lambda_i) in log space: neither the fourth
434 // power of norm(o) nor 1 / lambda_i^2 is formed.
435 Eigen::VectorXd terms = Eigen::VectorXd::Zero(count);
436 for (Eigen::Index k = 0; k < count; ++k) {
437 const Eigen::Index i = open[static_cast<std::size_t>(k)];
438 const double ln_root = std::log(0.5) +
439 0.5 * std::log(diagonal(k)) +
440 2.0 * std::log(norms(k));
441 spread(i) = std::exp(
442 ln_root -
443 std::log(std::max(std::abs(s.eigenvalues(i)),
444 std::numeric_limits<double>::min())));
445 if (s.eigenvalues(i) > zero_cut)
446 terms(k) = std::exp(ln_root - std::log(s.eigenvalues(i)));
447 }
448 ln_sum_std = terms.stableNorm();
449 }
450 half = summarize(s, x, kind, options, ln_sum_std);
451 half.measured = inside;
452 half.n_measured = static_cast<int>(S.cols());
453 half.oracle_calls = calls;
454 half.source = oracle ? Source::Refined : Source::Surrogate;
455 if (half.status == Status::Unavailable) break;
456
457 double widest = 0.0;
458 Eigen::Index pick = -1;
459 for (const Eigen::Index i: open)
460 if (spread(i) > widest || pick < 0) {
461 widest = spread(i);
462 pick = i;
463 }
464 if (round > 0 && std::abs(half.ln_sum - previous) < options.tolerance &&
465 widest < options.tolerance && half.ln_sum_std < options.tolerance) {
466 half.converged = true;
467 break;
468 }
469 if (!oracle) {
470 half.source = Source::Surrogate;
471 half.converged = widest < options.tolerance &&
472 half.ln_sum_std < options.tolerance;
473 break;
474 }
475 if (pick < 0 || S.cols() >= budget || S.cols() >= dof) {
476 // Every vibrational direction measured is the measured Hessian.
477 half.converged = S.cols() >= static_cast<Eigen::Index>(modes);
478 break;
479 }
480 Eigen::VectorXd direction = outside.col(pick);
481 for (int pass = 0; pass < 2 && S.cols() > 0; ++pass)
482 direction -= S * (S.transpose() * direction);
483 direction.normalize();
484 if (!direction.allFinite() ||
485 std::abs(direction.squaredNorm() - 1.0) > 1e-8) {
486 markUnavailable(half, calls, S.cols(),
487 "no independent direction is left to measure");
488 break;
489 }
490 const Eigen::VectorXd action =
491 centralAction(oracle, x, direction, options.fd_step);
492 calls += 2;
493 S.conservativeResize(Eigen::NoChange, S.cols() + 1);
494 W.conservativeResize(Eigen::NoChange, W.cols() + 1);
495 S.col(S.cols() - 1) = direction;
496 W.col(W.cols() - 1) = action;
497
498 // Exact on span(S), the surrogate on its complement. An empty
499 // result means the measured actions were not finite or S lost
500 // orthonormality; the spectrum of a 0 x 0 matrix is not a half.
501 corrected = optim::completeMeasuredHessian(surrogate_hessian, S, W);
502 if (corrected.rows() != dof || corrected.cols() != dof) {
503 markUnavailable(half, calls, S.cols(),
504 "measured Hessian actions are not finite or the "
505 "measured directions lost orthonormality");
506 break;
507 }
508 previous = half.ln_sum;
509 }
510 if (half.status == Status::Ok && !half.converged && oracle)
511 half.status = Status::NotConverged;
512 return half;
513}
bool findConditionedHessian(const Eigen::VectorXd &point, Eigen::MatrixXd &hessian_out) const
const AtomsConfiguration & getAtomsConfig() const
int status
Options geometryOptions(const Options &options, const AtomsConfiguration &atoms, Eigen::Index dof)
Eigen::MatrixXd completeMeasuredHessian(const Eigen::MatrixXd &prior, const Eigen::MatrixXd &basis, const Eigen::MatrixXd &action)
DerivativeReport hessianBilinearVariances(GaussianProcessRegression &gp, const Eigen::MatrixXd &points, const std::vector< Eigen::MatrixXd > &directions, const DerivativeOptions &options, std::vector< Eigen::VectorXd > &variances)
Diagonal posterior variances of v_i^T H v_i at each point. Computes one stencil functional at a time,...
DerivativeReport meanHessians(GaussianProcessRegression &gp, const Eigen::MatrixXd &points, const DerivativeOptions &options, std::vector< Eigen::MatrixXd > &hessians, Eigen::MatrixXd *residuals)
Full posterior-mean Hessians at the rows of points, symmetrized. residuals, when given,...
double variance(const Weights &w, const Matrix &covariance)
double variance_step
Stencil step of the GP curvature variance (0: the primitive default).
int max_measured
Oracle-measured directions at most; 0 allows every vibrational mode.

◆ searchHalf()

Half gpr::htst::searchHalf ( const EvaluationRecord & record,
const Eigen::VectorXd & x,
Kind kind,
const InputParameters & params,
const AtomsConfiguration & atoms,
const GradientOracle & oracle,
const SearchRequest & request,
const Eigen::MatrixXd * stencil_hessian = nullptr )

One half at x from a finished search. A measured stencil Hessian is used when given; otherwise MEASURED differentiates the oracle, and the other modes fit a GP with params on the record's evaluations nearest x. A half that cannot be formed is returned with Status::Unavailable.

Definition at line 614 of file HarmonicPrefactor.cpp.

619{
620 const Source requested_source =
621 stencil_hessian
623 : (request.mode == Mode::Measured
625 : (request.mode == Mode::Refined ? Source::Refined
627 const double scale = request.options.omega_scale;
628 try {
629 const Options options =
630 geometryOptions(request.options, atoms, x.size());
631 validate(x, options);
632 (void)coordinateMasses(x, options);
633 if (stencil_hessian) {
634 Half half = fromHessian(*stencil_hessian, x, kind, options);
635 half.source = Source::Stencil;
636 return half;
637 }
638 if (request.mode == Mode::Measured) {
639 if (!oracle)
640 return unavailableHalf(kind, requested_source, x.size(), scale,
641 "measured prefactor requires an oracle");
642 return measured(oracle, x, kind, options);
643 }
644 const Observation obs = record.nearest(x, kSearchHalfRows);
645 if (obs.R.rows() == 0)
646 return unavailableHalf(kind, requested_source, x.size(), scale,
647 "no evaluations near stationary point");
648 GaussianProcessRegression gp;
649 gp.initialize(params, atoms);
650 gp.setUseZBLPriorMean(false);
651 gp.setUseFFPriorMean(false);
652 gp.setHyperparameters(obs, atoms);
653 gp.optimize(obs);
654 if (!gp.isDecomposedSuccessfully())
655 return unavailableHalf(kind, requested_source, x.size(), scale,
656 "GP Cholesky decomposition failed");
657 return request.mode == Mode::Refined
658 ? refined(gp, oracle, x, kind, options)
659 : surrogate(gp, x, kind, options);
660 } catch (const std::bad_alloc&) {
661 return unavailableHalf(kind, requested_source, x.size(), scale,
662 "prefactor allocation failed");
663 } catch (const std::exception& error) {
664 return unavailableHalf(kind, requested_source, x.size(), scale,
665 error.what());
666 } catch (...) {
667 return unavailableHalf(kind, requested_source, x.size(), scale,
668 "prefactor computation failed");
669 }
670}
Observation nearest(const Eigen::VectorXd &x, std::size_t rows) const
Up to rows evaluations nearest x, nearest first.
Half surrogate(GaussianProcessRegression &gp, const Eigen::VectorXd &x, Kind kind, const Options &options)
Half measured(const GradientOracle &oracle, const Eigen::VectorXd &x, Kind kind, const Options &options)
Full central difference of the oracle gradient: 2 d calls.
Half refined(GaussianProcessRegression &gp, const GradientOracle &oracle, const Eigen::VectorXd &x, Kind kind, const Options &raw_options)

◆ searchParameters()

InputParameters gpr::htst::searchParameters ( )

The GP settings of gpr_model_config_defaults, used by searches that carry no GP configuration of their own.

Definition at line 672 of file HarmonicPrefactor.cpp.

673{
674 InputParameters params;
675 params.gp_sigma2.value = 1e-4;
676 params.jitter_sigma2.value = 1e-4;
677 params.sigma2.value = 1e-4;
678 params.magnSigma2.value = 0.0;
679 params.constSigma2.value = 0.0;
680 params.prior_mu.value = 0.0;
681 params.prior_nu.value = 20.0;
682 params.prior_s2.value = 1.0;
683 params.max_iter.value = 400;
684 params.tolerance_func.value = 1e-3;
685 params.tolerance_sol.value = 1e-3;
686 params.report_level.value = 0;
687 params.optimization_alg.value = "SCG_opt";
688 return params;
689}
Structure of the input parameters. All input parameters are pairs of string names and values.
Definition Structures.h:370
KeyValuePair< double > prior_s2
Definition Structures.h:650
KeyValuePair< int > max_iter
Definition Structures.h:674
KeyValuePair< std::string > optimization_alg
Definition Structures.h:614
KeyValuePair< double > prior_nu
Definition Structures.h:649
KeyValuePair< int > report_level
Definition Structures.h:673
KeyValuePair< double > jitter_sigma2
Definition Structures.h:613
KeyValuePair< double > constSigma2
Definition Structures.h:618
KeyValuePair< double > tolerance_func
Definition Structures.h:675
KeyValuePair< double > tolerance_sol
Definition Structures.h:676
KeyValuePair< double > prior_mu
Definition Structures.h:648
KeyValuePair< double > sigma2
Definition Structures.h:616
KeyValuePair< double > magnSigma2
Definition Structures.h:617
KeyValuePair< double > gp_sigma2
Definition Structures.h:612

◆ searchRequest()

SearchRequest & gpr::htst::searchRequest ( )

This thread's request; it persists until it is assigned again.

Definition at line 515 of file HarmonicPrefactor.cpp.

516{
517 thread_local SearchRequest request;
518 return request;
519}

◆ stencilHessian()

Eigen::MatrixXd gpr::htst::stencilHessian ( const Eigen::MatrixXd & positions,
const Eigen::MatrixXd & gradients,
double step )
nodiscard

Central-difference Hessian of an index stencil: the center, then the +h and -h displacements along each coordinate, as columns (or rows) of gradients. Empty when the stencil does not have that shape.

Definition at line 699 of file HarmonicPrefactor.cpp.

701{
702 const Eigen::Index dof = positions.rows();
703 if (dof == 0 || positions.cols() != 2 * dof + 1 || !std::isfinite(step) ||
704 !(step > 0.0) || !positions.allFinite() || !gradients.allFinite())
705 return {};
706 const bool by_column =
707 gradients.rows() == dof && gradients.cols() == 2 * dof + 1;
708 const bool by_row =
709 gradients.rows() == 2 * dof + 1 && gradients.cols() == dof;
710 if (!by_column && !by_row) return {};
711 const Eigen::VectorXd center = positions.col(0);
712 const double tol = std::max(
713 1e-9 * step, 64.0 * std::numeric_limits<double>::epsilon() *
714 std::max(1.0, center.cwiseAbs().maxCoeff() + step));
715 for (Eigen::Index j = 0; j < dof; ++j) {
716 Eigen::VectorXd expected_plus = center;
717 expected_plus(j) += step;
718 Eigen::VectorXd expected_minus = center;
719 expected_minus(j) -= step;
720 if ((positions.col(2 * j + 1) - expected_plus)
721 .lpNorm<Eigen::Infinity>() > tol ||
722 (positions.col(2 * j + 2) - expected_minus)
723 .lpNorm<Eigen::Infinity>() > tol)
724 return {};
725 }
726 const auto gradient = [&](Eigen::Index k) -> Eigen::VectorXd {
727 return by_column ? Eigen::VectorXd(gradients.col(k))
728 : Eigen::VectorXd(gradients.row(k).transpose());
729 };
730 Eigen::MatrixXd hessian(dof, dof);
731 for (Eigen::Index j = 0; j < dof; ++j)
732 hessian.col(j) =
733 (gradient(2 * j + 1) - gradient(2 * j + 2)) / (2.0 * step);
734 return hessian;
735}

◆ surrogate()

Half gpr::htst::surrogate ( GaussianProcessRegression & gp,
const Eigen::VectorXd & x,
Kind kind,
const Options & options )

The GP posterior-mean Hessian, with no oracle call. converged says whether every mode's estimated ln nu spread is under the tolerance.

Definition at line 333 of file HarmonicPrefactor.cpp.

335{
336 return refined(gp, GradientOracle{}, x, kind, options);
337}
std::function< Eigen::VectorXd(const Eigen::VectorXd &position)> GradientOracle

◆ takeSearchRequest()

SearchRequest gpr::htst::takeSearchRequest ( )

Consume this thread's one-shot request masses and return the request for the search about to run.

Definition at line 521 of file HarmonicPrefactor.cpp.

522{
523 SearchRequest& current = searchRequest();
524 SearchRequest out = current;
525 current.options.masses.resize(0);
526 return out;
527}
SearchRequest & searchRequest()
This thread's request; it persists until it is assigned again.
Eigen::VectorXd masses

◆ validateSearchRequest()

void gpr::htst::validateSearchRequest ( const SearchRequest & request,
const AtomsConfiguration & atoms,
Eigen::Index dof )

Validate a search request's options and masses against atoms and dof before a search runs. An enabled request on coordinates that are not a whole number of atoms throws std::invalid_argument, masses given or not.

Definition at line 529 of file HarmonicPrefactor.cpp.

531{
532 if (!request.enabled) return;
533 if (dof <= 0 || dof % 3 != 0) {
535 throw std::invalid_argument(
536 "prefactor requests need coordinates for a whole number of atoms");
537 }
538 Options effective;
539 try {
540 effective = geometryOptions(request.options, atoms, dof);
541 } catch (...) {
543 throw;
544 }
545 if (!normalPositive(effective.omega_scale) ||
546 !(effective.tolerance > 0.0) || !std::isfinite(effective.tolerance) ||
547 !(effective.fd_step > 0.0) || !std::isfinite(effective.fd_step) ||
548 effective.max_measured < 0 || !std::isfinite(effective.variance_step)) {
550 throw std::invalid_argument("invalid HTST option");
551 }
552 if (effective.masses.size() > 0) {
553 if (dof <= 0 || dof % 3 != 0 || effective.masses.size() * 3 != dof ||
554 !effective.masses.unaryExpr(&normalPositive).all()) {
556 throw std::invalid_argument(
557 "HTST needs one positive mass per atom of the coordinates, "
558 "each a normal double");
559 }
560 }
561}