Loading...
Searching...
No Matches
gpr::neb::ActiveLearningSession::ImageModel Struct Reference

#include <gpr/neb/Session.h>

Public Member Functions

void setGP (std::unique_ptr< gpr::GaussianProcessRegression > next_gp)
gpr::GaussianProcessRegression * gp ()
const gpr::GaussianProcessRegression * gp () const
const gpr::Observation & observations () const
void updateConfiguration (const gpr::AtomsConfiguration &configuration)
void setInternalCoordinateChart (std::shared_ptr< const gpr::geometry::InternalCoordinateChart > chart, double length_scale)
void clearInternalCoordinateChart ()
const std::shared_ptr< const gpr::geometry::InternalCoordinateChart > & internalCoordinateChart () const noexcept
double internalCoordinateLengthScale () const noexcept
void setGeodesicReferencePath (gpr::Coord reference_path)
void clearGeodesicReferencePath ()
bool hasGeodesicReferencePath () const noexcept
const gpr::Coord & geodesicReferencePath () const noexcept
std::uint64_t observationRevision () const noexcept
std::uint64_t surrogateRevision () const noexcept
std::uint64_t synchronizeSurrogateRevision (const Eigen::VectorXd &theta_global, double likelihood_noise_floor_sigma2, const SharedParameterState &shared_state={}) const
const std::vector< int > & selectedIndices () const
const std::vector< int > & directIndices () const
bool hasEnoughRows (int n_min) const
int directObservationCount () const
bool hasEnoughDirectRows (int n_min) const
void appendObservation (const Eigen::VectorXd &positions, double energy, const Eigen::VectorXd &gradient, int global_row_index)
void refreshSelectedObservation (int global_row, const gpr::Observation &global)
void compactAfterRowRemoval (int removed_row)
void remapGlobalRows (const std::vector< int > &old_to_new, const gpr::Observation &global)
int pruneAdaptiveAtPoint (const Eigen::VectorXd &band_point)
void replaceNeighborhood (gpr::Observation observations, std::vector< int > selected_indices, std::vector< uint64_t > archived_keys={})
const std::vector< uint64_t > & archivedKeys () const noexcept
bool materializedFor (const Eigen::VectorXd &theta_global, double likelihood_noise_floor_sigma2, const SharedParameterState &shared_state={}) const
void recordMaterialized (const Eigen::VectorXd &theta_global, double likelihood_noise_floor_sigma2, const SharedParameterState &shared_state={})

Detailed Description

Per-image local model slot. The slot owns both its observations and the factor materialization state, so every mutation invalidates through the same object that hands out model leases.

Definition at line 476 of file Session.h.

Member Function Documentation

◆ appendObservation()

void gpr::neb::ActiveLearningSession::ImageModel::appendObservation ( const Eigen::VectorXd & positions,
double energy,
const Eigen::VectorXd & gradient,
int global_row_index )
inline

Definition at line 673 of file Session.h.

676 {
677 // Drop a row that repeats a configuration already held: a
678 // dimer burst restarting from a stored stop point
679 // re-oracles the same geometry every phase, and a
680 // duplicate row leaves the per-image covariance
681 // rank-deficient -> non-finite Cholesky factor -> NaN
682 // curvature handed back to the dimer.
683 if (detail::hasPosition(observations_, positions)) return;
684 // Row k of the local set is selected_indices_[k]; archived
685 // rows ride behind the selected ones. A row bound to a global
686 // index therefore joins the selected rows, ahead of the
687 // archive, or every later refresh would write it over an
688 // archived row.
689 if (global_row_index >= 0) {
690 detail::insertObservationRow(
691 observations_,
692 static_cast<Eigen::Index>(selected_indices_.size()),
693 positions, energy, gradient);
694 selected_indices_.push_back(global_row_index);
695 direct_indices_.push_back(global_row_index);
696 } else {
697 detail::appendObservationRow(observations_, positions, energy,
698 gradient);
699 }
700 ++direct_observation_count_;
701 recordObservationMutation();
702 }

