GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
PopulationPrior.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
#ifndef GPR_PRIOR_POPULATION_PRIOR_H_
5
#define GPR_PRIOR_POPULATION_PRIOR_H_
6
7
#include <Eigen/Core>
8
#include <cmath>
9
#include <istream>
10
#include <sstream>
11
#include <string>
12
#include <utility>
13
#include <vector>
14
15
#include "
../../structures/Structures.h
"
16
17
namespace
gpr
{
18
namespace
priors
{
19
30
struct
PopulationPairPrior
{
31
int
element_a
= 0;
32
int
element_b
= 0;
33
int
cells
= 0;
34
double
log_length_mu
= 0.0;
35
double
log_length_sigma
= 0.0;
36
};
37
38
class
PopulationPrior
{
39
public
:
40
[[nodiscard]]
bool
empty
() const noexcept
41
{
42
return
pairs_.empty();
43
}
44
[[nodiscard]] std::size_t
size
() const noexcept
45
{
46
return
pairs_.size();
47
}
48
void
clear
()
49
{
50
pairs_.clear();
51
}
52
void
add
(
PopulationPairPrior
prior)
53
{
54
if
(prior.
element_a
> prior.
element_b
)
55
std::swap(prior.
element_a
, prior.
element_b
);
56
for
(
auto
& existing: pairs_) {
57
if
(existing.element_a == prior.
element_a
&&
58
existing.element_b == prior.
element_b
) {
59
existing = prior;
60
return
;
61
}
62
}
63
pairs_.push_back(prior);
64
}
65
66
[[nodiscard]]
const
PopulationPairPrior
*
find
(
int
element_a,
67
int
element_b)
const
noexcept
68
{
69
if
(element_a > element_b) std::swap(element_a, element_b);
70
for
(
const
auto
& prior: pairs_)
71
if
(prior.element_a == element_a && prior.element_b == element_b)
72
return
&prior;
73
return
nullptr
;
74
}
75
77
bool
read
(std::istream& input)
78
{
79
std::string line;
80
while
(std::getline(input, line)) {
81
const
auto
hash = line.find(
'#'
);
82
if
(hash != std::string::npos) line.erase(hash);
83
std::istringstream row(line);
84
PopulationPairPrior
prior;
85
if
(!(row >> prior.
element_a
))
continue
;
86
if
(!(row >> prior.
element_b
>> prior.
cells
>>
87
prior.
log_length_mu
>> prior.
log_length_sigma
) ||
88
!std::isfinite(prior.
log_length_mu
) ||
89
!std::isfinite(prior.
log_length_sigma
) ||
90
prior.
log_length_sigma
< 0.0)
91
return
false
;
92
add
(prior);
93
}
94
return
true
;
95
}
96
99
[[nodiscard]] std::vector<const PopulationPairPrior*>
perPairtype
(
100
const
AtomsConfiguration
& conf)
const
101
{
102
std::vector<const PopulationPairPrior*> entries(
103
static_cast<
std::size_t
>
(conf.
n_pt
),
nullptr
);
104
if
(pairs_.empty() || conf.
n_pt
<= 0)
return
entries;
105
const
Eigen::Index n_types = conf.
pairtype
.rows();
106
std::vector<int> type_to_Z(
static_cast<
std::size_t
>
(n_types), -1);
107
const
auto
& types = conf.
type
.size() == conf.
atomicNrs
.size()
108
? conf.
type
109
: conf.
atoms_mov
.
type
;
110
const
Eigen::Index count =
111
std::min(types.size(), conf.
atomicNrs
.size());
112
for
(Eigen::Index atom = 0; atom < count; ++atom) {
113
const
auto
type =
static_cast<
Eigen::Index
>
(types.data()[atom]);
114
if
(type < 0 || type >= n_types)
continue
;
115
if
(type_to_Z[
static_cast<
std::size_t
>
(type)] == -1)
116
type_to_Z[
static_cast<
std::size_t
>
(type)] =
117
conf.
atomicNrs
.data()[atom];
118
}
119
for
(Eigen::Index ti = 0; ti < n_types; ++ti) {
120
for
(Eigen::Index tj = ti; tj < n_types; ++tj) {
121
if
(ti >= conf.
pairtype
.rows() || tj >= conf.
pairtype
.cols())
122
continue
;
123
const
auto
k =
static_cast<
Eigen::Index
>
(conf.
pairtype
(ti, tj));
124
if
(k < 0 || k >= conf.
n_pt
)
continue
;
125
const
int
za = type_to_Z[
static_cast<
std::size_t
>
(ti)];
126
const
int
zb = type_to_Z[
static_cast<
std::size_t
>
(tj)];
127
if
(za < 0 || zb < 0)
continue
;
128
if
(entries[
static_cast<
std::size_t
>
(k)] ==
nullptr
)
129
entries[
static_cast<
std::size_t
>
(k)] =
find
(za, zb);
130
}
131
}
132
return
entries;
133
}
134
135
private
:
136
std::vector<PopulationPairPrior> pairs_;
137
};
138
139
}
// namespace priors
140
}
// namespace gpr
141
142
#endif
// GPR_PRIOR_POPULATION_PRIOR_H_
Structures.h
gpr::priors::PopulationPrior
Definition
PopulationPrior.h:38
gpr::priors::PopulationPrior::size
std::size_t size() const noexcept
Definition
PopulationPrior.h:44
gpr::priors::PopulationPrior::empty
bool empty() const noexcept
Definition
PopulationPrior.h:40
gpr::priors::PopulationPrior::clear
void clear()
Definition
PopulationPrior.h:48
gpr::priors::PopulationPrior::add
void add(PopulationPairPrior prior)
Definition
PopulationPrior.h:52
gpr::priors::PopulationPrior::perPairtype
std::vector< const PopulationPairPrior * > perPairtype(const AtomsConfiguration &conf) const
Definition
PopulationPrior.h:99
gpr::priors::PopulationPrior::read
bool read(std::istream &input)
Definition
PopulationPrior.h:77
gpr::priors::PopulationPrior::find
const PopulationPairPrior * find(int element_a, int element_b) const noexcept
The entry of an element pair, in either order; null when unseen.
Definition
PopulationPrior.h:66
gpr::priors
Prior distributions and prior-mean functions for the GP.
Definition
CovalentBondPrior.h:34
gpr
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition
Macros.h:16
gpr::AtomsConfiguration
Stores configurations of all atoms in the system.
Definition
Structures.h:832
gpr::AtomsConfiguration::atomicNrs
FieldMatrixi atomicNrs
Atomic Number of each atom.
Definition
Structures.h:836
gpr::AtomsConfiguration::pairtype
FieldMatrixi pairtype
Definition
Structures.h:847
gpr::AtomsConfiguration::n_pt
Index_t n_pt
Definition
Structures.h:850
gpr::AtomsConfiguration::atoms_mov
AtomsPositionAndType atoms_mov
Info on moving atoms.
Definition
Structures.h:844
gpr::AtomsConfiguration::type
FieldMatrixIdx type
Type of each atom.
Definition
Structures.h:839
gpr::AtomsPositionAndType::type
FieldMatrixIdx type
Definition
Structures.h:812
gpr::priors::PopulationPairPrior
Definition
PopulationPrior.h:30
gpr::priors::PopulationPairPrior::log_length_sigma
double log_length_sigma
Definition
PopulationPrior.h:35
gpr::priors::PopulationPairPrior::element_b
int element_b
Definition
PopulationPrior.h:32
gpr::priors::PopulationPairPrior::log_length_mu
double log_length_mu
Definition
PopulationPrior.h:34
gpr::priors::PopulationPairPrior::element_a
int element_a
Definition
PopulationPrior.h:31
gpr::priors::PopulationPairPrior::cells
int cells
Definition
PopulationPrior.h:33
gpr
prior
PopulationPrior.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf