5 #ifndef CALOCLUSTERCORRECTION_CALOCLUSTERMLCALIBGAUSSIANMIXTURE_H
6 #define CALOCLUSTERCORRECTION_CALOCLUSTERMLCALIBGAUSSIANMIXTURE_H
23 return -std::numeric_limits<float>::infinity();
25 float max_val = *std::max_element(
vec.begin(),
vec.end());
34 float log_likelihood(
float x,
const std::vector<float> &mus,
const std::vector<float> &log_sigma2s,
const std::vector<float> &alphas)
37 assert(mus.size() == 3 && log_sigma2s.size() == 3 && alphas.size() == 3);
39 std::vector<float> log_likelihood_components(3);
41 for (
int i = 0;
i < 3; ++
i)
44 float neg_log_gauss =
std::pow(mus[
i] -
x, 2.0) / (2.0 *
std::exp(log_sigma2s[
i])) + 0.5 * log_sigma2s[
i];
55 float modes(
const std::vector<float> &mus,
const std::vector<float> &log_sigma2s,
const std::vector<float> &alphas)
58 float x_min = 0.9 * (*std::min_element(mus.begin(), mus.end()));
59 float x_max = 1.1 * (*std::max_element(mus.begin(), mus.end()));
62 const int num_points = 1000;
63 std::vector<float> x_test(num_points);
64 float step = (x_max - x_min) / (num_points - 1);
65 for (
int i = 0;
i < num_points; ++
i)
67 x_test[
i] = x_min +
i *
step;
70 float max_log_likelihood = -std::numeric_limits<float>::infinity();
71 float mode = x_test[0];
74 for (
float x : x_test)
77 if (
ll > max_log_likelihood)
79 max_log_likelihood =
ll;
88 const std::vector<float> &log_sigma2s,
89 const std::vector<float> &alphas)
91 float sigma_stoch2 = 0.0;
92 float sum_alphas_mus = 0.0;
95 for (
size_t i = 0;
i < mus.size(); ++
i)
98 sigma_stoch2 += alphas[
i] *
std::exp(log_sigma2s[
i]);
100 sigma_stoch2 += alphas[
i] *
std::pow(mus[
i], 2);
102 sum_alphas_mus += alphas[
i] * mus[
i];
106 sigma_stoch2 -=
std::pow(sum_alphas_mus, 2);
109 return std::sqrt(sigma_stoch2);
113 #endif // CALOCLUSTERCORRECTION_CALOCLUSTERMLCALIBGAUSSIANMIXTURE_H