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) = [(ex - e-x) / (ex + e-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. They are to be used with SigmoidVisitor

Signature Description Parameters
#include <DataFrame/DataFrameStatsVisitors.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
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);
}
C++ DataFrame