blob: c65bae62c56c0f2db3f7dd1f1683f5d154af708c [file] [log] [blame]
Austin Schuhad596222018-01-31 23:34:03 -08001#include <chrono>
2#include <cmath>
3#include <thread>
4
Austin Schuh99f7c6a2024-06-25 22:07:44 -07005#include "absl/flags/flag.h"
6#include "absl/flags/parse.h"
Austin Schuhad596222018-01-31 23:34:03 -08007#include "third_party/matplotlib-cpp/matplotlibcpp.h"
8
Austin Schuh99f7c6a2024-06-25 22:07:44 -07009ABSL_FLAG(double, yrange, 1.0, "+- y max");
Austin Schuhad596222018-01-31 23:34:03 -080010
11double fx(double x, double yrange) {
Philipp Schrader790cb542023-07-05 21:06:52 -070012 return 2.0 * ((1.0 / (1.0 + ::std::exp(-x * 2.0 / yrange)) - 0.5)) * yrange;
Austin Schuhad596222018-01-31 23:34:03 -080013}
14
15int main(int argc, char **argv) {
Austin Schuh99f7c6a2024-06-25 22:07:44 -070016 absl::ParseCommandLine(argc, argv);
Austin Schuhad596222018-01-31 23:34:03 -080017
18 matplotlibcpp::figure();
19 ::std::vector<double> x;
20 ::std::vector<double> y;
21 ::std::vector<double> slope_y;
22
23 for (double i = -5.0; i < 5.0; i += 0.01) {
24 x.push_back(i);
Austin Schuh99f7c6a2024-06-25 22:07:44 -070025 y.push_back(fx(i, absl::GetFlag(FLAGS_yrange)));
26 slope_y.push_back((fx(i + 0.0001, absl::GetFlag(FLAGS_yrange)) -
27 fx(i - 0.0001, absl::GetFlag(FLAGS_yrange))) /
28 (2.0 * 0.0001));
Austin Schuhad596222018-01-31 23:34:03 -080029 }
30
31 matplotlibcpp::plot(x, y, {{"label", "saturated x"}});
32 matplotlibcpp::plot(x, slope_y, {{"label", "slope"}});
33 matplotlibcpp::legend();
34 matplotlibcpp::show();
Austin Schuhad596222018-01-31 23:34:03 -080035}