CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
ConfigIONovelty.cc
Go to the documentation of this file.
4 #include "casm/clex/ConfigIO.hh"
7 #include "casm/clex/PrimClex.hh"
8 
9 namespace CASM {
10 
11  namespace ConfigIO {
12  void Novelty::init(const Configuration &_tmplt) const {
13 
14  m_format.clear();
15  m_format.push_back(Corr());
16 
17  // setup DataStream
18  // -- fills a matrix so that each row corresponds to a configuration and column corresponds to correlation value
20 
21  // Cases control which configurations to use for obtaining novelty data
22  if(m_selection == "all")
23  mat_wrapper << m_format(_tmplt.get_primclex().config_cbegin(), _tmplt.get_primclex().config_cend());
24  else if(m_selection == "MASTER" || m_selection.empty())
25  mat_wrapper << m_format(_tmplt.get_primclex().selected_config_cbegin(), _tmplt.get_primclex().selected_config_cend());
26  else {
28  mat_wrapper << m_format(select.selected_config_cbegin(), select.selected_config_cend());
29  }
30 
31  m_avg_corr = mat_wrapper.matrix().colwise().sum().transpose() / double(mat_wrapper.matrix().cols());
32  Eigen::MatrixXd tcovar = mat_wrapper.matrix().transpose() * mat_wrapper.matrix() / double(mat_wrapper.matrix().cols()) - m_avg_corr * m_avg_corr.transpose();
33 
34  m_gram_mat = (double(tcovar.rows()) * tcovar + 1E-6 * Eigen::MatrixXd::Identity(tcovar.rows(), tcovar.cols())).inverse();
35 
36  }
37 
38  //****************************************************************************************
39  bool Novelty::parse_args(const std::string &args) {
40  if(m_selection.size())
41  return false;
42  if(args.empty())
43  m_selection = "MASTER";
44  else
45  m_selection = args;
46  return true;
47  }
48 
49  // ****************************************************************************************
50 
51  std::string Novelty::short_header(const Configuration &_tmplt) const {
52  return name() + "(" + (m_selection.empty() ? "MASTER" : m_selection) + ")";
53  }
54 
55  // ****************************************************************************************
56  /*
57  void Novelty::inject(const Configuration &_config, DataStream &_stream, Index) const {
58  _stream << _evaluate(_config);
59  }
60 
61  // ****************************************************************************************
62 
63  void Novelty::print(const Configuration &_config, std::ostream &_stream, Index) const {
64  _stream.flags(std::ios::showpoint | std::ios::fixed | std::ios::right);
65  _stream.precision(8);
66 
67  _stream << _evaluate(_config);
68  }
69 
70  // ****************************************************************************************
71 
72  jsonParser &Novelty::to_json(const Configuration &_config, jsonParser &json)const {
73  json = _evaluate(_config);
74  return json;
75  }
76  */
77 
78  //****************************************************************************************
79 
80  double Novelty::evaluate(const Configuration &_config) const {
82  tstr << m_format(_config);
83  Eigen::Map<const Eigen::VectorXd> corr(tstr.vector().data(), tstr.vector().size());
84  return sqrt(double((corr - m_avg_corr).transpose() * m_gram_mat * (corr - m_avg_corr)));
85  }
86  }
87 }
88 
Eigen::MatrixXd MatrixXd
const std::string & name() const
Returns a name for the formatter, which becomes the tag used for parsing.
bool parse_args(const std::string &args) override
Eigen::MatrixXd m_gram_mat
Gram matrix, which defind Mahalanobis scalar product.
PrimClex & get_primclex() const
Get the PrimClex for this Configuration.
double evaluate(const Configuration &_config) const override
void init(const Configuration &_tmplt) const override
std::string m_selection
specifies which selection to use as the population
Eigen::VectorXd m_avg_corr
The average correlation vector of the population.
Main CASM namespace.
Definition: complete.cpp:8
const Eigen::MatrixXd & matrix()
config_const_iterator selected_config_cend() const
const Configuration iterator: end
Definition: PrimClex.cc:438
config_const_iterator selected_config_cbegin() const
const Configuration iterator: begin
Definition: PrimClex.cc:430
config_const_iterator config_cend() const
const Configuration iterator: end
Definition: PrimClex.cc:407
std::string short_header(const Configuration &_config) const override
config_const_iterator config_cbegin() const
const Configuration iterator: begin
Definition: PrimClex.cc:399
DataFormatter< Configuration > m_format
Formatter which is used to obtain correlations.
const std::vector< T > & vector() const
Definition: DataStream.hh:336
Returns correlation values.
Definition: ConfigIO.hh:281
A Configuration represents the values of all degrees of freedom in a Supercell.