#include #include #include "fits.hpp" int main(int argc, char* argv[]) { unsigned Nend = 1; unsigned M = 10; unsigned nBatches = 5; Real σ = 0.2; Real iniVar = 0.0; long unsigned maxSteps = 1e12; int opt; while ((opt = getopt(argc, argv, "M:s:S:B:i:N:")) != -1) { switch (opt) { case 'N': Nend = (unsigned)atof(optarg); break; case 'M': M = (unsigned)atof(optarg); break; case 's': σ = atof(optarg); break; case 'S': maxSteps = (long unsigned)atof(optarg); break; case 'B': nBatches = (unsigned)atof(optarg); break; case 'i': iniVar = atof(optarg); break; default: exit(1); } } Rng r; Data data = generateData([](Real x) {return std::sin(2 * M_PI * x);}, M, σ, r); std::cout << std::setprecision(15); for (std::tuple datum : data) { std::cout << std::get<0>(datum) << " " << std::get<1>(datum) << " "; } std::cout << std::endl; for (unsigned N = 1; N <= M; N++) { Vector a = underSolve(data, N); for (Real ai : a) { std::cout << ai << " "; } std::cout << std::endl; } for (unsigned N = Nend; N > M; N--) { Vector a₀ = Vector::Zero(N); for (Real& aa : a₀) { aa = r.variate(0, iniVar); } Vector a = stochasticGradientDescent(data, a₀, nBatches, maxSteps); for (Real ai : a) { std::cout << ai << " "; } std::cout << std::endl; } return 0; }