From d35526be738413a65ecb2544793a76c3c6ec2809 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 26 Dec 2023 23:31:06 +0100 Subject: [PATCH] Re-enabled statistics tests. --- test/mlpp_tests.cpp | 60 +++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/test/mlpp_tests.cpp b/test/mlpp_tests.cpp index 80640af..8503ab6 100644 --- a/test/mlpp_tests.cpp +++ b/test/mlpp_tests.cpp @@ -77,43 +77,45 @@ void MLPPTests::test_statistics() { MLPPConvolutions conv; // STATISTICS - std::vector x = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - std::vector y = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; - std::vector w = { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 }; + const real_t x_arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + const real_t y_arr[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; + const real_t w_arr[] = { 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 }; - /* - is_approx_equalsd(stat.mean(x), 5.5, "Arithmetic Mean"); - is_approx_equalsd(stat.mean(x), 5.5, "Median"); + Ref x = memnew(MLPPVector(x_arr, 10)); + Ref y = memnew(MLPPVector(y_arr, 10)); + Ref w = memnew(MLPPVector(w_arr, 10)); - is_approx_equals_dvec(dstd_vec_to_vec(stat.mode(x)), dstd_vec_to_vec(x), "stat.mode(x)"); + is_approx_equalsd(stat.meanv(x), 5.5, "Arithmetic Mean"); + is_approx_equalsd(stat.meanv(x), 5.5, "Median"); + + is_approx_equals_vec(stat.mode(x), x, "stat.mode(x)"); is_approx_equalsd(stat.range(x), 9, "Range"); is_approx_equalsd(stat.midrange(x), 4.5, "Midrange"); - is_approx_equalsd(stat.absAvgDeviation(x), 2.5, "Absolute Average Deviation"); - is_approx_equalsd(stat.standardDeviation(x), 3.02765, "Standard Deviation"); - is_approx_equalsd(stat.variance(x), 9.16667, "Variance"); - is_approx_equalsd(stat.covariance(x, y), -9.16667, "Covariance"); + is_approx_equalsd(stat.abs_avg_deviation(x), 2.5, "Absolute Average Deviation"); + is_approx_equalsd(stat.standard_deviationv(x), 3.02765, "Standard Deviation"); + is_approx_equalsd(stat.variancev(x), 9.16667, "Variance"); + is_approx_equalsd(stat.covariancev(x, y), -9.16667, "Covariance"); is_approx_equalsd(stat.correlation(x, y), -1, "Correlation"); - is_approx_equalsd(stat.R2(x, y), 1, "R^2"); + is_approx_equalsd(stat.r2(x, y), 1, "R^2"); // Returns 1 - (1/k^2) - is_approx_equalsd(stat.chebyshevIneq(2), 0.75, "Chebyshev Inequality"); - is_approx_equalsd(stat.weightedMean(x, w), 5.5, "Weighted Mean"); - is_approx_equalsd(stat.geometricMean(x), 4.52873, "Geometric Mean"); - is_approx_equalsd(stat.harmonicMean(x), 3.41417, "Harmonic Mean"); - is_approx_equalsd(stat.RMS(x), 6.20484, "Root Mean Square (Quadratic mean)"); - is_approx_equalsd(stat.powerMean(x, 5), 7.39281, "Power Mean (p = 5)"); - is_approx_equalsd(stat.lehmerMean(x, 5), 8.71689, "Lehmer Mean (p = 5)"); - is_approx_equalsd(stat.weightedLehmerMean(x, w, 5), 8.71689, "Weighted Lehmer Mean (p = 5)"); - is_approx_equalsd(stat.contraHarmonicMean(x), 7, "Contraharmonic Mean"); - is_approx_equalsd(stat.heronianMean(1, 10), 4.72076, "Hernonian Mean"); - is_approx_equalsd(stat.heinzMean(1, 10, 1), 5.5, "Heinz Mean (x = 1)"); - is_approx_equalsd(stat.neumanSandorMean(1, 10), 3.36061, "Neuman-Sandor Mean"); - is_approx_equalsd(stat.stolarskyMean(1, 10, 5), 6.86587, "Stolarsky Mean (p = 5)"); - is_approx_equalsd(stat.identricMean(1, 10), 4.75135, "Identric Mean"); - is_approx_equalsd(stat.logMean(1, 10), 3.90865, "Logarithmic Mean"); - is_approx_equalsd(stat.absAvgDeviation(x), 2.5, "Absolute Average Deviation"); - */ + is_approx_equalsd(stat.chebyshev_ineq(2), 0.75, "Chebyshev Inequality"); + is_approx_equalsd(stat.weighted_mean(x, w), 5.5, "Weighted Mean"); + is_approx_equalsd(stat.geometric_mean(x), 4.52873, "Geometric Mean"); + is_approx_equalsd(stat.harmonic_mean(x), 3.41417, "Harmonic Mean"); + is_approx_equalsd(stat.rms(x), 6.20484, "Root Mean Square (Quadratic mean)"); + is_approx_equalsd(stat.power_mean(x, 5), 7.39281, "Power Mean (p = 5)"); + is_approx_equalsd(stat.lehmer_mean(x, 5), 8.71689, "Lehmer Mean (p = 5)"); + is_approx_equalsd(stat.weighted_lehmer_mean(x, w, 5), 8.71689, "Weighted Lehmer Mean (p = 5)"); + is_approx_equalsd(stat.contra_harmonic_mean(x), 7, "Contraharmonic Mean"); + is_approx_equalsd(stat.heronian_mean(1, 10), 4.72076, "Hernonian Mean"); + is_approx_equalsd(stat.heinz_mean(1, 10, 1), 5.5, "Heinz Mean (x = 1)"); + is_approx_equalsd(stat.neuman_sandor_mean(1, 10), 3.36061, "Neuman-Sandor Mean"); + is_approx_equalsd(stat.stolarsky_mean(1, 10, 5), 6.86587, "Stolarsky Mean (p = 5)"); + is_approx_equalsd(stat.identric_mean(1, 10), 4.75135, "Identric Mean"); + is_approx_equalsd(stat.log_mean(1, 10), 3.90865, "Logarithmic Mean"); + is_approx_equalsd(stat.abs_avg_deviation(x), 2.5, "Absolute Average Deviation"); ERR_PRINT("MLPPTests::test_statistics() Finished!"); }