]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/example/daubechies_wavelets/regress_daubechies_accuracy.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / math / example / daubechies_wavelets / regress_daubechies_accuracy.cpp
CommitLineData
1e59de90
TL
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)
5//
6
7
f67539c2
TL
8#include <iostream>
9#include <string>
10#include <fstream>
11#include <map>
12#include <cmath>
13#include <vector>
14#include <iomanip>
15#include <boost/algorithm/string.hpp>
16#include <boost/math/statistics/linear_regression.hpp>
1e59de90 17#include <boost/assert.hpp>
f67539c2
TL
18
19
20int main(int argc, char** argv)
21{
22 if (argc != 2)
23 {
24 std::cout << "Usage: ./regress_accuracy.x foo.csv\n";
25 return 1;
26 }
27 std::string filename = std::string(argv[1]);
28 std::ifstream ifs(filename.c_str());
29 if (!ifs.good())
30 {
31 std::cerr << "Couldn't find file " << filename << "\n";
32 return 1;
33 }
34 std::map<std::string, std::vector<double>> m;
35
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);
43 }
44
45 std::string line;
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))
61 {
62 std::vector<std::string> strs;
63 boost::split(strs, line, boost::is_any_of(","));
64 for (auto & s : strs)
65 {
66 boost::algorithm::trim(s);
67 }
68 std::vector<double> v(strs.size(), std::numeric_limits<double>::quiet_NaN());
69 for (size_t i = 0; i < v.size(); ++i)
70 {
71 v[i] = std::stod(strs[i]);
72 }
73 r.push_back(v[0]);
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]));
83 if (v.size() > 10) {
84 quintic_hermite.push_back(std::log2(v[10]));
85 sotaylor.push_back(std::log2(v[11]));
86 }
87 if (v.size() > 12) {
88 totaylor.push_back(std::log2(v[12]));
89 septic_hermite.push_back(std::log2(v[13]));
90 }
91 }
92
93 std::cout << std::fixed << std::setprecision(16);
94 auto q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, matched_holder);
1e59de90 95 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
96 std::cout << "Matched Holder : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
97
98 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, linear);
1e59de90 99 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
100 std::cout << "Linear : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
101
102 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, quadratic_b_spline);
1e59de90 103 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
104 std::cout << "Quadratic B-spline: " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
105
106 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, cubic_b_spline);
1e59de90 107 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
108 std::cout << "Cubic B-spline : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
109
110 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, quintic_b_spline);
1e59de90 111 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
112 std::cout << "Quintic B-spline : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
113
114 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, cubic_hermite);
1e59de90 115 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
116 std::cout << "Cubic Hermite : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
117
118 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, pchip);
1e59de90 119 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
120 std::cout << "PCHIP : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
121
122 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, makima);
1e59de90 123 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
124 std::cout << "Makima : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
125
126 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, fotaylor);
1e59de90 127 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
128 std::cout << "First-order Taylor: " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
129
130 if (sotaylor.size() > 0)
131 {
132 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, quintic_hermite);
1e59de90 133 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
134 std::cout << "Quintic Hermite : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
135
136 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, sotaylor);
1e59de90 137 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
138 std::cout << "2nd order Taylor : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
139
140 }
141
142 if (totaylor.size() > 0)
143 {
144 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, totaylor);
1e59de90 145 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
146 std::cout << "3rd order Taylor : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
147
148 q = boost::math::statistics::simple_ordinary_least_squares_with_R_squared(r, septic_hermite);
1e59de90 149 BOOST_ASSERT(std::get<1>(q) < 0);
f67539c2
TL
150 std::cout << "Septic Hermite : " << std::get<0>(q) << " - " << std::abs(std::get<1>(q)) << "r, R^2 = " << std::get<2>(q) << "\n";
151
152 }
153
1e59de90 154}