26 #include <boost/container/static_vector.hpp>
41 double &transformed_weight,
42 double &transformed_mean,
43 double &transformed_var) {
44 const auto &[weight,
mean, var] =
cmp;
46 transformed_weight = std::log(weight) - std::log(1 - weight);
47 transformed_mean = std::log(mean) - std::log(1 - mean);
48 transformed_var = std::log(var);
54 double transformed_mean,
55 double transformed_var) {
57 cmp.
weight = 1. / (1 + std::exp(-transformed_weight));
58 cmp.
mean = 1. / (1 + std::exp(-transformed_mean));
59 cmp.
var = std::exp(transformed_var);
85 std::array<detail::GaussianComponent, 1> ret{};
89 const double c = x / std::log(2);
90 ret[0].mean = std::pow(2, -c);
91 ret[0].var = std::pow(3, -c) - std::pow(4, -c);
101 template <
int NComponents,
int PolyDegree>
103 static_assert(NComponents > 0);
104 static_assert(PolyDegree > 0);
113 using Data = std::array<PolyData, NComponents>;
136 bool low_transform,
bool high_transform)
156 boost::container::static_vector<detail::GaussianComponent, NComponents>;
159 const std::array<ActsScalar, PolyDegree + 1> &coeffs) {
161 for (
const auto c : coeffs) {
164 assert((std::isfinite(
sum) &&
"polynom result not finite"));
171 Array ret(NComponents);
173 for (
int i = 0;
i < NComponents; ++
i) {
178 poly(xx, data[
i].weightCoeffs),
poly(xx, data[
i].meanCoeffs),
179 poly(xx, data[
i].varCoeffs));
181 ret[
i].weight =
poly(xx, data[
i].weightCoeffs);
182 ret[
i].mean =
poly(xx, data[
i].meanCoeffs);
183 ret[
i].var =
poly(xx, data[
i].varCoeffs);
186 weight_sum += ret[
i].weight;
189 for (
int i = 0;
i < NComponents; ++
i) {
190 ret[
i].weight /= weight_sum;
232 std::ifstream
file(filepath);
235 throw std::invalid_argument(
"Could not open '" + filepath +
"'");
238 std::size_t n_cmps = 0,
degree = 0;
239 bool transform_code =
false;
241 file >> n_cmps >>
degree >> transform_code;
243 if (NComponents != n_cmps) {
244 throw std::invalid_argument(
"Wrong number of components in '" +
248 if (PolyDegree !=
degree) {
249 throw std::invalid_argument(
"Wrong polynom order in '" + filepath +
255 for (
auto &
cmp : data) {
256 for (
auto &coeff :
cmp.weightCoeffs) {
259 for (
auto &coeff :
cmp.meanCoeffs) {
262 for (
auto &coeff :
cmp.varCoeffs) {
270 const auto [low_data, low_transform] = read_file(low_parameters_path);
271 const auto [high_data, high_transform] = read_file(high_parameters_path);