◆ archivedKeys()

const std::vector< uint64_t > & gpr::neb::ActiveLearningSession::ImageModel::archivedKeys ( ) const
inlinenodiscardnoexcept

Archive-pool row indices folded into the neighborhood beyond the active training rows (empty without an archive).

Definition at line 889 of file Session.h.

890 {
891 return archived_keys_;
892 }

◆ clearGeodesicReferencePath()

void gpr::neb::ActiveLearningSession::ImageModel::clearGeodesicReferencePath ( )
inline

Definition at line 575 of file Session.h.

576 {
577 if (!hasGeodesicReferencePath()) return;
578 geodesic_reference_path_.resize(0, 0);
579 if (gp_) {
580 gp_->getSexpAtCovarianceFunction().clearGeodesicHeatKernel();
581 }
582 ++geometry_prior_revision_;
583 ++surrogate_revision_;
584 invalidateMaterialization();
585 }
bool hasGeodesicReferencePath() const noexcept
Definition Session.h:587

◆ clearInternalCoordinateChart()

void gpr::neb::ActiveLearningSession::ImageModel::clearInternalCoordinateChart ( )
inline

Definition at line 527 of file Session.h.

528 {
529 if (!internal_coordinate_chart_) return;
530 internal_coordinate_chart_.reset();
531 internal_coordinate_length_scale_ =
532 std::numeric_limits<double>::quiet_NaN();
533 if (gp_) {
534 gp_->getSexpAtCovarianceFunction().clearManifoldChart();
535 }
536 ++geometry_prior_revision_;
537 ++surrogate_revision_;
538 invalidateMaterialization();
539 }

◆ compactAfterRowRemoval()

void gpr::neb::ActiveLearningSession::ImageModel::compactAfterRowRemoval ( int removed_row)
inline

A global training row was removed: drop references to it and shift every index above it down by one, in the same order the removals happened. Removing a selected row changes the local conditioning data; shifting unrelated global indices does not.

Definition at line 734 of file Session.h.

735 {
736 const auto selected =
737 std::find(selected_indices_.begin(), selected_indices_.end(),
738 removed_row);
739 const bool selected_observation_removed =
740 selected != selected_indices_.end();
741 if (selected_observation_removed) {
742 // Row k is selected_indices_[k]; archived rows ride behind.
743 const auto position = static_cast<Eigen::Index>(
744 std::distance(selected_indices_.begin(), selected));
745 if (position >= observations_.R.rows()) {
746 throw std::logic_error(
747 "image local set is shorter than its selected rows");
748 }
749 detail::eraseObservationRow(observations_, position);
750 }
751 auto compact = [removed_row](std::vector<int>& indices) {
752 std::size_t w = 0;
753 for (std::size_t r = 0; r < indices.size(); ++r) {
754 if (indices[r] == removed_row) continue;
755 indices[w++] =
756 indices[r] > removed_row ? indices[r] - 1 : indices[r];
757 }
758 indices.resize(w);
759 };
760 const std::size_t direct_before = direct_indices_.size();
761 compact(selected_indices_);
762 compact(direct_indices_);
763 if (direct_indices_.size() < direct_before &&
764 direct_observation_count_ > 0) {
765 --direct_observation_count_;
766 }
767 if (selected_observation_removed) {
768 recordObservationMutation();
769 }
770 }

◆ directIndices()

const std::vector< int > & gpr::neb::ActiveLearningSession::ImageModel::directIndices ( ) const
inlinenodiscard

Global ~training_obs~ rows this image was oracled at directly – its own search / climb trajectory. Append-only; unlike ~selected_indices_~ it survives ~replaceNeighborhood~ so the trajectory-aware neighbourhood union can always re-include it.

Definition at line 649 of file Session.h.

650 {
651 return direct_indices_;
652 }

◆ directObservationCount()

int gpr::neb::ActiveLearningSession::ImageModel::directObservationCount ( ) const
inlinenodiscard

Definition at line 659 of file Session.h.

