Signature | Description |
---|---|
enum class sigmoid_type : unsigned char { logistic = 1, // f(x) = 1 / (1 + e-x) algebraic = 2, // f(x) = 1 / √1 + x2 hyperbolic_tan = 3, // f(x) = tanh(x) arc_tan = 4, // f(x) = atan(x) error_function = 5, // f(x) = 2 / √ℼ * ∫ e-t2 dt gudermannian = 6, // f(x) = atan(sinh(x)) smoothstep = 7, // f(x) = 0 if x <= 0, 1 if x >= 1, else 3x2 - 2x3 }; |
Different Sigmoid function types that are supported in Sigmoid |
Signature | Description |
---|---|
enum class rectify_type : unsigned char {
ReLU = 1, // f(x) = x if x > 0 else 0
param_ReLU = 2, // f(x) = x if x > 0 else a * x, a <= 1
GeLU = 3, // f(x) = x * Φ(x), Φ = Standard Normal Dist
SiLU = 4, // f(x) = x * Sigmoid(x)
softplus = 5, // f(x) = log(1 + ea * x) / a, a != 0
elu = 6, // f(x) = x if x > 0 else a * (ex - 1), a >= 0
mish = 7, // f(x) = x * tanh(softplus(x))
metallic_mean = 8, // f(x) = (x + √x2 + 4) / 2
};
|
Different rectifying function types that are supported in RectifyVisitor |
Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameMLVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct SigmoidVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using sigm_v = SigmoidVisitor<T, I, A>; |
This is a “single action visitor”, meaning it is passed the whole data vector in one call and you must use the single_act_visit() interface. This functor class calculates Sigmoid function for each item in the given column. The Sigmoid fuction is based on the sigmoid_type above. explicit SigmoidVisitor(sigmoid_type st); |
T: Column data type. I: Index type. A: Memory alignment boundary for vectors. Default is system default alignment |
#include <DataFrame/DataFrameMLVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct RectifyVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using recf_v = RectifyVisitor<T, I, A>; |
This is a “single action visitor”, meaning it is passed the whole data vector in one call and you must use the single_act_visit() interface. This visitor calculates different rectifying functions specified above. explicit RectifyVisitor(rectify_type r_type, double param = 1) param: This is a multiplicative parameters denoted above as a. |
T: Column data type. I: Index type. A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_SigmoidVisitor() { std::cout << "\nTesting SigmoidVisitor{ } ..." << std::endl; std::vector<unsigned long> idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; std::vector<double> d1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 }; std::vector<double> d2 = { 0.23, 0.25, 0.256, 0.26, 0.268, 0.271, 0.279, 0.285, 0.29, 0.3, 0.5, -0.2, 1, 0, 2, 0, -0.1, 0.55, 0.58, 0.6, 0.7 }; std::vector<int> i1 = { 22, 23, 24, 25, 99 }; MyDataFrame df; df.load_data(std::move(idx), std::make_pair("d1_col", d1), std::make_pair("d2_col", d2), std::make_pair("col_3", i1)); SigmoidVisitor<double> sig_log(sigmoid_type::logistic); SigmoidVisitor<double> sig_alg(sigmoid_type::algebraic); SigmoidVisitor<double> sig_tan(sigmoid_type::hyperbolic_tan); SigmoidVisitor<double> sig_atan(sigmoid_type::arc_tan); SigmoidVisitor<double> sig_err(sigmoid_type::error_function); SigmoidVisitor<double> sig_gud(sigmoid_type::gudermannian); SigmoidVisitor<double> sig_smo(sigmoid_type::smoothstep); const auto log_result = df.single_act_visit<double>("d1_col", sig_log).get_result(); const auto alg_result = df.single_act_visit<double>("d1_col", sig_alg).get_result(); const auto tan_result = df.single_act_visit<double>("d1_col", sig_tan).get_result(); const auto atan_result = df.single_act_visit<double>("d1_col", sig_atan).get_result(); const auto err_result = df.single_act_visit<double>("d1_col", sig_err).get_result(); const auto gud_result = df.single_act_visit<double>("d1_col", sig_gud).get_result(); const auto smo_result = df.single_act_visit<double>("d2_col", sig_smo).get_result(); std::vector<double> result { 0.731059, 0.880797, 0.952574, 0.982014, 0.993307, 0.997527, 0.999089, 0.999665, 0.999877, 0.999955, 0.999983, 0.999994, 0.999998, 0.999999, 1, 1, 1, 1, 1, 1, 1 }; for (size_t idx = 0; idx < result.size(); ++idx) assert(fabs(result[idx] - log_result[idx]) < 0.00001); result = std::vector<double> { 0.707107, 0.447214, 0.316228, 0.242536, 0.196116, 0.164399, 0.141421, 0.124035, 0.110432, 0.0995037, 0.0905357, 0.0830455, 0.0766965, 0.071247, 0.066519, 0.0623783, 0.058722, 0.05547, 0.0525588, 0.0499376, 0.0475651 }; for (size_t idx = 0; idx < result.size(); ++idx) assert(fabs(result[idx] - alg_result[idx]) < 0.00001); result = std::vector<double> { 0.761594, 0.964028, 0.995055, 0.999329, 0.999909, 0.999988, 0.999998, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; for (size_t idx = 0; idx < result.size(); ++idx) assert(fabs(result[idx] - tan_result[idx]) < 0.00001); result = std::vector<double> { 0.785398, 1.10715, 1.24905, 1.32582, 1.3734, 1.40565, 1.4289, 1.44644, 1.46014, 1.47113, 1.48014, 1.48766, 1.49402, 1.49949, 1.50423, 1.50838, 1.51204, 1.5153, 1.51821, 1.52084, 1.52321 }; for (size_t idx = 0; idx < result.size(); ++idx) assert(fabs(result[idx] - atan_result[idx]) < 0.00001); result = std::vector<double> { 0.842701, 0.995322, 0.999978, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; for (size_t idx = 0; idx < result.size(); ++idx) assert(fabs(result[idx] - err_result[idx]) < 0.00001); result = std::vector<double> { 0.865769, 1.30176, 1.4713, 1.53417, 1.55732, 1.56584, 1.56897, 1.57013, 1.57055, 1.57071, 1.57076, 1.57078, 1.57079, 1.57079, 1.5708, 1.5708, 1.5708, 1.5708, 1.5708, 1.5708, 1.5708 }; for (size_t idx = 0; idx < result.size(); ++idx) assert(fabs(result[idx] - gud_result[idx]) < 0.00001); result = std::vector<double> { 0.134366, 0.15625, 0.163054, 0.167648, 0.176974, 0.180518, 0.190088, 0.197377, 0.203522, 0.216, 0.5, 0, 1, 0, 1, 0, 0, 0.57475, 0.618976, 0.648, 0.784 }; for (size_t idx = 0; idx < result.size(); ++idx) assert(fabs(result[idx] - smo_result[idx]) < 0.00001); }
// ----------------------------------------------------------------------------- static void test_RectifyVisitor() { std::cout << "\nTesting RectifyVisitor{ } ..." << std::endl; MyDataFrame df; StlVecType<unsigned long> idxvec = { 1UL, 2UL, 3UL, 10UL, 5UL, 7UL, 8UL, 12UL, 9UL, 12UL, 10UL, 13UL, 10UL, 15UL, 14UL }; StlVecType<double> dblvec = { 0.0, 15.0, -14.0, 2.0, 1.0, -12.0, 11.0, 8.0, 7.0, 0.0, 5.0, 4.0, 3.0, 9.0, -10.0}; StlVecType<double> dblvec2 = { 1.0, 0.05, 0.28, 0.31, 0.01, 0.68, 0.12, 1, 0.98, 0.9, 0.81, 0.82, 0.777, 0.34, 0.25}; StlVecType<std::string> strvec = { "zz", "bb", "cc", "ww", "ee", "ff", "gg", "hh", "ii", "jj", "kk", "ll", "mm", "nn", "oo" }; df.load_data(std::move(idxvec), std::make_pair("dbl_col", dblvec), std::make_pair("dbl_col_2", dblvec2), std::make_pair("str_col", strvec)); recf_v<double, unsigned long> relu(rectify_type::ReLU); df.single_act_visit<double>("dbl_col", relu); assert(relu.get_result().size() == 15); assert(std::abs(relu.get_result()[0] - 0) < 0.0001); assert(std::abs(relu.get_result()[7] - 8) < 0.0001); assert(std::abs(relu.get_result()[14] - 0) < 0.0001); recf_v<double, unsigned long> prelu(rectify_type::param_ReLU, 0.001); df.single_act_visit<double>("dbl_col", prelu); assert(prelu.get_result().size() == 15); assert(std::abs(prelu.get_result()[0] - 0) < 0.0001); assert(std::abs(prelu.get_result()[5] - -0.012) < 0.0001); assert(std::abs(prelu.get_result()[14] - -0.01) < 0.0001); recf_v<double, unsigned long> gelu(rectify_type::GeLU); df.single_act_visit<double>("dbl_col_2", gelu); assert(gelu.get_result().size() == 15); assert(std::abs(gelu.get_result()[0] - 0.242) < 0.0001); assert(std::abs(gelu.get_result()[5] - 0.2153) < 0.0001); assert(std::abs(gelu.get_result()[14] - 0.0967) < 0.0001); recf_v<double, unsigned long> silu(rectify_type::SiLU); df.single_act_visit<double>("dbl_col", silu); assert(silu.get_result().size() == 15); assert(std::abs(silu.get_result()[0] - 0) < 0.0001); assert(std::abs(silu.get_result()[6] - 10.9998) < 0.0001); assert(std::abs(silu.get_result()[14] - -0.0005) < 0.0001); recf_v<double, unsigned long> softplus(rectify_type::softplus); df.single_act_visit<double>("dbl_col", softplus); assert(softplus.get_result().size() == 15); assert(std::abs(softplus.get_result()[0] - 0.6931) < 0.0001); assert(std::abs(softplus.get_result()[6] - 11) < 0.0001); assert(std::abs(softplus.get_result()[14] - 0) < 0.0001); recf_v<double, unsigned long> elu(rectify_type::elu, 0.5); df.single_act_visit<double>("dbl_col", elu); assert(elu.get_result().size() == 15); assert(std::abs(elu.get_result()[0] - 0) < 0.0001); assert(std::abs(elu.get_result()[5] - -0.5) < 0.0001); assert(std::abs(elu.get_result()[14] - -0.5) < 0.0001); recf_v<double, unsigned long> mish(rectify_type::mish); df.single_act_visit<double>("dbl_col", mish); assert(mish.get_result().size() == 15); assert(std::abs(mish.get_result()[0] - 0) < 0.0001); assert(std::abs(mish.get_result()[6] - 11) < 0.0001); assert(std::abs(mish.get_result()[14] - -0.0005) < 0.0001); recf_v<double, unsigned long> mm(rectify_type::metallic_mean); df.single_act_visit<double>("dbl_col", mm); assert(mm.get_result().size() == 15); assert(std::abs(mm.get_result()[0] - 1) < 0.0001); assert(std::abs(mm.get_result()[6] - 11.0902) < 0.0001); assert(std::abs(mm.get_result()[14] - 0.099) < 0.0001); }