summaryrefslogtreecommitdiff
path: root/many_over.cpp
blob: 5785ad34eeaecf981a47af6e23cdc2c953089c9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
}