660 {
661 return direct_observation_count_;
662 }

◆ geodesicReferencePath()

const gpr::Coord & gpr::neb::ActiveLearningSession::ImageModel::geodesicReferencePath ( ) const
inlinenodiscardnoexcept

Definition at line 592 of file Session.h.

593 {
594 return geodesic_reference_path_;
595 }

◆ gp() [1/2]

gpr::GaussianProcessRegression * gpr::neb::ActiveLearningSession::ImageModel::gp ( )
inlinenodiscard

Definition at line 484 of file Session.h.

485 {
486 return gp_.get();
487 }

◆ gp() [2/2]

const gpr::GaussianProcessRegression * gpr::neb::ActiveLearningSession::ImageModel::gp ( ) const
inlinenodiscard

Definition at line 489 of file Session.h.

490 {
491 return gp_.get();
492 }

◆ hasEnoughDirectRows()

bool gpr::neb::ActiveLearningSession::ImageModel::hasEnoughDirectRows ( int n_min) const
inlinenodiscard

Number of distinct direct-image rows retained after position deduplication. Repeated oracle calls at the same geometry do not make the local GP eligible because they do not add independent conditioning information.

Definition at line 668 of file Session.h.

669 {
670 return direct_observation_count_ >= n_min;
671 }

◆ hasEnoughRows()

bool gpr::neb::ActiveLearningSession::ImageModel::hasEnoughRows ( int n_min) const
inlinenodiscard

Definition at line 654 of file Session.h.

655 {
656 return observations_.E.rows() >= n_min;
657 }

◆ hasGeodesicReferencePath()

bool gpr::neb::ActiveLearningSession::ImageModel::hasGeodesicReferencePath ( ) const
inlinenodiscardnoexcept

Definition at line 587 of file Session.h.

588 {
589 return geodesic_reference_path_.size() > 0;
590 }

◆ internalCoordinateChart()

const std::shared_ptr< const gpr::geometry::InternalCoordinateChart > & gpr::neb::ActiveLearningSession::ImageModel::internalCoordinateChart ( ) const
inlinenodiscardnoexcept

Definition at line 543 of file Session.h.

544 {
545 return internal_coordinate_chart_;
546 }

◆ internalCoordinateLengthScale()

double gpr::neb::ActiveLearningSession::ImageModel::internalCoordinateLengthScale ( ) const
inlinenodiscardnoexcept

Definition at line 548 of file Session.h.

549 {
550 return internal_coordinate_length_scale_;
551 }

◆ materializedFor()

bool gpr::neb::ActiveLearningSession::ImageModel::materializedFor ( const Eigen::VectorXd & theta_global,
double likelihood_noise_floor_sigma2,
const SharedParameterState & shared_state = {} ) const
inlinenodiscard

Definition at line 894 of file Session.h.

897 {}) const
898 {
899 if (materialized_revision_ != observation_revision_) return false;
900 if (materialized_shared_state_ != shared_state) return false;
901 if (materialized_geometry_prior_revision_ !=
902 geometry_prior_revision_) {
903 return false;
904 }
905 return surrogateInputsMatch(
906 materialized_theta_, materialized_noise_floor_sigma2_,
907 theta_global, likelihood_noise_floor_sigma2);
908 }

◆ observationRevision()

std::uint64_t gpr::neb::ActiveLearningSession::ImageModel::observationRevision ( ) const
inlinenodiscardnoexcept

Monotonic version of the local conditioning data. It advances only when the observations available to this image change, so callers can distinguish a genuinely refreshed local model from unrelated growth of the global training set.

Definition at line 601 of file Session.h.

602 {
603 return observation_revision_;
604 }

◆ observations()

const gpr::Observation & gpr::neb::ActiveLearningSession::ImageModel::observations ( ) const
inlinenodiscard

Definition at line 494 of file Session.h.

495 {
496 return observations_;
497 }

◆ pruneAdaptiveAtPoint()

