EWM === .. cpp:class:: numpy::EWM numpy C++ class. Example ------- .. code-block:: cpp #include using namespace numpy; // Use EWM EWM obj; // ... operations ... Constructors ------------ .. list-table:: :widths: 55 25 20 :header-rows: 1 * - Signature - Location - Example * - ``EWM(const Series& series, double alpha, bool adjust, bool ignore_na, size_t min_periods)`` - df_ewm.h:50 - Construction ------------ .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``static EWM from_alpha(const Series& series, double alpha, bool adjust = true, bool ignore_na = false, size_t min_periods = 0)`` - static EWM - df_ewm.h:120 - * - ``static EWM from_com(const Series& series, double com, bool adjust = true, bool ignore_na = false, size_t min_periods = 0)`` - static EWM - df_ewm.h:86 - * - ``static EWM from_halflife(const Series& series, double halflife, bool adjust = true, bool ignore_na = false, size_t min_periods = 0)`` - static EWM - df_ewm.h:103 - * - ``static EWM from_span(const Series& series, double span, bool adjust = true, bool ignore_na = false, size_t min_periods = 0)`` - static EWM - df_ewm.h:69 - Indexing / Selection -------------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``double get_value(size_t i) const`` - double - df_ewm.h:292 - Statistics ---------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``Series mean() const`` - Series - df_ewm.h:133 - :ref:`View ` * - ``Series std\_(int ddof = 1) const`` - Series - df_ewm.h:268 - * - ``Series var(int ddof = 1) const`` - Series - df_ewm.h:206 - :ref:`View ` Other Methods ------------- .. list-table:: :widths: 40 20 15 25 :header-rows: 1 * - Signature - Return Type - Location - Example * - ``bool adjust() const`` - bool - df_ewm.h:285 - * - ``double alpha() const`` - double - df_ewm.h:284 - * - ``bool ignore_na() const`` - bool - df_ewm.h:286 - Code Examples ------------- The following examples are extracted from the test suite. .. _example-ewm-mean-0: .. dropdown:: mean (np_test_1_all.cpp:11714) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11704 :emphasize-lines: 11 // Create test array auto array = createInt32Array({ 2, 3 }, 0); array.setElementAt({ 0, 0 }, 1); array.setElementAt({ 0, 1 }, 2); array.setElementAt({ 0, 2 }, 3); array.setElementAt({ 1, 0 }, 4); array.setElementAt({ 1, 1 }, 5); array.setElementAt({ 1, 2 }, 6); // Test mean without axis auto mean_all = mean(array); if (!(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))) { std::string description = std::string("testBasicStatistics():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(mean_all.getElementAt({ 0 }), 3.5, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] mean (all elements) works correctly\n"; // Test mean along axis 0 auto mean_axis0 = mean(array, 0); if (!(mean_axis0.getShape()[0] == 3)) { .. _example-ewm-var-1: .. dropdown:: var (np_test_1_all.cpp:11816) :class-title: example-dropdown .. code-block:: cpp :linenos: :lineno-start: 11806 :emphasize-lines: 11 std::cout << "========= testVarianceAndStandardDeviation ======================="; // Create test array with known variance auto array = createFloat64Array({ 4 }, 0); array.setElementAt({ 0 }, 1.0); array.setElementAt({ 1 }, 2.0); array.setElementAt({ 2 }, 3.0); array.setElementAt({ 3 }, 4.0); // Test variance (population) auto var_result = var(array, std::nullopt, 0); // ddof=0 for population variance double expected_var = 1.25; // Known variance for [1,2,3,4] if (!(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))) { std::string description = std::string("testVarianceAndStandardDeviation():") + __FILE__ + ":" + std::to_string(__LINE__) + ": !(approx_equal(var_result.getElementAt({ 0 }), expected_var, 1e-10))"; std::cout << std::string("[FAIL] ") + description << std::endl; throw std::runtime_error(description); } // std::cout << "[OK] Population variance works correctly\n"; // Test variance (sample) auto var_sample = var(array, std::nullopt, 1); // ddof=1 for sample variance