]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/math/example/daubechies_wavelets/regress_daubechies_accuracy.cpp
8 #include <boost/algorithm/string.hpp>
9 #include <boost/math/statistics/linear_regression.hpp>
12 int main(int argc
, char** argv
)
16 std::cout
<< "Usage: ./regress_accuracy.x foo.csv\n";
19 std::string filename
= std::string(argv
[1]);
20 std::ifstream
ifs(filename
.c_str());
23 std::cerr
<< "Couldn't find file " << filename
<< "\n";
26 std::map
<std::string
, std::vector
<double>> m
;
28 std::string header_line
;
29 std::getline(ifs
, header_line
);
30 std::cout
<< "Header line = " << header_line
<< "\n";
31 std::vector
<std::string
> header_strs
;
32 boost::split(header_strs
, header_line
, boost::is_any_of(","));
33 for (auto & s
: header_strs
) {
34 boost::algorithm::trim(s
);
38 std::vector
<double> r
;
39 std::vector
<double> matched_holder
;
40 std::vector
<double> linear
;
41 std::vector
<double> quadratic_b_spline
;
42 std::vector
<double> cubic_b_spline
;
43 std::vector
<double> quintic_b_spline
;
44 std::vector
<double> cubic_hermite
;
45 std::vector
<double> pchip
;
46 std::vector
<double> makima
;
47 std::vector
<double> fotaylor
;
48 std::vector
<double> quintic_hermite
;
49 std::vector
<double> sotaylor
;
50 std::vector
<double> totaylor
;
51 std::vector
<double> septic_hermite
;
52 while(std::getline(ifs
, line
))
54 std::vector
<std::string
> strs
;
55 boost::split(strs
, line
, boost::is_any_of(","));
58 boost::algorithm::trim(s
);
60 std::vector
<double> v(strs
.size(), std::numeric_limits
<double>::quiet_NaN());
61 for (size_t i
= 0; i
< v
.size(); ++i
)
63 v
[i
] = std::stod(strs
[i
]);
66 matched_holder
.push_back(std::log2(v
[1]));
67 linear
.push_back(std::log2(v
[2]));
68 quadratic_b_spline
.push_back(std::log2(v
[3]));
69 cubic_b_spline
.push_back(std::log2(v
[4]));
70 quintic_b_spline
.push_back(std::log2(v
[5]));
71 cubic_hermite
.push_back(std::log2(v
[6]));
72 pchip
.push_back(std::log2(v
[7]));
73 makima
.push_back(std::log2(v
[8]));
74 fotaylor
.push_back(std::log2(v
[9]));
76 quintic_hermite
.push_back(std::log2(v
[10]));
77 sotaylor
.push_back(std::log2(v
[11]));
80 totaylor
.push_back(std::log2(v
[12]));
81 septic_hermite
.push_back(std::log2(v
[13]));
85 std::cout
<< std::fixed
<< std::setprecision(16);
86 auto q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, matched_holder
);
87 assert(std::get
<1>(q
) < 0);
88 std::cout
<< "Matched Holder : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
90 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, linear
);
91 assert(std::get
<1>(q
) < 0);
92 std::cout
<< "Linear : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
94 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, quadratic_b_spline
);
95 assert(std::get
<1>(q
) < 0);
96 std::cout
<< "Quadratic B-spline: " << 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
, cubic_b_spline
);
99 assert(std::get
<1>(q
) < 0);
100 std::cout
<< "Cubic B-spline : " << 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
, quintic_b_spline
);
103 assert(std::get
<1>(q
) < 0);
104 std::cout
<< "Quintic 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_hermite
);
107 assert(std::get
<1>(q
) < 0);
108 std::cout
<< "Cubic Hermite : " << 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
, pchip
);
111 assert(std::get
<1>(q
) < 0);
112 std::cout
<< "PCHIP : " << 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
, makima
);
115 assert(std::get
<1>(q
) < 0);
116 std::cout
<< "Makima : " << 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
, fotaylor
);
119 assert(std::get
<1>(q
) < 0);
120 std::cout
<< "First-order Taylor: " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
122 if (sotaylor
.size() > 0)
124 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, quintic_hermite
);
125 assert(std::get
<1>(q
) < 0);
126 std::cout
<< "Quintic Hermite : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
128 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, sotaylor
);
129 assert(std::get
<1>(q
) < 0);
130 std::cout
<< "2nd order Taylor : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
134 if (totaylor
.size() > 0)
136 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, totaylor
);
137 assert(std::get
<1>(q
) < 0);
138 std::cout
<< "3rd order Taylor : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";
140 q
= boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r
, septic_hermite
);
141 assert(std::get
<1>(q
) < 0);
142 std::cout
<< "Septic Hermite : " << std::get
<0>(q
) << " - " << std::abs(std::get
<1>(q
)) << "r, R^2 = " << std::get
<2>(q
) << "\n";