Back to Documentations

Signature Description
struct  ICAParams  {

    using seed_t = std::random_device::result_type;

    // First center the data matrix
    //
    bool                center { true };

    // Max number of iterations before giving up
    //
    std::size_t         num_iter { 200 };

    // Epsilon value to call it done
    //
    double              epsilon { 1e-5 };

    // Nonlinearity applied to data
    //
    sigmoid_type        nonlinearity { sigmoid_type::hyperbolic_tan };

    // Seed for random number generator
    //
    seed_t              seed { seed_t(-1) };
};
A structure containing the parameteres to fast_ica() call

Signature Description Parameters
template<typename T>
Matrix<T, matrix_orient::column_major>
fast_ica(std::vector<const char *> &&col_names,
         size_type num_ind_features,
         const ICAParams params = { }) const;
Independent Component Analysis (ICA) is a powerful technique in the field of data analysis that allows you to separate and identify the underlying independent sources in a multivariate data set. ICA is important because it provides a way to understand the hidden structure of a data set, and it can be used in a variety of applications, such as signal processing, brain imaging, finance, and many other fields. In addition, ICA can help extract the most relevant information from data, providing valuable insights that would otherwise be lost in a sea of correlations.
It returns a matrix whose columns are the requested independent components and number rows is the same as the original data.
T: Type of the named columns
col_names: Vector of column names
num_ind_features: Number of independent features you want to reduce the specified columns to
params: Parameters necessary for for this operation
static void test_fast_ica()  {

    std::cout << "\nTesting fast_ica( ) ..." << std::endl;

    StrDataFrame    df;

    try  {
        df.read("IBM.csv", io_format::csv2);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
        ::exit(-1);
    }

    const auto  result = df.fast_ica<double>({ "IBM_Close", "IBM_Open", "IBM_High", "IBM_Low" }, 2, { .seed = 21 });

    assert(result.rows() == 5031);
    assert(result.cols() == 2);
    assert((std::fabs(result(0, 0) - 0.01778) < 0.00001));
    assert((std::fabs(result(0, 1) - -0.0123) < 0.00001));
    assert((std::fabs(result(678, 0) - 0.0484) < 0.00001));
    assert((std::fabs(result(678, 1) - -0.01284) < 0.00001));
    assert((std::fabs(result(1852, 0) - 0.02188) < 0.00001));
    assert((std::fabs(result(1852, 1) - 0.01310) < 0.00001));
    assert((std::fabs(result(4008, 0) - -0.03373) < 0.00001));
    assert((std::fabs(result(4008, 1) - 0.02964) < 0.00001));
    assert((std::fabs(result(5030, 0) - -0.0237) < 0.00001));
    assert((std::fabs(result(5030, 1) - -0.06062) < 0.00001));
}

C++ DataFrame