| Signature | Description | Parameters |
|---|---|---|
#include <DataFrame/DataFrameStatsVisitors.h> template<typename T, typename I = unsigned long> struct TrackingErrorVisitor; // ------------------------------------- template<typename T, typename I = unsigned long> using te_v = TrackingErrorVisitor<T, I>; |
This functor class calculates the tracking error between two columns. Tracking error is the standard deviation of the difference vector. This works with both scalar and multidimensional (i.e. vector and arrays) datasets. For multidimensiional datasetes, you must use the single_act_visit() interface.
explicit
TrackingErrorVisitor(bool bias = true);
bias: If true it divides by n - 1, otherwise by n.There are also the following member functions:
get_result(): Returns the Tracking Error.
In case of scalar dataset, TE is a single number. In case of multidimensional dataset,
TE is a vector of data dimension size.
|
T: Column data type. I: Index type. |
static void test_tracking_error() { std::cout << "\nTesting Tracking Error ..." << std::endl; StlVecType<unsigned long> idx = { 123450, 123451, 123452, 123453, 123454, 123455, 123456, 123457, 123458, 123459, 123460, 123461, 123462, 123466, 123467, 123468, 123469, 123470, 123471, 123472, 123473 }; StlVecType<double> d1 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; StlVecType<double> d2 = { 1.0, 10, 8, 18, 19, 16, 21, 17, 20, 3, 2, 11, 7.0, 5, 9, 15, 14, 13, 12, 6, 4 }; StlVecType<double> d3 = { 1.1, 10.09, 8.2, 18.03, 19.4, 15.9, 20.8, 17.1, 19.9, 3.3, 2.2, 10.8, 7.4, 5.3, 9.1, 14.9, 14.8, 13.2, 12.6, 6.1, 4.4 }; StlVecType<double> d4 = { 0.1, 9.09, 7.2, 17.03, 18.4, 14.9, 19.8, 16.1, 18.9, 2.3, 1.2, 9.8, 6.4, 4.3, 8.1, 13.9, 13.8, 12.2, 11.6, 5.1, 3.4 }; StlVecType<double> d5 = { 20.0, 10.1, -30.2, 18.5, 1.1, 16.2, 30.8, -1.56, 20.1, 25.5, 30.89, 11.1, 7.4, 5.3, 19, 15.1, 1.3, 1.2, 12.6, 23.2, 40.1 }; MyDataFrame df; df.load_data(std::move(idx), std::make_pair("dblcol_1", d1), std::make_pair("dblcol_2", d2), std::make_pair("dblcol_3", d3), std::make_pair("dblcol_4", d4), std::make_pair("dblcol_5", d5)); TrackingErrorVisitor<double> tracking_visit; double result = df.visit<double, double>("dblcol_1", "dblcol_2", tracking_visit).get_result(); assert(result == 0.0); result = df.visit<double, double>("dblcol_1", "dblcol_3", tracking_visit, true).get_result(); assert(fabs(result - 0.256416) < 0.00001); result = df.visit<double, double>("dblcol_1", "dblcol_4", tracking_visit).get_result(); assert(fabs(result - 0.256416) < 0.00001); result = df.visit<double, double>("dblcol_3", "dblcol_4", tracking_visit).get_result(); assert(result == 0.0); result = df.visit<double, double>("dblcol_2", "dblcol_4", tracking_visit).get_result(); assert(fabs(result - 0.256416) < 0.00001); result = df.visit<double, double>("dblcol_1", "dblcol_5", tracking_visit).get_result(); assert(fabs(result - 17.0566) < 0.0001); // Now multidimensional data // RandGenParams<double> p; p.seed = 123; p.min_value = -20.0; p.max_value = 20.0; using col_t = std::array<double, 3>; const auto rand_vec = gen_uniform_real_dist<double, 64>(df.get_index().size() * 3 * 2, p); StlVecType<col_t> multi_dimen_col1(df.get_index().size()); StlVecType<col_t> multi_dimen_col2(df.get_index().size()); for (std::size_t i { 0 }, j { 0 }; j < rand_vec.size(); ++i) { multi_dimen_col1[i][0] = rand_vec[j++]; multi_dimen_col1[i][1] = rand_vec[j++]; multi_dimen_col1[i][2] = rand_vec[j++]; multi_dimen_col2[i][0] = rand_vec[j++]; multi_dimen_col2[i][1] = rand_vec[j++]; multi_dimen_col2[i][2] = rand_vec[j++]; } df.load_column<col_t>("multi_dimen_col1", std::move(multi_dimen_col1)); df.load_column<col_t>("multi_dimen_col2", std::move(multi_dimen_col2)); TrackingErrorVisitor<col_t> md_te; df.single_act_visit<col_t, col_t>("multi_dimen_col1", "multi_dimen_col2", md_te); const auto &md_result { md_te.get_result() }; assert(md_result.size() == 3); assert(fabs(md_result[0] - 15.0167) < 0.0001); assert(fabs(md_result[1] - 15.7958) < 0.0001); assert(fabs(md_result[2] - 17.6217) < 0.0001); }