Models

class M_Core

Abstract base class for model cores.

Provides common functionality and interface for model implementations, including training status and weight management.

Subclassed by M_BLR_Core< Function_Base & >, M_KRR_Core< Function_Base & >, M_BLR_Core< BF >, M_KRR_Core< K >, M_Tadah_Base

Public Functions

inline virtual ~M_Core()

Virtual destructor for polymorphic deletion.

inline bool is_trained() const

Checks if the model has been trained.

Returns:

True if the model is trained, otherwise false.

inline const t_type &get_weights() const

Retrieves the weights of the model.

Returns:

Constant reference to the weights vector.

inline void set_weights(const t_type w)

Sets the model weights.

Parameters:

w – New weights vector to be set.

virtual double predict(const aed_type &v) const = 0

Pure virtual function for making predictions.

Must be implemented by derived classes.

Parameters:

v – Input vector for prediction.

Returns:

Predicted value.

virtual t_type get_weights_uncertainty() const = 0

Pure virtual function to get weights’ uncertainty.

Must be implemented by derived classes.

Returns:

Vector of uncertainties for the weights.

Public Members

int verbose = 0

Verbose level for logging.

bool trained = false

Indicates if the model has been trained.

t_type weights

Weights vector for the model.

M_BLR

template<class BF = DM_Function_Base&>
class M_BLR : public M_Tadah_Base, public M_BLR_Train<DM_Function_Base&>

Bayesian Linear Regression (BLR).

This class implements Bayesian Linear Regression, a statistical method to make predictions using linear models with both linear and nonlinear features.

Model Supported Training Modes:

  • LINEAR: Uses Ordinary Least Squares or Ridge Regression for linear relationships.

  • NONLINEAR: Utilizes basis functions to handle nonlinear input spaces, transforming input descriptors into higher-dimensional feature spaces. For example, polynomial transformations.

Prediction:

  • Computes predictions as a weighted sum of basis functions applied to input vectors.

Training:

  • Employs regularized least squares, allowing for optional regularization through the \(\lambda\) parameter.

  • Ordinary Least Squares (OLS) is a special case when \(\lambda = 0\).

Configuration Options:

  • LAMBDA: Set to 0 for OLS, a positive value for specified regularization, or -1 for automatic tuning using evidence approximation.

Template Parameters:

BF – DM_BF_Base child, Basis function

Public Functions

inline M_BLR(Config &c)

Initializes for training or prediction using a configuration.

Example:

Config config("Config");
M_BLR<BF_Linear> blr(config);

Parameters:

c – Configuration object.

inline M_BLR(BF &bf, Config &c)

Initializes for training or prediction using a basis function and configuration.

Parameters:
  • bf – Basis function.

  • c – Configuration object.

inline virtual double epredict(const aed_type &aed) const

Predict local energy of an atom or bond energy.

The result depends on how aed is computed.

If it is computed between a pair of atoms than the result is a bond energy.

If aed contains sum over all nearest neighbours than the result is a local atomic energy \( E_i \).

inline virtual double fpredict(const fd_type &fdij, const aed_type &aedi, const size_t k) const

Predict force between a pair of atoms in a k-direction.

inline virtual force_type fpredict(const fd_type &fdij, const aed_type &aedi) const

Predict force between a pair of atoms.

inline virtual void train(StDescriptorsDB &st_desc_db, const StructureDB &stdb)

This will fit a model with precalculated StDescriptorsDB object.

 Structure stdb object must have all nearest neighbours calculated
 with NN_Finder.

inline virtual void train(StructureDB &stdb, DC_Base &dc)

This will fit a model without precalculated StDescriptorsDB object.

 Structure stdb object must have all nearest neighbours calculated
 with NN_Finder.

 @param dc is a DescriptorCalc object

inline virtual Structure predict(const Config &c, StDescriptors &std, const Structure &st)

Predict energy, forces and stresses for the Structure st.

inline virtual StructureDB predict(Config &c, const StructureDB &stdb, DC_Base &dc)

Predict energy, forces and stresses for a set of Structures.

inline virtual Config get_param_file()

Return potential file.

M_KRR

template<class K = DM_Function_Base&>
class M_KRR : public M_Tadah_Base, public M_KRR_Train<DM_Function_Base&>

Kernel Ridge Regression (KRR) with Empirical Kernel Map (EKM).

This class performs Kernel Ridge Regression using an Empirical Kernel Map to efficiently handle high-dimensional data. EKM is used to map objects into a kernel feature space, where linear methods can be applied.

Empirical Kernel Map (EKM):

  • Maps sample objects into finite-dimensional vectors in the kernel feature space.

  • Requires a kernel and basis samples to project new samples into the space defined by these bases.

  • Facilitates the kernelization of algorithms traditionally operating on vectors.

  • Supports basis sample selection through methods like random sampling or finding linearly independent subsets.

Usage:

  • Kernels: Use kernel functions (e.g., linear, RBF) to transform data for effective modeling in higher-dimensional spaces.

Configuration Options:

  • LAMBDA: Controls regularization. Use 0 for ordinary least squares, positive values for manual setting, or -1 for automatic tuning.

  • SBASIS: Defines the number of basis functions for nonlinear kernels.

Template Parameters:

K – DM_Kern_Base child, Kernel function

Public Functions

inline M_KRR(Config &c)

Initializes for training or prediction using a configuration.

Example:

Config config("Config");
M_KRR<Kern_Linear> krr(config);

Parameters:

c – Configuration object.

inline M_KRR(K &kernel, Config &c)

Initializes for training or prediction using a kernel and configuration.

Parameters:
  • kernel – Kernel function.

  • c – Configuration object.

inline virtual double epredict(const aed_type &aed) const

Predict local energy of an atom or bond energy.

The result depends on how aed is computed.

If it is computed between a pair of atoms than the result is a bond energy.

If aed contains sum over all nearest neighbours than the result is a local atomic energy \( E_i \).

inline virtual double fpredict(const fd_type &fdij, const aed_type &aedi, const size_t k) const

Predict force between a pair of atoms in a k-direction.

inline virtual force_type fpredict(const fd_type &fdij, const aed_type &aedi) const

Predict force between a pair of atoms.

inline virtual void train(StDescriptorsDB &st_desc_db, const StructureDB &stdb)

This will fit a model with precalculated StDescriptorsDB object.

 Structure stdb object must have all nearest neighbours calculated
 with NN_Finder.

inline virtual void train(StructureDB &stdb, DC_Base &dc)

This will fit a model without precalculated StDescriptorsDB object.

 Structure stdb object must have all nearest neighbours calculated
 with NN_Finder.

 @param dc is a DescriptorCalc object

inline virtual Structure predict(const Config &c, StDescriptors &std, const Structure &st)

Predict energy, forces and stresses for the Structure st.

inline virtual StructureDB predict(Config &c, const StructureDB &stdb, DC_Base &dc)

Predict energy, forces and stresses for a set of Structures.

inline virtual Config get_param_file()

Return potential file.