|
| 1 | +// LeaveOneOutRegression.cpp : This file contains the 'main' function. Program execution begins and ends there. |
| 2 | +// |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +#include "../Vectorisation/VecX/dr3.h" |
| 7 | + |
| 8 | + |
| 9 | +#include <random> |
| 10 | +#include <numeric> |
| 11 | +#include <iostream> |
| 12 | +#include <vector> |
| 13 | +#include <iomanip> |
| 14 | +#include <functional> |
| 15 | +#include <chrono> |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +//using namespace DRC::VecD2D; |
| 20 | +//using namespace DRC::VecF4F; |
| 21 | +//using namespace DRC::VecD4D; |
| 22 | +using namespace DRC::VecD8D; |
| 23 | +//using namespace DRC::VecF16F; |
| 24 | +//using namespace DRC::VecF8F; |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +int main() |
| 30 | +{ |
| 31 | + |
| 32 | + |
| 33 | + // std::vector<double> vc(300, 1.1); |
| 34 | + |
| 35 | + // VecXX myvec = vc; |
| 36 | + |
| 37 | + int N = 1000000; |
| 38 | + |
| 39 | + VecXX data_X(N); |
| 40 | + VecXX data_Y(N); |
| 41 | + |
| 42 | + for (int i = 0; i < N; i++) |
| 43 | + { |
| 44 | + data_X[i] = i; |
| 45 | + data_Y[i] = 0.5 * i + 0.25 +rand() / double(RAND_MAX); |
| 46 | + } |
| 47 | + |
| 48 | + // std::vector<double> debg; |
| 49 | + |
| 50 | + const auto startTme = std::chrono::high_resolution_clock::now(); |
| 51 | + |
| 52 | + for (int LOOP = 0; LOOP < 200; LOOP++) |
| 53 | + { |
| 54 | + auto MULT = [](auto x, auto y) { return x * y; }; |
| 55 | + auto SUM = [](auto x, auto y) { return x + y; }; |
| 56 | + auto SQR = [](auto x) {return x * x; }; |
| 57 | + |
| 58 | + auto S_x = reduce(data_X, SUM); |
| 59 | + auto S_y = reduce(data_Y, SUM); |
| 60 | + |
| 61 | + auto S_xx = transformReduce(data_X, SQR, SUM); |
| 62 | + |
| 63 | + auto S_xy = transformReduce(data_X, data_Y, MULT, SUM); |
| 64 | + |
| 65 | + auto SX_loo = S_x - data_X; |
| 66 | + |
| 67 | + // debg = SX_loo; |
| 68 | + |
| 69 | + auto SY_loo = S_y - data_Y; |
| 70 | + |
| 71 | + // debg = SY_loo; |
| 72 | + |
| 73 | + auto data_X_squared = data_X * data_X; |
| 74 | + auto SXxx_loo = S_xx - data_X_squared; |
| 75 | + |
| 76 | + // debg = SXxx_loo; |
| 77 | + |
| 78 | + auto data_X_Y = data_X * data_Y; |
| 79 | + auto SXY_loo = S_xy - data_X_Y; |
| 80 | + |
| 81 | + // debg = SXY_loo; |
| 82 | + |
| 83 | + |
| 84 | + /// |
| 85 | + double lambda = 0.0;// 0.1; |
| 86 | + double Sz = data_X.size() - 1.0; |
| 87 | + |
| 88 | + auto denominator = (Sz * (SXxx_loo + lambda)) - (SX_loo * SX_loo); |
| 89 | + |
| 90 | + auto Beta_0_numerator = (SXxx_loo + lambda) * SY_loo - SX_loo * SXY_loo; |
| 91 | + |
| 92 | + auto Beta_0 = Beta_0_numerator / denominator; |
| 93 | + |
| 94 | + auto Beta_1_numerator = Sz * SXY_loo - (SX_loo * SY_loo); |
| 95 | + |
| 96 | + auto Beta_1 = Beta_1_numerator / denominator; |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | + // debg = denominator; |
| 101 | + // debg = Beta_0_numerator; |
| 102 | + // debg = Beta_1_numerator; |
| 103 | + |
| 104 | + // std::vector<double> offset = Beta_0; |
| 105 | + // std::vector<double> slope = Beta_1; |
| 106 | + // std::vector<double> x = data_X; |
| 107 | + // std::vector<double> y = data_Y; |
| 108 | + |
| 109 | + |
| 110 | + } |
| 111 | + |
| 112 | + const auto endTme = std::chrono::high_resolution_clock::now(); |
| 113 | + |
| 114 | + // const std::chrono::duration<double, std::milli> runtime = endTme - startTme; |
| 115 | + |
| 116 | + // auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(runtime); |
| 117 | + |
| 118 | + const std::chrono::duration<double, std::milli> fp_ms = endTme - startTme; |
| 119 | + |
| 120 | + // integral duration: requires duration_cast |
| 121 | + // const auto int_ms = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1); |
| 122 | + |
| 123 | + std::cout << fp_ms.count() << " milli seconds"; |
| 124 | +} |
| 125 | + |
0 commit comments