int gpr::neb::ActiveLearningSession::ImageModel::pruneAdaptiveAtPoint ( const Eigen::VectorXd & band_point)
inline

Per-image adaptive pruning at this image's own band point. After the global-to-single handover each image GP conditions on its own selected rows, so the influence question is local: can this row move THIS image's posterior energy by one likelihood sigma. One removal per event, the same exactness argument as the session-level pruner. The removal is local only – the global training row survives – so selected/direct index maps drop the entry without shifting, and the handover eligibility counter is untouched: pruning an information-free row must not retract a model that already earned activation.

Definition at line 836 of file Session.h.

837 {
838 const Eigen::Index min_rows = 4;
839 if (!gp_ || observations_.R.rows() <= min_rows) return 0;
840 if (selected_indices_.size() !=
841 static_cast<std::size_t>(observations_.R.rows())) {
842 return 0;
843 }
844 gpr::Coord point(1, band_point.size());
845 point.row(0) = band_point.transpose();
846 Eigen::VectorXd influence;
847 if (!gp_->observationBandInfluence(observations_, point,
848 influence)) {
849 return 0;
850 }
851 if (influence.size() != observations_.R.rows()) return 0;
852 const double noise_sigma =
853 std::sqrt(std::max(gp_->getLikGaussian().getSigma2(), 0.0));
854 if (!(noise_sigma > 0.0) || !std::isfinite(noise_sigma)) return 0;
855 Eigen::Index r_min = -1;
856 double v_min = std::numeric_limits<double>::infinity();
857 for (Eigen::Index r = 0; r < influence.size(); ++r) {
858 if (influence(r) < v_min) {
859 v_min = influence(r);
860 r_min = r;
861 }
862 }
863 if (r_min < 0 || !(v_min < noise_sigma)) return 0;
864 const int global_row =
865 selected_indices_[static_cast<std::size_t>(r_min)];
866 detail::eraseObservationRow(observations_, r_min);
867 selected_indices_.erase(selected_indices_.begin() + r_min);
868 const auto direct_it = std::find(direct_indices_.begin(),
869 direct_indices_.end(), global_row);
870 if (direct_it != direct_indices_.end()) {
871 direct_indices_.erase(direct_it);
872 }
873 recordObservationMutation();
874 return 1;
875 }
FieldMatrixd Coord
Definition Macros.h:35

◆ recordMaterialized()

void gpr::neb::ActiveLearningSession::ImageModel::recordMaterialized ( const Eigen::VectorXd & theta_global,
double likelihood_noise_floor_sigma2,
const SharedParameterState & shared_state = {} )
inline

Definition at line 910 of file Session.h.

912 {})
913 {
914 const double effective_noise_sigma2 =
915 gp_ ? gp_->getSigma2() : likelihood_noise_floor_sigma2;
917 theta_global, effective_noise_sigma2, shared_state);
918 materialized_revision_ = observation_revision_;
919 materialized_geometry_prior_revision_ = geometry_prior_revision_;
920 materialized_theta_ = theta_global;
921 materialized_noise_floor_sigma2_ = likelihood_noise_floor_sigma2;
922 materialized_shared_state_ = shared_state;
923 }
std::uint64_t synchronizeSurrogateRevision(const Eigen::VectorXd &theta_global, double likelihood_noise_floor_sigma2, const SharedParameterState &shared_state={}) const
Definition Session.h:615

◆ refreshSelectedObservation()

void gpr::neb::ActiveLearningSession::ImageModel::refreshSelectedObservation ( int global_row,
const gpr::Observation & global )
inline

A selected global row retains its identity when repeated oracle draws update its targets. Invalidate this image's posterior only when the selected observation changes.

Definition at line 707 of file Session.h.

