CASM  1.1.0
A Clusters Approach to Statistical Mechanics
ConfigIONovelty.cc
Go to the documentation of this file.
2 
4 #include "casm/clex/ConfigIO.hh"
6 #include "casm/clex/PrimClex.hh"
9 
10 namespace CASM {
11 
12 namespace ConfigIO {
13 bool Novelty::init(const Configuration &_tmplt) const {
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
19  // and column corresponds to correlation value
21 
22  DB::Selection<Configuration> select(_tmplt.primclex().db<Configuration>(),
23  m_selection);
24  mat_wrapper << m_format(select.all().begin(), select.all().end());
25 
26  m_avg_corr = mat_wrapper.matrix().colwise().sum().transpose() /
27  double(mat_wrapper.matrix().cols());
28 
29  Eigen::MatrixXd tcovar = mat_wrapper.matrix().transpose() *
30  mat_wrapper.matrix() /
31  double(mat_wrapper.matrix().cols()) -
32  m_avg_corr * m_avg_corr.transpose();
33 
34  m_gram_mat = (double(tcovar.rows()) * tcovar +
35  1E-6 * Eigen::MatrixXd::Identity(tcovar.rows(), tcovar.cols()))
36  .inverse();
37  return true;
38 }
39 
40 //****************************************************************************************
41 bool Novelty::parse_args(const std::string &args) {
42  if (m_selection.size()) return false;
43  if (args.empty())
44  m_selection = "MASTER";
45  else
46  m_selection = args;
47  return true;
48 }
49 
50 // ****************************************************************************************
51 
52 std::string Novelty::short_header(const Configuration &_tmplt) const {
53  return name() + "(" + (m_selection.empty() ? "MASTER" : m_selection) + ")";
54 }
55 
56 // ****************************************************************************************
57 /*
58  void Novelty::inject(const Configuration &_config, DataStream &_stream,
59  Index) const { _stream << _evaluate(_config);
60  }
61 
62  //
63  ****************************************************************************************
64 
65  void Novelty::print(const Configuration &_config, std::ostream &_stream,
66  Index) const { _stream.flags(std::ios::showpoint | std::ios::fixed |
67  std::ios::right); _stream.precision(8);
68 
69  _stream << _evaluate(_config);
70  }
71 
72  //
73  ****************************************************************************************
74 
75  jsonParser &Novelty::to_json(const Configuration &_config, jsonParser
76  &json)const { json = _evaluate(_config); return json;
77  }
78 */
79 
80 //****************************************************************************************
81 
82 double Novelty::evaluate(const Configuration &_config) const {
84  tstr << m_format(_config);
85  Eigen::Map<const Eigen::VectorXd> corr(tstr.vector().data(),
86  tstr.vector().size());
87  return sqrt(double((corr - m_avg_corr).transpose() * m_gram_mat *
88  (corr - m_avg_corr)));
89 }
90 } // namespace ConfigIO
91 } // namespace CASM
const std::string & name() const
Returns a name for the formatter, which becomes the tag used for parsing.
Returns correlation values.
Definition: ConfigIO.hh:197
std::string short_header(const Configuration &_config) const override
bool parse_args(const std::string &args) override
bool init(const Configuration &_tmplt) const override
double evaluate(const Configuration &_config) const override
std::string m_selection
specifies which selection to use as the population
DataFormatter< Configuration > m_format
Formatter which is used to obtain correlations.
Eigen::VectorXd m_avg_corr
The average correlation vector of the population.
Eigen::MatrixXd m_gram_mat
Gram matrix, which defind Mahalanobis scalar product.
boost::iterator_range< iterator > all()
Definition: Selection.cc:222
const Eigen::MatrixXd & matrix()
const std::vector< T > & vector() const
Definition: DataStream.hh:293
Eigen::Matrix< typename Derived::Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime > inverse(const Eigen::MatrixBase< Derived > &M)
Return the integer inverse matrix of an invertible integer matrix.
IdentitySymRepBuilder Identity()
Main CASM namespace.
Definition: APICommand.hh:8
Eigen::MatrixXd MatrixXd