Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • tadah/models
1 result
Show changes
Commits on Source (2)
......@@ -3,7 +3,7 @@
#include "../../CORE/registry.h"
#include "../../CORE/core_types.h"
#include "../../CORE/eigen_types.h"
//#include "../../CORE/eigen_types.h"
#include "../../CORE/config/config.h"
#include <iomanip>
......
......@@ -23,12 +23,17 @@ class LinearRegressor {
public:
static void train(Config &config, const phi_type &Phi, const t_type &T,
t_type &weights, mat &Sigma) {
// Convert t_type to Eigen type
vec ww=Eigen::Map<vec>(weights.data.data(),weights.data.size());
vec TT=Eigen::Map<const vec>(T.data.data(),T.data.size());
int verbose = config.get<int>("VERBOSE");
double lambda=config.get<double>("LAMBDA");
if (lambda == 0)
weights = Phi.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(T);
ww = Phi.bdcSvd(Eigen::ComputeThinU | Eigen::ComputeThinV).solve(TT);
else {
double alpha = config.get<double>("ALPHA");
double beta = config.get<double>("BETA");
......@@ -47,7 +52,7 @@ class LinearRegressor {
if (lambda<0) {
EA ea(config);
ea.run(Phi,T,S,U,V,alpha,beta);
ea.run(Phi,TT,S,U,V,alpha,beta);
lambda=alpha/beta;
mat P_inv(S.rows(),S.rows());
......@@ -74,11 +79,12 @@ class LinearRegressor {
D(i,i) = 0.0;
}
if (verbose) std::cout << std::endl << "REG LAMBDA: " << lambda << std::endl;
weights = V*D*U.transpose()*T;
//weights = beta*Sigma*V*S.asDiagonal()*U.transpose()*T;
ww = V*D*U.transpose()*TT;
//weights = beta*Sigma*V*S.asDiagonal()*U.transpose()*TT;
// add Sigma to the config file
dump_sigma(config,Sigma);
}
weights = t_type(ww);
}
static void dump_sigma(Config &config, mat &Sigma) {
vec Sigma_as_vector(Eigen::Map<vec>(Sigma.data(), Sigma.cols()*Sigma.rows()));
......
#ifndef M_BLR_TRAIN_H
#define M_BLR_TRAIN_H
#include "m_core.h"
#include "m_train.h"
#include "m_blr_core.h"
#include "linear_regressor.h"
#include "functions/function_base.h"
......
......@@ -2,7 +2,7 @@
#define M_Core_H
#include "../CORE/core_types.h"
#include "../CORE/eigen_types.h"
//#include "../CORE/eigen_types.h"
class M_Core {
public:
......@@ -25,32 +25,4 @@ class M_Core {
virtual double predict(const aed_type2 &v)const=0;
virtual t_type get_weights_uncertainty()const=0;
};
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_type2 &aed)=0;
/** \brief Predict force between a pair of atoms in a k-direction. */
virtual double fpredict(const fd_type &fdij, const aed_type2 &aedi, size_t k)=0;
/** \brief Predict force between a pair of atoms. */
virtual force_type fpredict(const fd_type &fdij,
const aed_type2 &aedi)=0;
};
class M_Train {
public:
virtual ~M_Train() {}
virtual void train(phi_type &Phi, const t_type &T)=0;
};
#endif
......@@ -5,7 +5,7 @@
#include "../CORE/config/config.h"
#include "functions/function_base.h"
#include "functions/kernels/kern_base.h"
#include "m_core.h"
#include "m_train.h"
#include "m_krr_core.h"
#include "ekm.h"
......
#ifndef M_PREDICT_H
#define M_PREDICT_H
#include "../CORE/core_types.h"
//#include "../CORE/eigen_types.h"
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_type2 &aed)=0;
/** \brief Predict force between a pair of atoms in a k-direction. */
virtual double fpredict(const fd_type &fdij, const aed_type2 &aedi, size_t k)=0;
/** \brief Predict force between a pair of atoms. */
virtual force_type fpredict(const fd_type &fdij,
const aed_type2 &aedi)=0;
};
#endif
#ifndef M_TRAIN_H
#define M_TRAIN_H
#include "../CORE/core_types.h"
//#include "../CORE/eigen_types.h"
class M_Train {
public:
virtual ~M_Train() {}
virtual void train(phi_type &Phi, const t_type &T)=0;
};
#endif