709 {
710 const auto found = std::find(selected_indices_.begin(),
711 selected_indices_.end(), global_row);
712 if (found == selected_indices_.end()) return;
713 const auto row = static_cast<Eigen::Index>(
714 std::distance(selected_indices_.begin(), found));
715 const bool unchanged =
716 (observations_.R.row(row).array() ==
717 global.R.row(global_row).array())
718 .all() &&
719 observations_.E(row, 0) == global.E(global_row, 0) &&
720 (observations_.G.row(row).array() ==
721 global.G.row(global_row).array())
722 .all();
723 if (unchanged) return;
724 observations_.R.row(row) = global.R.row(global_row);
725 observations_.E.row(row) = global.E.row(global_row);
726 observations_.G.row(row) = global.G.row(global_row);
727 recordObservationMutation();
728 }
FieldMatrixd E

◆ remapGlobalRows()

void gpr::neb::ActiveLearningSession::ImageModel::remapGlobalRows ( const std::vector< int > & old_to_new,
const gpr::Observation & global )
inline

Rewrite global-row indices after a policy prune. ~old_to_new~ maps a previous training row to its row in ~global~, or -1 when that row was dropped. The local observations and, when this image already has a posterior, its factor follow the new order.

Definition at line 776 of file Session.h.

778 {
779 const std::vector<int> previous_selected = selected_indices_;
780 const std::size_t direct_before = direct_indices_.size();
781 auto rewrite = [&old_to_new](std::vector<int>& indices) {
782 std::vector<int> next;
783 next.reserve(indices.size());
784 for (const int old_index: indices) {
785 if (old_index < 0 || static_cast<std::size_t>(old_index) >=
786 old_to_new.size())
787 continue;
788 const int mapped =
789 old_to_new[static_cast<std::size_t>(old_index)];
790 if (mapped >= 0) next.push_back(mapped);
791 }
792 indices.swap(next);
793 };
794 rewrite(selected_indices_);
795 rewrite(direct_indices_);
796 if (direct_indices_.size() < direct_before) {
797 const int removed =
798 static_cast<int>(direct_before - direct_indices_.size());
799 direct_observation_count_ =
800 std::max(0, direct_observation_count_ - removed);
801 }
802 if (selected_indices_ == previous_selected) return;
803 gpr::Observation local;
804 for (const int row: selected_indices_) {
805 if (row < 0 || row >= global.R.rows()) continue;
806 const double energy =
807 row < global.E.rows() ? global.E(row, 0) : 0.0;
808 Eigen::VectorXd gradient(global.R.cols());
809 if (row < global.G.rows())
810 gradient = global.G.row(row).transpose();
811 else
812 gradient.setZero();
813 detail::appendObservationRow(
814 local, global.R.row(row).transpose(), energy, gradient);
815 }
816 observations_ = std::move(local);
817 recordObservationMutation();
818 if (gp_ && observations_.R.rows() > 0 && gp_->hasBeenOptimized()) {
819 const Eigen::VectorXd theta = gp_->packInlaHyperparameters();
820 if (theta.size() > 0) gp_->setParameters(theta);
821 gp_->updateModelWithFullData(observations_);
822 }
823 }

◆ replaceNeighborhood()

void gpr::neb::ActiveLearningSession::ImageModel::replaceNeighborhood ( gpr::Observation observations,
std::vector< int > selected_indices,
std::vector< uint64_t > archived_keys = {} )
inline

Definition at line 877 of file Session.h.

879 {})
880 {
881 observations_ = std::move(observations);
882 selected_indices_ = std::move(selected_indices);
883 archived_keys_ = std::move(archived_keys);
884 recordObservationMutation();
885 }
const gpr::Observation & observations() const
Definition Session.h:494

◆ selectedIndices()

const std::vector< int > & gpr::neb::ActiveLearningSession::ImageModel::selectedIndices ( ) const
inlinenodiscard

Rows of the global ~training_obs~ currently selected into ~observations~ – the EMD k-nearest neighbourhood of this image's position. Ascending-sorted so a caller can compare it against a freshly computed selection to decide whether the neighbourhood membership turned over.

Definition at line 639 of file Session.h.

640 {
641 return selected_indices_;
642 }

◆ setGeodesicReferencePath()

void gpr::neb::ActiveLearningSession::ImageModel::setGeodesicReferencePath ( gpr::Coord reference_path)
inline

