summaryrefslogtreecommitdiff
path: root/many_over.cpp
diff options
context:
space:
mode:
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;
+}