blob: 9fb1a354ffc8754b9de2815d303963489c6a98a6 [file] [log] [blame]
Austin Schuhad596222018-01-31 23:34:03 -08001#include <chrono>
2#include <cmath>
3#include <thread>
4
Austin Schuh87dc7bb2018-10-29 21:53:23 -07005#include "gflags/gflags.h"
Austin Schuhad596222018-01-31 23:34:03 -08006#include "third_party/matplotlib-cpp/matplotlibcpp.h"
7
8DEFINE_double(yrange, 1.0, "+- y max");
9
10double fx(double x, double yrange) {
11 return 2.0 * ((1.0 / (1.0 + ::std::exp(-x * 2.0 / yrange)) - 0.5)) *
12 yrange;
13}
14
15int main(int argc, char **argv) {
16 gflags::ParseCommandLineFlags(&argc, &argv, false);
17
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);
25 y.push_back(fx(i, FLAGS_yrange));
26 slope_y.push_back(
27 (fx(i + 0.0001, FLAGS_yrange) - fx(i - 0.0001, FLAGS_yrange)) /
28 (2.0 * 0.0001));
29 }
30
31 matplotlibcpp::plot(x, y, {{"label", "saturated x"}});
32 matplotlibcpp::plot(x, slope_y, {{"label", "slope"}});
33 matplotlibcpp::legend();
34 matplotlibcpp::show();
35
36}