3 #include "catch2/catch_all.hpp"
22 CHECK(0 == energy_function(x));
23 for (
t_uint i = 1; i < 10; i++) {
24 const t_real alpha = 0.9 + i * 0.01;
26 CHECK(gamma == Approx(
N * (std::sqrt(16 * std::log(3 / (1 - alpha)) /
N) + 1)));
30 const t_Vector x = t_Vector::Constant(
N, 0.5);
32 return (input.array()).cwiseAbs().maxCoeff();
34 constexpr
t_real gamma = 1.;
35 std::tuple<t_uint, t_uint, t_uint, t_uint>
const region = std::make_tuple(0, 0,
rows,
cols);
40 std::tie(lower, mean, upper) =
42 CHECK(std::abs(lower + 1.5) <= 1e-2);
43 CHECK(std::abs(mean - 0.5) <= 1e-2);
44 CHECK(std::abs(upper - 0.5) <= 1e-2);
50 std::make_tuple(std::floor(
rows * 0.25), std::floor(
cols * 0.25), std::floor(
rows * 0.5),
51 std::floor(
cols * 0.5)),
52 energy_function, gamma);
53 CHECK(std::abs(lower + 1.5) <= 1e-2);
54 CHECK(std::abs(upper - 0.5) <= 1e-2);
55 CHECK(std::abs(mean - 0.5) <= 1e-2);
61 TEST_CASE(
"calculating upper and lower interval grid") {
62 constexpr
t_uint pix_size = 16;
63 const t_uint grid_cols = std::floor(
cols / pix_size);
64 const t_uint grid_rows = std::floor(
rows / pix_size);
65 constexpr
t_real gamma = 1.;
70 const t_Vector x = t_Vector::Map(image.data(), image.size());
72 return input.cwiseAbs().maxCoeff();
77 std::tie(lower, mean, upper) = credible_region::credible_interval_grid<t_Vector, t_real>(
78 x,
rows,
cols, pix_size, energy_function, gamma);
79 CHECK(expected_lower.isApprox(lower, 1e-2));
80 CHECK(expected_mean.isApprox(mean, 1e-2));
81 CHECK(expected_upper.isApprox(upper, 1e-2));
84 TEST_CASE(
"calculating upper and lower interval grid non const") {
85 constexpr
t_uint pix_size = 16;
89 const t_uint grid_cols = std::ceil(
cols / pix_size);
90 const t_uint grid_rows = std::ceil(
rows / pix_size);
92 const t_Vector x = t_Vector::Map(image.data(), image.size());
94 return input.cwiseAbs().maxCoeff();
96 constexpr
t_real gamma = 1.;
100 std::tie(lower, mean, upper) = credible_region::credible_interval_grid<t_Vector, t_real>(
101 x,
rows,
cols, pix_size, energy_function, gamma);
105 CHECK(expected_lower.isApprox(lower, 1e-2));
106 CHECK(expected_mean.isApprox(mean, 1e-2));
107 CHECK(expected_upper.isApprox(upper, 1e-2));
sopt::Vector< Scalar > t_Vector
TEST_CASE("calculating gamma")
std::tuple< t_real, t_real, t_real > find_credible_interval(const Eigen::MatrixBase< T > &solution, const t_uint &rows, const t_uint &cols, const std::tuple< t_uint, t_uint, t_uint, t_uint > ®ion, const std::function< t_real(typename T::PlainObject)> &objective_function, const t_real &energy_upperbound)
t_real compute_energy_upper_bound(const t_real &alpha, const Eigen::MatrixBase< T > &solution, const std::function< t_real(typename T::PlainObject)> &objective_function)
void set_level(const std::string &level)
Method to set the logging level of the default Log object.
double t_real
Root of the type hierarchy for real numbers.
size_t t_uint
Root of the type hierarchy for unsigned integers.
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Image
A 2-dimensional list of elements of given type.
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
std::complex< t_real > t_complex
Root of the type hierarchy for (real) complex numbers.