#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