Skip to content
Snippets Groups Projects
Commit 679c69f6 authored by mkirsz's avatar mkirsz
Browse files

More refactoring

parent 4b78a88a
No related branches found
No related tags found
No related merge requests found
......@@ -10,24 +10,24 @@ class M_Base {
public:
//Normaliser norm; // TODO?
virtual ~M_Base() {};
/** \brief 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 \f$ E_i \f$.
* */
virtual double epredict(const aed_rctype &aed)=0;
/** \brief Predict force between a pair of atoms in a k-direction. */
virtual double fpredict(const fd_type &fdij, const aed_rctype &aedi, size_t k)=0;
/** \brief Predict force between a pair of atoms. */
virtual force_type fpredict(const fd_type &fdij,
const aed_rctype &aedi)=0;
//
// /** \brief 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 \f$ E_i \f$.
// * */
// virtual double epredict(const aed_rctype &aed)=0;
//
// /** \brief Predict force between a pair of atoms in a k-direction. */
// virtual double fpredict(const fd_type &fdij, const aed_rctype &aedi, size_t k)=0;
//
// /** \brief Predict force between a pair of atoms. */
// virtual force_type fpredict(const fd_type &fdij,
// const aed_rctype &aedi)=0;
};
......
......@@ -11,13 +11,20 @@
template
<class BF=Function_Base&>
class M_BLR_Core: public virtual M_Core {
class M_BLR_Core:
public virtual M_Core,
public virtual M_Predict,
public virtual M_Train {
public:
Config &config;
//using M_Core<BF>::weights;
//using M_Core<BF>::trained;
//using M_Core<BF>::config;
mat Sigma;
Config &config;
BF bf;
M_BLR_Core(Config &c):
config(c),
//M_Core<BF>(c),
bf(c)
{
static_assert(std::is_base_of<BF_Base, BF>::value,
......@@ -31,6 +38,7 @@ class M_BLR_Core: public virtual M_Core {
M_BLR_Core(BF &bf, Config &c):
config(c),
//M_Core<BF>(bf,c),
bf(bf)
{
if (dynamic_cast<BF_Base*>(&bf) == nullptr)
......@@ -67,7 +75,7 @@ class M_BLR_Core: public virtual M_Core {
trained=true;
}
M_Core::verbose=(config.get<int>("VERBOSE"));
verbose=(config.get<int>("VERBOSE"));
}
};
#endif
......@@ -3,8 +3,21 @@
#include "../CORE/typedefs.h"
//template
//<class F=Function_Base&>
class M_Core {
public:
// F f;
// Config &config;
//
// M_Core(Config &c):
// config(c),
// f(c)
// {}
// M_Core(F &f, Config &c):
// config(c),
// f(f)
// {}
int verbose;
bool trained=false;
t_type weights;
......@@ -12,7 +25,6 @@ class M_Core {
virtual ~M_Core() {}
virtual double predict(const rvec &v)const=0;
virtual void train(phi_type &Phi, const t_type &T)=0;
virtual t_type get_weights_uncertainty()const=0;
bool is_trained() const {
......@@ -25,4 +37,33 @@ class M_Core {
weights=w;
}
};
class M_Predict {
public:
virtual ~M_Predict() {}
/** \brief 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 \f$ E_i \f$.
* */
virtual double epredict(const aed_rctype &aed)=0;
/** \brief Predict force between a pair of atoms in a k-direction. */
virtual double fpredict(const fd_type &fdij, const aed_rctype &aedi, size_t k)=0;
/** \brief Predict force between a pair of atoms. */
virtual force_type fpredict(const fd_type &fdij,
const aed_rctype &aedi)=0;
};
class M_Train {
public:
virtual ~M_Train() {}
virtual void train(phi_type &Phi, const t_type &T)=0;
};
#endif
......@@ -12,14 +12,21 @@
template
<class K=Function_Base&>
class M_KRR_Core: public virtual M_Core {
class M_KRR_Core:
public virtual M_Core,
public virtual M_Predict,
public virtual M_Train {
public:
Config &config;
//using M_Core<K>::weights;
//using M_Core<K>::trained;
//using M_Core<K>::config;
mat Sigma;
Config &config;
K kernel;
EKM<K> ekm;
M_KRR_Core(Config &c):
config(c),
//M_Core<K>(c),
kernel(c),
ekm(c)
{
......@@ -33,6 +40,7 @@ class M_KRR_Core: public virtual M_Core {
M_KRR_Core(K &kernel, Config &c):
config(c),
//M_Core<K>(kernel, c),
kernel(kernel),
ekm(kernel)
{
......@@ -75,7 +83,7 @@ class M_KRR_Core: public virtual M_Core {
trained=true;
}
M_Core::verbose=(config.get<int>("VERBOSE"));
verbose=(config.get<int>("VERBOSE"));
}
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment