3 #include <boost/math/special_functions/erf.hpp>
44 (observations(0) == 0.0) ? 1e-8 : std::abs(observations(0)) * 1e-8;
46 N = observations.size();
47 bool is_even = ((N % 2) == 0);
54 if (std::abs(observations(i) - observations(0)) > eps) {
66 start2 = (is_even) ? N / 2 : (N / 2) + 1;
69 sum1 = observations.head(start2).sum();
71 sum2 = observations.segment(start2, N - start2).sum();
78 while (std::abs((sum1 / (start2 - start1)) - (sum2 / (N - start2))) > prec &&
88 sum1 -= observations(start1);
89 sum1 += observations(start2);
90 sum2 -= observations(start2);
93 sum1 -= observations(start1);
101 double mean_tot = (sum1 + sum2) / (N - start1);
103 if (observations(start1) < mean_tot) {
104 while (observations(start1) < mean_tot && start1 < N - 1) start1++;
106 while (observations(start1) > mean_tot && start1 < N - 1) start1++;
134 : m_is_converged(false),
135 m_mean(observations.mean()),
136 m_squared_norm(observations.squaredNorm()) {
138 double z_alpha = sqrt(2.0) * boost::math::erf_inv(conf);
146 std::tie(found_rho, rho, CoVar0) =
_calc_rho(observations);
154 double var_of_mean = (CoVar0 / N) * (1.0 + rho) / (1.0 - rho);
162 return (X - vmean).dot(Y - vmean) / X.size();
176 if (std::abs(CoVar0 /
m_mean) < 1e-8 || CoVar0 == 0.0) {
178 return std::make_tuple(
true, pow(2.0, -1.0 / 1), CoVar0);
185 double cov =
covariance(observations.segment(0, range_size),
186 observations.segment(i, range_size),
m_mean);
188 if (std::abs(cov / CoVar0) <= 0.5) {
189 return std::make_tuple(
true, pow(2.0, (-1.0 / i)), CoVar0);
194 return std::make_tuple(
false, 0.0, CoVar0);
std::tuple< bool, double, double > _calc_rho(const Eigen::VectorXd &observations)
Try to find rho = pow(2.0, -1.0/i), using min i such that CoVar[i]/CoVar[0] <= 0.5.
MCData::size_type size_type
MCDataConvergence()
Default constructor.
MCDataEquilibration()
Default constructor.
size_type m_equil_samples
MCData::size_type size_type
double covariance(const Eigen::VectorXd &X, const Eigen::VectorXd &Y, double mean)