]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/daubechies_wavelets/regress_daubechies_accuracy.cpp
1 // (C) Copyright Nick Thompson 2020.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
15 #include <boost/algorithm/string.hpp>
16 #include <boost/math/statistics/linear_regression.hpp>
17 #include <boost/assert.hpp>
20 int main(int argc
, char** argv
)
24 std::cout
<< "Usage: ./regress_accuracy.x foo.csv\n";
27 std::string filename
= std::string(argv
[1]);
28 std::ifstream
ifs(filename
.c_str());
31 std::cerr
<< "Couldn't find file " << filename
<< "\n";
34 std::map
<std::string
, std::vector
<double>> m
;
36 std::string header_line
;
37 std::getline(ifs
, header_line
);
38 std::cout
<< "Header line = " << header_line
<< "\n";
39 std::vector
<std::string
> header_strs
;
40 boost::split(header_strs
, header_line
, boost::is_any_of(","));
41 for (auto & s
: header_strs
) {
42 boost::algorithm::trim(s
);
46 std::vector
<double> r
;
47 std::vector
<double> matched_holder
;
48 std::vector
<double> linear
;
49 std::vector
<double> quadratic_b_spline
;
50 std::vector
<double> cubic_b_spline
;
51 std::vector
<double> quintic_b_spline
;
52 std::vector
<double> cubic_hermite
;
53 std::vector
<double> pchip
;
54 std::vector
<double> makima
;
55 std::vector
<double> fotaylor
;
56 std::vector
<double> quintic_hermite
;
57 std::vector
<double> sotaylor
;
58 std::vector
<double> totaylor
;
59 std::vector
<double> septic_hermite
;
60 while(std::getline(ifs
, line
))
62 std::vector
<std::string
> strs
;
63 boost::split(strs
, line
, boost::is_any_of(","));
66 boost::algorithm::trim(s
);
68 std::vector
<double> v(strs
.size(), std::numeric_limits
<double>::quiet_NaN());
69 for (size_t i
= 0; i
< v
.size(); ++i
)
71 v
[i
] = std::stod(strs
[i
]);
74 matched_holder
.push_back(std::log2(v
[1]));
75 linear
.push_back(std::log2(v
[2]));
76 quadratic_b_spline
.push_back(std::log2(v
[3]));
77 cubic_b_spline
.push_back(std::log2(v
[4]));
78 quintic_b_spline
.push_back(std::log2(v
[5]));
79 cubic_hermite
.push_back(std::log2(v
[6]));
80 pchip
.push_back(std::log2(v
[7]));
81 makima
.push_back(std::log2(v
[8]));
82 fotaylor
.push_back(std::log2(v
[9]));
84 quintic_hermite
.push_back(std::log2(v
[10]));
85 sotaylor
.push_back(std::log2(v
[11]));
88 totaylor
.push_back(std::log2(v
[12]));
89 septic_hermite
.push_back(std::log2(v
[13]));
93 std::cout
<< std::fixed
<< std::setprecision(16);
94 auto q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, matched_holder
);
95 BOOST_ASSERT(std::get
<1>(q
) < 0);
96 std::cout
<< "Matched Holder : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
98 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, linear
);
99 BOOST_ASSERT(std::get
<1>(q
) < 0);
100 std::cout
<< "Linear : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
102 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, quadratic_b_spline
);
103 BOOST_ASSERT(std::get
<1>(q
) < 0);
104 std::cout
<< "Quadratic B-spline: " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
106 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, cubic_b_spline
);
107 BOOST_ASSERT(std::get
<1>(q
) < 0);
108 std::cout
<< "Cubic B-spline : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
110 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, quintic_b_spline
);
111 BOOST_ASSERT(std::get
<1>(q
) < 0);
112 std::cout
<< "Quintic B-spline : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
114 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, cubic_hermite
);
115 BOOST_ASSERT(std::get
<1>(q
) < 0);
116 std::cout
<< "Cubic Hermite : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
118 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, pchip
);
119 BOOST_ASSERT(std::get
<1>(q
) < 0);
120 std::cout
<< "PCHIP : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
122 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, makima
);
123 BOOST_ASSERT(std::get
<1>(q
) < 0);
124 std::cout
<< "Makima : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
126 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, fotaylor
);
127 BOOST_ASSERT(std::get
<1>(q
) < 0);
128 std::cout
<< "First-order Taylor: " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
130 if (sotaylor
.size() > 0)
132 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, quintic_hermite
);
133 BOOST_ASSERT(std::get
<1>(q
) < 0);
134 std::cout
<< "Quintic Hermite : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
136 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, sotaylor
);
137 BOOST_ASSERT(std::get
<1>(q
) < 0);
138 std::cout
<< "2nd order Taylor : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
142 if (totaylor
.size() > 0)
144 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, totaylor
);
145 BOOST_ASSERT(std::get
<1>(q
) < 0);
146 std::cout
<< "3rd order Taylor : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
148 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, septic_hermite
);
149 BOOST_ASSERT(std::get
<1>(q
) < 0);
150 std::cout
<< "Septic Hermite : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";