Austin Schuh | ad59622 | 2018-01-31 23:34:03 -0800 | [diff] [blame] | 1 | #include <chrono> |
| 2 | #include <cmath> |
| 3 | #include <thread> |
| 4 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 5 | #include "absl/flags/flag.h" |
| 6 | #include "absl/flags/parse.h" |
Austin Schuh | ad59622 | 2018-01-31 23:34:03 -0800 | [diff] [blame] | 7 | #include "third_party/matplotlib-cpp/matplotlibcpp.h" |
| 8 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 9 | ABSL_FLAG(double, yrange, 1.0, "+- y max"); |
Austin Schuh | ad59622 | 2018-01-31 23:34:03 -0800 | [diff] [blame] | 10 | |
| 11 | double fx(double x, double yrange) { |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 12 | return 2.0 * ((1.0 / (1.0 + ::std::exp(-x * 2.0 / yrange)) - 0.5)) * yrange; |
Austin Schuh | ad59622 | 2018-01-31 23:34:03 -0800 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | int main(int argc, char **argv) { |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 16 | absl::ParseCommandLine(argc, argv); |
Austin Schuh | ad59622 | 2018-01-31 23:34:03 -0800 | [diff] [blame] | 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); |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 25 | 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 Schuh | ad59622 | 2018-01-31 23:34:03 -0800 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | matplotlibcpp::plot(x, y, {{"label", "saturated x"}}); |
| 32 | matplotlibcpp::plot(x, slope_y, {{"label", "slope"}}); |
| 33 | matplotlibcpp::legend(); |
| 34 | matplotlibcpp::show(); |
Austin Schuh | ad59622 | 2018-01-31 23:34:03 -0800 | [diff] [blame] | 35 | } |