#ifndef _STATISTICS_CPP_ #define _STATISTICS_CPP_ #include #include #include #include namespace stats { using namespace std; typedef double val; struct inverse_error {}; template array, N> invert(const array, N>& T) { int iN = N; auto T1 = T, T2 = T; for(int y=0; y abs(T1[best][a])) best = b; int b = best; if(b != a) for(int c=0; c=0; a--) { for(int b=0; b struct leastsquare_solution : public array { val operator() (const array X) { int iN = N; val res = 0; for(int j=0; j struct leastsquare_solver { array, N> toinvert; array Xty; static constexpr int iN = N; leastsquare_solver() { for(int y=0; y X, val y) { for(int j=0; j other) { for(int j=0; j solve() { auto res = invert(toinvert); leastsquare_solution s; for(int i=0; i double small_kendall(const vector>& allp) { int maxo = 0, maxe = 0; for(const auto& a: allp) maxo = max(maxo, a.first), maxe = max(maxe, a.second); maxo++; maxe++; if(maxo >= dim1 || maxe >= dim2) throw hr::hr_exception("small_kendall limit exceeded"); int cnt[dim1][dim2]; for(int a=0; a counts(maxe, 0); vector totals(maxe); double tau = 0; for(int i=0; i double kendall(vector> allp) { int maxx = 0; for(const auto& a: allp) maxx = max(maxx, a.first); maxx++; vector counts(maxx, 0); vector totals(maxx, 0); double tau = 0; sort(allp.begin(), allp.end(), [] (auto a, auto b) { return a.second < b.second; }); auto last = allp[0].second; vector to_add; for(const auto& a: allp) { if(a.second != last) { for(auto ad: to_add) { totals[ad]++; for(int x=ad+1; x> p = { {1,1}, {2,2}, {3,3}, {4,4} }; println(hlog, "p = ", stats::kendall(p)); vector> q = { {1,1}, {2,2}, {3,3}, {4,3} }; println(hlog, "q = ", stats::kendall(q)); vector> r = { {1,1}, {2,2}, {3,4}, {4,3} }; println(hlog, "r = ", stats::kendall(r)); vector> s = { {1,1}, {2,2}, {3,3}, {3,4} }; println(hlog, "s = ", stats::kendall(s)); } } #endif } #endif