Austin Schuh | ad59622 | 2018-01-31 23:34:03 -0800 | [diff] [blame] | 1 | #include <chrono> |
| 2 | #include <cmath> |
| 3 | #include <thread> |
| 4 | |
Austin Schuh | 87dc7bb | 2018-10-29 21:53:23 -0700 | [diff] [blame^] | 5 | #include "gflags/gflags.h" |
Austin Schuh | ad59622 | 2018-01-31 23:34:03 -0800 | [diff] [blame] | 6 | #include "third_party/matplotlib-cpp/matplotlibcpp.h" |
| 7 | |
| 8 | DEFINE_double(yrange, 1.0, "+- y max"); |
| 9 | |
| 10 | double 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 | |
| 15 | int 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 | } |