n2p2 - A neural network potential package
SymFncStatistics.cpp
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17#include "SymFncStatistics.h"
18#include <algorithm> // std::min, std::max
19#include <limits> // std::numeric_limits
20#include "utility.h"
21
22using namespace std;
23using namespace nnp;
24
25SymFncStatistics::Container::Container() :
26 count (0 ),
27 countEW(0 ),
28 type (0 ),
29 min ( numeric_limits<double>::max()),
30 max (-numeric_limits<double>::max()),
31 Gmin (0.0 ),
32 Gmax (0.0 ),
33 sum (0.0 ),
34 sum2 (0.0 ),
35 element("" )
36{
37}
38
40{
43
44 return;
45}
46
48{
49 count = 0;
50 min = numeric_limits<double>::max();
51 max = -numeric_limits<double>::max();
52 sum = 0.0;
53 sum2 = 0.0;
54
55 return;
56}
57
59{
60 countEW = 0;
61 Gmin = 0.0;
62 Gmax = 0.0;
63 type = 0;
64 element = "";
65 indexStructureEW.clear();
66 indexAtomEW.clear();
67 valueEW.clear();
68
69 return;
70}
71
73 collectStatistics (false),
77{
78}
79
80void SymFncStatistics::addValue(size_t index, double value)
81{
82 data[index].count++;
83 data[index].sum += value;
84 data[index].sum2 += value * value;
85 data[index].min = min(data[index].min, value);
86 data[index].max = max(data[index].max, value);
87
88 return;
89}
90
92 size_t type,
93 double value,
94 double Gmin,
95 double Gmax,
96 string element,
97 size_t indexStructure,
98 size_t indexAtom)
99{
100 data[index].countEW++;
101 data[index].Gmin = Gmin;
102 data[index].Gmax = Gmax;
103 data[index].type = type;
104 data[index].element = element;
105 data[index].valueEW.push_back(value);
106 data[index].indexStructureEW.push_back(indexStructure);
107 data[index].indexAtomEW.push_back(indexAtom);
108
109 return;
110}
111
113{
114 vector<string> vs;
115 for (map<size_t, Container>::const_iterator it = data.begin();
116 it != data.end(); ++it)
117 {
118 SymFncStatistics::Container const& d = it->second;
119 for (size_t i = 0; i < d.valueEW.size(); ++i)
120 {
121 vs.push_back(strpr("### NNP EXTRAPOLATION WARNING ### "
122 "STRUCTURE: %6zu ATOM: %9zu ELEMENT: %2s "
123 "SYMFUNC: %4zu TYPE: %2zu VALUE: %10.3E "
124 "MIN: %10.3E MAX: %10.3E\n",
125 d.indexStructureEW[i],
126 d.indexAtomEW[i],
127 d.element.c_str(),
128 it->first + 1,
129 d.type,
130 d.valueEW[i],
131 d.Gmin,
132 d.Gmax));
133 }
134 }
135
136 return vs;
137}
138
140{
141 size_t n = 0;
142
143 for (map<size_t, Container>::const_iterator it = data.begin();
144 it != data.end(); ++it)
145 {
146 n += it->second.countEW;
147 }
148
149 return n;
150}
151
153{
154 for (map<size_t, Container>::iterator it = data.begin();
155 it != data.end(); ++it)
156 {
157 it->second.resetStatistics();
158 }
159
160 return;
161}
162
164{
165 for (map<size_t, Container>::iterator it = data.begin();
166 it != data.end(); ++it)
167 {
168 it->second.resetExtrapolationWarnings();
169 }
170
171 return;
172}
173
175{
176 data.clear();
177 return;
178}
void clear()
Completely erase database.
std::vector< std::string > getExtrapolationWarningLines() const
Get lines with extrapolation warnings.
SymFncStatistics()
Constructor, initializes bool variables.
bool stopOnExtrapolationWarnings
Whether to raise an exception in case of extrapolation warnings.
std::map< std::size_t, Container > data
Map for all symmetry functions containing all gathered information.
void addValue(std::size_t index, double value)
Update symmetry function statistics with one value.
bool collectStatistics
Whether statistics are gathered.
void resetExtrapolationWarnings()
Reset extrapolation warnings for all symmetry functions at once.
void addExtrapolationWarning(std::size_t index, std::size_t type, double value, double Gmin, double Gmax, std::string element, std::size_t indexStructure, std::size_t indexAtom)
Add extrapolation warning entry.
std::size_t countExtrapolationWarnings() const
Count total number of extrapolation warnings.
bool collectExtrapolationWarnings
Whether extrapolation warnings are logged.
bool writeExtrapolationWarnings
Whether to write out extrapolation warnings immediately as they occur.
void resetStatistics()
Reset statistics for all symmetry functions at once.
Definition: Atom.h:28
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90
double d
Definition: nnp-cutoff.cpp:34
Struct containing statistics gathered during symmetry function calculation.
void resetStatistics()
Reset only statistics.
void resetExtrapolationWarnings()
Reset only extrapolation warnings.