Definition at line 553 of file Session.h.

554 {
555 if (reference_path.rows() <= 0 || reference_path.cols() <= 0 ||
556 !reference_path.allFinite()) {
557 throw std::invalid_argument(
558 "image GP requires a finite geodesic reference path");
559 }
560 if (geodesic_reference_path_.rows() == reference_path.rows() &&
561 geodesic_reference_path_.cols() == reference_path.cols() &&
562 (geodesic_reference_path_.array() == reference_path.array())
563 .all()) {
564 return;
565 }
566 geodesic_reference_path_ = std::move(reference_path);
567 if (gp_) {
568 gp_->getSexpAtCovarianceFunction().clearGeodesicHeatKernel();
569 }
570 ++geometry_prior_revision_;
571 ++surrogate_revision_;
572 invalidateMaterialization();
573 }

◆ setGP()

void gpr::neb::ActiveLearningSession::ImageModel::setGP ( std::unique_ptr< gpr::GaussianProcessRegression > next_gp)
inline

Definition at line 477 of file Session.h.

478 {
479 gp_ = std::move(next_gp);
480 ++surrogate_revision_;
481 invalidateMaterialization();
482 }

◆ setInternalCoordinateChart()

void gpr::neb::ActiveLearningSession::ImageModel::setInternalCoordinateChart ( std::shared_ptr< const gpr::geometry::InternalCoordinateChart > chart,
double length_scale )
inline

Definition at line 507 of file Session.h.

510 {
511 if (!chart || !chart->valid() || !(length_scale > 0.0) ||
512 !std::isfinite(length_scale)) {
513 throw std::invalid_argument(
514 "image GP requires a valid internal-coordinate chart");
515 }
516 if (internal_coordinate_chart_ == chart &&
517 internal_coordinate_length_scale_ == length_scale) {
518 return;
519 }
520 internal_coordinate_chart_ = std::move(chart);
521 internal_coordinate_length_scale_ = length_scale;
522 ++geometry_prior_revision_;
523 ++surrogate_revision_;
524 invalidateMaterialization();
525 }

◆ surrogateRevision()

std::uint64_t gpr::neb::ActiveLearningSession::ImageModel::surrogateRevision ( ) const
inlinenodiscardnoexcept

Monotonic version of every input that defines this image's GP. Local observations, inherited global hyperparameters, and the live likelihood-noise floor all affect predictions consumed by MMF, even when the local row set itself is unchanged.

Definition at line 610 of file Session.h.

611 {
612 return surrogate_revision_;
613 }

◆ synchronizeSurrogateRevision()

std::uint64_t gpr::neb::ActiveLearningSession::ImageModel::synchronizeSurrogateRevision ( const Eigen::VectorXd & theta_global,
double likelihood_noise_floor_sigma2,
const SharedParameterState & shared_state = {} ) const
inline

Definition at line 615 of file Session.h.

618 {}) const
619 {
620 if (!surrogate_inputs_initialized_ ||
621 surrogate_shared_state_ != shared_state ||
622 !surrogateInputsMatch(
623 surrogate_theta_, surrogate_noise_floor_sigma2_,
624 theta_global, likelihood_noise_floor_sigma2)) {
625 ++surrogate_revision_;
626 surrogate_theta_ = theta_global;
627 surrogate_noise_floor_sigma2_ = likelihood_noise_floor_sigma2;
628 surrogate_shared_state_ = shared_state;
629 surrogate_inputs_initialized_ = true;
630 }
631 return surrogate_revision_;
632 }

◆ updateConfiguration()

void gpr::neb::ActiveLearningSession::ImageModel::updateConfiguration ( const gpr::AtomsConfiguration & configuration)
inline

Definition at line 499 of file Session.h.

500 {
501 if (gp_) gp_->updateConfiguration(configuration);
502 ++surrogate_revision_;
503 ++geometry_prior_revision_;
504 invalidateMaterialization();
505 }

The documentation for this struct was generated from the following file: