diff --git a/rogueviz/leastsquare.cpp b/rogueviz/leastsquare.cpp new file mode 100644 index 00000000..245dcce7 --- /dev/null +++ b/rogueviz/leastsquare.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include + +namespace lsq { + +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 const 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