25#include <google/protobuf/text_format.h>
38 const std::vector<double>& val_table,
41 static double sigmoid(
const double value);
42 static double relu(
const double value);
43 double normalize(
const double value,
const double mean,
const double std);
47 std::fstream input(filename, std::ios::in | std::ios::binary);
48 return pb_out->ParseFromIstream(&input);
53 std::fstream input(filename, std::ios::in);
54 std::string input_data((std::istreambuf_iterator<char>(input)),
55 std::istreambuf_iterator<char>());
57 if (input_data.empty()) {
61 return google::protobuf::TextFormat::ParseFromString(input_data, pb_out);
81 bool ends_with(
const std::string& original,
const std::string& pattern) {
82 return original.length() >= pattern.length() &&
83 original.substr(original.length() - pattern.length()) == pattern;
88 return static_cast<int>(value > threshold);
92 double get_eta(
double rise_time,
double peak_time) {
93 if (peak_time <= 0.0) {
94 AFATAL <<
"peak_time should be positive";
96 return cos(M_PI - rise_time / (peak_time / M_PI));
102 AFATAL <<
"not an underdamped system";
104 return peak_time / sqrt(1 - eta * eta);
int delta_function(double value, double threshold)
bool load_file_to_proto(const std::string &filename, P *pb_out)
double interpolate_1d(const double &p1, const double &p2, const double &frac1)
double interpolated_find(const std::vector< double > &range_table, const std::vector< double > &val_table, double to_find)
bool load_text_file(const std::string &filename, P *pb_out)
static double relu(const double value)
double normalize(const double value, const double mean, const double std)
static double sigmoid(const double value)
bool ends_with(const std::string &original, const std::string &pattern)
double get_eta(double rise_time, double peak_time)
double get_tau_s(double peak_time, double eta)
bool load_binary_file(const std::string &filename, P *pb_out)