diff options
Diffstat (limited to 'fits_abs.cpp')
-rw-r--r-- | fits_abs.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/fits_abs.cpp b/fits_abs.cpp new file mode 100644 index 0000000..087bdbe --- /dev/null +++ b/fits_abs.cpp @@ -0,0 +1,81 @@ +#include <getopt.h> +#include <iomanip> + +#include "fits.hpp" + +int main(int argc, char* argv[]) { + unsigned Nend = 1; + unsigned nBatches = 5; + Real σ = 0.2; + Real iniVar = 0.0; + long unsigned maxSteps = 1e12; + + int opt; + + while ((opt = getopt(argc, argv, "s:S:B:i:N:")) != -1) { + switch (opt) { + case 'N': + Nend = (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); + } + } + + std::string firstline; + std::getline(std::cin, firstline); + std::stringstream ss; + ss << firstline; + + Data data; + + while (!ss.eof()) { + Real x, y; + ss >> x; + ss >> y; + data.push_back({x,y}); + } + + unsigned M = data.size(); + + Rng r; + + std::cout << std::setprecision(15); + + 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<Real, std::normal_distribution>(0, iniVar); + } + + Vector a = stochasticGradientDescent(data, a₀, nBatches, maxSteps); + + for (Real ai : a) { + std::cout << ai << " "; + } + std::cout << std::endl; + } + + return 0; +} |