diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2025-02-10 19:04:48 -0300 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2025-02-10 19:04:48 -0300 |
commit | 8666acd6c33c3d408328d9f548175029fb1b5bd2 (patch) | |
tree | 12df52afd710e44cb25c0f8cdeb207893ca7c9ed | |
parent | 26fff09ab2cfd42aafcebd3b39d3c13265cc4faf (diff) | |
download | ictp-saifr_colloquium-8666acd6c33c3d408328d9f548175029fb1b5bd2.tar.gz ictp-saifr_colloquium-8666acd6c33c3d408328d9f548175029fb1b5bd2.tar.bz2 ictp-saifr_colloquium-8666acd6c33c3d408328d9f548175029fb1b5bd2.zip |
Modfied code to produce chain of examples
-rw-r--r-- | fits.cpp | 24 |
1 files changed, 11 insertions, 13 deletions
@@ -125,7 +125,6 @@ Data generateData(Real(*f)(Real), unsigned M, Real σ, Rng& r) { } int main(int argc, char* argv[]) { - unsigned N = 10; unsigned M = 10; unsigned nBatches = 5; Real σ = 0.2; @@ -134,11 +133,8 @@ int main(int argc, char* argv[]) { int opt; - while ((opt = getopt(argc, argv, "N:M:s:S:B:i:")) != -1) { + while ((opt = getopt(argc, argv, "M:s:S:B:i:")) != -1) { switch (opt) { - case 'N': - N = (unsigned)atof(optarg); - break; case 'M': M = (unsigned)atof(optarg); break; @@ -170,17 +166,19 @@ int main(int argc, char* argv[]) { } std::cout << std::endl; - Vector a₀ = Vector::Zero(N); - for (Real& aa : a₀) { - aa = r.variate<Real, std::normal_distribution>(0, iniVar); - } + for (unsigned N = 1; N <= 2 * 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); + Vector a = stochasticGradientDescent(data, a₀, nBatches, maxSteps); - for (unsigned i = 0; i < N; i++) { - std::cout << a[i] << " "; + for (Real ai : a) { + std::cout << ai << " "; + } + std::cout << std::endl; } - std::cout << std::endl; return 0; } |