summaryrefslogtreecommitdiff
path: root/many_over.cpp
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2025-02-11 15:26:41 -0300
committerJaron Kent-Dobias <jaron@kent-dobias.com>2025-02-11 15:26:41 -0300
commit8331cf653f6ac80ebb9c96c9c844803ce0278d43 (patch)
tree7a92c9e0cce3eec16c2c05008921a9cc64c5aa5b /many_over.cpp
parent01a22225f2d207f04df595290e0e5c742a29ccee (diff)
downloadictp-saifr_colloquium-8331cf653f6ac80ebb9c96c9c844803ce0278d43.tar.gz
ictp-saifr_colloquium-8331cf653f6ac80ebb9c96c9c844803ce0278d43.tar.bz2
ictp-saifr_colloquium-8331cf653f6ac80ebb9c96c9c844803ce0278d43.zip
Split up code, worked on presentation slides.
Diffstat (limited to 'many_over.cpp')
-rw-r--r--many_over.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/many_over.cpp b/many_over.cpp
new file mode 100644
index 0000000..5785ad3
--- /dev/null
+++ b/many_over.cpp
@@ -0,0 +1,67 @@
+#include <getopt.h>
+#include <iomanip>
+
+#include "fits.hpp"
+
+int main(int argc, char* argv[]) {
+ unsigned N = 80;
+
+ int opt;
+
+ while ((opt = getopt(argc, argv, "M:s:S:B:i:N:")) != -1) {
+ switch (opt) {
+ case 'N':
+ N = (unsigned)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});
+ }
+
+ Rng r;
+
+ std::cout << std::setprecision(15);
+
+ for (unsigned i = 0; i < 5; i++) {
+ Vector a₀ = Vector::Zero(N);
+ for (Real& aa : a₀) {
+ aa = r.variate<Real, std::normal_distribution>(0, 2e-2);
+ }
+
+ Vector a = stochasticGradientDescent(data, a₀, 10, 1e12);
+
+ for (Real ai : a) {
+ std::cout << ai << " ";
+ }
+ std::cout << std::endl;
+ }
+ for (unsigned i = 0; i < 5; i++) {
+ Vector a₀ = Vector::Zero(N);
+ for (Real& aa : a₀) {
+ aa = r.variate<Real, std::normal_distribution>(0, 5);
+ }
+
+ Vector a = stochasticGradientDescent(data, a₀, 10, 1e12);
+
+ for (Real ai : a) {
+ std::cout << ai << " ";
+ }
+ std::cout << std::endl;
+ }
+
+ return 0;
+}