summaryrefslogtreecommitdiff
path: root/fits_abs.cpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2025-02-12 16:23:43 -0300
committerJaron Kent-Dobias <jaron@kent-dobias.com>2025-02-12 16:23:43 -0300
commitae56a721eb63e6e2032e10436a4944d9203aa560 (patch)
tree8ebd3c6e5bc404011ce3df82dcc5ae2cb86f07a1 /fits_abs.cpp
parent8331cf653f6ac80ebb9c96c9c844803ce0278d43 (diff)
downloadictp-saifr_colloquium-ae56a721eb63e6e2032e10436a4944d9203aa560.tar.gz
ictp-saifr_colloquium-ae56a721eb63e6e2032e10436a4944d9203aa560.tar.bz2
ictp-saifr_colloquium-ae56a721eb63e6e2032e10436a4944d9203aa560.zip
More writing
Diffstat (limited to 'fits_abs.cpp')
-rw-r--r--fits_abs.cpp81
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;
+}