Models

class M_Base

Base class for all models.

All models must inherit this class and implement all methods.

Naming convention used: M_ModelName

Subclassed by M_BLR< BF >, M_KRR< K >

Public Functions

virtual double epredict(const aed_rctype &aed) = 0

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 \).

double epredict(const StDescriptors &std)

Predict total energy for a set of atoms.

virtual double fpredict(const fd_type &fdij, const aed_rctype &aedi, size_t k) = 0

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

virtual force_type fpredict(const fd_type &fdij, const aed_rctype &aedi) = 0

Predict force between a pair of atoms.

virtual void fpredict(const size_t a, force_type &v, const StDescriptors &std, const Structure &st)

Predict total force on an atom a.

virtual force_type fpredict(const size_t a, const StDescriptors &std, const Structure &st)

Predict total force on an atom a.

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

Predict energy, forces and stresses for the Structure st.

virtual StructureDB predict(const Config &c, StDescriptorsDB &st_desc_db, const StructureDB &stdb)

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

Use precalculated descriptors.

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

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

virtual stress_type spredict(const StDescriptors &std, const Structure &st)

Predict virial stresses in a Structure st.

virtual stress_type spredict(const size_t a, const StDescriptors &std, const Structure &st)

Predict virial stresses in all Structures.

virtual void spredict(const size_t a, stress_type &s, const StDescriptors &std, const Structure &st)

Predict virial stress for atom a in a Structure st.

inline virtual void train(StructureDB&, DC_Base&)

This will fit a model without precalculated StDescriptorsDB object.

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

Parameters:

dc – is a DescriptorCalc object

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

This will fit a model with precalculated StDescriptorsDB object.

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

M_BLR

template<class BF = Func_Base&>
class M_BLR : public M_Base

Bayesian Linear Regression

Model supported training modes:

  • LINEAR: Ordinary Least Squares or Ridge Regression (Regularised Least Squares)

  • NONLINEAR: Linear in parameters but nonlinear in an input space. Each row of a matrix \(\Phi\) is a vector-valued function of the original input descriptor \( \mathbf{\phi(x)}^T \) e.g. BF_Polynomial2: (1, x_1, x_2) -> (1, x_1, x_2, x_1x_2, x_1^2, x_2^2)

Basis functions are selected at random. Number of basis functions is controled by SBASIS key in a Config file.

Prediction:

\[ y(\mathbf{x}, \mathbf{w}) = \sum_{j=0}^{M-1} w_j \phi_j(\mathbf(x)) \]

where M is a number of parameters, w are machine learned weights and x is a vector of input variables.

Training:

\[ \mathbf{w} = (\lambda \mathbf{I} + \mathbf{X}^T \mathbf{X})^{-1} \mathbf{X}^T \mathbf{y} \]

for \(\lambda=0\) this reduces to Ordinary Last Squares (OLS) aka Linear Least Squares with the normal equation:

\[ \mathbf{w} = (\mathbf{X}^T \mathbf{X})^{-1} \mathbf{X}^T \mathbf{y} \]

This model is always a linear function of its parameters \(w_i\).

When used with linear basis function \(\phi\) (here BF_Linear) it is also linear wrt to the input variables (here descriptors).

When nonlinear basis function \(\phi\) is used the function \(y(\mathbf{x}, \mathbf{w})\) becomes nonlinear wrt to x but still linear wrt to w.

Optional Config keys:

  • LAMBDA = 0 -> use OLS

  • LAMBDA > 0 -> manually set to given value

  • LAMBDA = -1 -> use evidence approximation to find \(\lambda\)

  • SBASIS N -> Use N basis functions when nonlinear BF is used

Template Parameters:

BFBF_Base child, Basis function

Public Functions

inline M_BLR(Config &c)

This constructor will preapare this object for either training or prediction (if potential is provides as a Config)

Usage example:

Config config("Config");
M_BLR<BF_Linear> blr(config);
inline M_BLR(BF &bf, Config &c)

This constructor will preapare this object for either training or prediction (if potential is provides as a Config)

Usage example:

Config config("Config");
BF_Linear bf(config);
M_BLR<> blr(bf, config);
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.

Parameters:

dc – is a DescriptorCalc object

inline virtual double epredict(const aed_rctype &aed)

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_rctype &aedi, const size_t k)

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

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

Predict force between a pair of atoms.

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

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

M_KRR

template<typename K = Func_Base&>
class M_KRR : public M_Base, public LinearRegressor

Kernel Ridge Regression implemented via Empirical Kernel Map

Optional Config keys:

  • LAMBDA = 0 -> use OLS

  • LAMBDA > 0 -> manually set to given value

  • LAMBDA = -1 -> use evidence approximation to find \(\lambda\)

  • SBASIS N -> Use N basis functions when nonlinear K is used

Template Parameters:

KKern_Base child, Kernel function

Public Functions

inline M_KRR(Config &c)

This constructor will preapare this object for either training or prediction (if potential is provides as a Config)

Usage example:

Config config("Config");
M_KRR<Kern_Linear> blr(config);
inline M_KRR(K &k, Config &c)

This constructor will preapare this object for either training or prediction (if potential is provides as a Config)

Usage example:

Config config("Config");
Kern_Linear kern(config);
M_KRR<> krr(kern, config);
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.

Parameters:

dc – is a DescriptorCalc object

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 double epredict(const aed_rctype &aed)

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_rctype &aedi, const size_t k)

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

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

Predict force between a pair of atoms.

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

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