diff --git a/ALFI/ALFI/dist.h b/ALFI/ALFI/dist.h index ca01b9a..09c7558 100644 --- a/ALFI/ALFI/dist.h +++ b/ALFI/ALFI/dist.h @@ -13,14 +13,14 @@ namespace alfi::dist { CUBIC, CHEBYSHEV, CHEBYSHEV_STRETCHED, - CIRCLE_PROJ, - CIRCLE_PROJ_NO_LAST, - CIRCLE_PROJ_NO_FIRST, + CHEBYSHEV_2, + CHEBYSHEV_3, + CHEBYSHEV_4, CHEBYSHEV_ELLIPSE, CHEBYSHEV_ELLIPSE_STRETCHED, - ELLIPSE_PROJ, - ELLIPSE_PROJ_NO_LAST, - ELLIPSE_PROJ_NO_FIRST, + CHEBYSHEV_ELLIPSE_2, + CHEBYSHEV_ELLIPSE_3, + CHEBYSHEV_ELLIPSE_4, LOGISTIC, LOGISTIC_STRETCHED, ERF, @@ -115,7 +115,7 @@ namespace alfi::dist { } template class Container = DefaultContainer> - Container circle_proj(SizeT n, Number a, Number b) { + Container chebyshev_2(SizeT n, Number a, Number b) { if (n == 1) return {(a+b)/2}; Container points(n); @@ -127,7 +127,7 @@ namespace alfi::dist { } template class Container = DefaultContainer> - Container circle_proj_no_last(SizeT n, Number a, Number b) { + Container chebyshev_3(SizeT n, Number a, Number b) { Container points(n); for (SizeT i = 0; i < n; ++i) { const Number x = 1 - std::cos(M_PI * static_cast(2*i) / static_cast(2*n - 1)); @@ -137,7 +137,7 @@ namespace alfi::dist { } template class Container = DefaultContainer> - Container circle_proj_no_first(SizeT n, Number a, Number b) { + Container chebyshev_4(SizeT n, Number a, Number b) { Container points(n); for (SizeT i = 0; i < n; ++i) { const Number x = 1 - std::cos(M_PI * static_cast(2*i + 1) / static_cast(2*n - 1)); @@ -166,7 +166,7 @@ namespace alfi::dist { } template class Container = DefaultContainer> - Container ellipse_proj(SizeT n, Number a, Number b, Number ratio) { + Container chebyshev_ellipse_2(SizeT n, Number a, Number b, Number ratio) { Container points(n); for (SizeT i = 0; i < n / 2; ++i) { const Number theta = M_PI * static_cast(i) / (static_cast(n) - 1); @@ -180,7 +180,7 @@ namespace alfi::dist { } template class Container = DefaultContainer> - Container ellipse_proj_no_last(SizeT n, Number a, Number b, Number ratio) { + Container chebyshev_ellipse_3(SizeT n, Number a, Number b, Number ratio) { Container points(n); for (SizeT i = 0; i < n; ++i) { const Number theta = M_PI * static_cast(2*i) / static_cast(2*n - 1); @@ -191,7 +191,7 @@ namespace alfi::dist { } template class Container = DefaultContainer> - Container ellipse_proj_no_first(SizeT n, Number a, Number b, Number ratio) { + Container chebyshev_ellipse_4(SizeT n, Number a, Number b, Number ratio) { Container points(n); for (SizeT i = 0; i < n; ++i) { const Number theta = M_PI * static_cast(2*i + 1) / static_cast(2*n - 1); @@ -310,22 +310,22 @@ namespace alfi::dist { return chebyshev(n, a, b); case Type::CHEBYSHEV_STRETCHED: return chebyshev_stretched(n, a, b); - case Type::CIRCLE_PROJ: - return circle_proj(n, a, b); - case Type::CIRCLE_PROJ_NO_LAST: - return circle_proj_no_last(n, a, b); - case Type::CIRCLE_PROJ_NO_FIRST: - return circle_proj_no_first(n, a, b); + case Type::CHEBYSHEV_2: + return chebyshev_2(n, a, b); + case Type::CHEBYSHEV_3: + return chebyshev_3(n, a, b); + case Type::CHEBYSHEV_4: + return chebyshev_4(n, a, b); case Type::CHEBYSHEV_ELLIPSE: return chebyshev_ellipse(n, a, b, parameter); case Type::CHEBYSHEV_ELLIPSE_STRETCHED: return chebyshev_ellipse_stretched(n, a, b, parameter); - case Type::ELLIPSE_PROJ: - return ellipse_proj(n, a, b, parameter); - case Type::ELLIPSE_PROJ_NO_LAST: - return ellipse_proj_no_last(n, a, b, parameter); - case Type::ELLIPSE_PROJ_NO_FIRST: - return ellipse_proj_no_first(n, a, b, parameter); + case Type::CHEBYSHEV_ELLIPSE_2: + return chebyshev_ellipse_2(n, a, b, parameter); + case Type::CHEBYSHEV_ELLIPSE_3: + return chebyshev_ellipse_3(n, a, b, parameter); + case Type::CHEBYSHEV_ELLIPSE_4: + return chebyshev_ellipse_4(n, a, b, parameter); case Type::LOGISTIC: return logistic(n, a, b, parameter); case Type::LOGISTIC_STRETCHED: diff --git a/ALFI/ALFI/misc.h b/ALFI/ALFI/misc.h index bf99fc4..1482381 100644 --- a/ALFI/ALFI/misc.h +++ b/ALFI/ALFI/misc.h @@ -57,21 +57,21 @@ namespace alfi::misc { for (SizeT j = 0; j < N; ++j) { W[j] = (j % 2 == 0 ? 1 : -1) * std::sin(((2 * static_cast(j) + 1) * M_PI) / (2 * static_cast(N))); } - } else if (dist_type == dist::Type::CIRCLE_PROJ) { + } else if (dist_type == dist::Type::CHEBYSHEV_2) { for (SizeT j = 0; j < N; ++j) { W[j] = (j % 2 == 0 ? 1 : -1); if (j == 0 || j == N - 1) { W[j] /= 2; } } - } else if (dist_type == dist::Type::CIRCLE_PROJ_NO_LAST) { + } else if (dist_type == dist::Type::CHEBYSHEV_3) { for (SizeT j = 0; j < N; ++j) { W[j] = (j % 2 == 0 ? 1 : -1) * std::cos((static_cast(2*j) * M_PI) / static_cast(2*N - 1) / 2); if (j == 0) { W[j] /= 2; } } - } else if (dist_type == dist::Type::CIRCLE_PROJ_NO_FIRST) { + } else if (dist_type == dist::Type::CHEBYSHEV_4) { for (SizeT j = 0; j < N; ++j) { W[j] = (j % 2 == 0 ? 1 : -1) * std::sin((static_cast(2*j + 1) * M_PI) / static_cast(2*N - 1) / 2); if (j == N - 1) { diff --git a/examples/dist_QCustomPlot/dist_QCustomPlot.cpp b/examples/dist_QCustomPlot/dist_QCustomPlot.cpp index e42d68b..90a659b 100644 --- a/examples/dist_QCustomPlot/dist_QCustomPlot.cpp +++ b/examples/dist_QCustomPlot/dist_QCustomPlot.cpp @@ -16,8 +16,8 @@ class PlotWindow final : public QWidget { PlotWindow() { static const VariableParams n_params = {7, 1, 40, 1}; - static const VariableParams a_params = {0.0, 0.0, 100.0, 0.01}; - static const VariableParams b_params = {1.0, 0.0, 100.0, 0.01}; + static const VariableParams a_params = {0.0, -100.0, 100.0, 0.01}; + static const VariableParams b_params = {1.0, -100.0, 100.0, 0.01}; static const VariableParams ratio_params = {2.0, 0.0, 4.0, 0.01}; static const VariableParams steepness_params = {8.0, 0.0, 10.0, 0.01}; @@ -178,7 +178,7 @@ class PlotWindow final : public QWidget { const size_t n = _n_spin_box->value(); const double a = _a_spin_box->value(); const double b = _b_spin_box->value(); - const double B = _ratio_spin_box->value(); + const double ratio = _ratio_spin_box->value(); const double steepness = _steepness_spin_box->value(); const QVector>> distributions = { @@ -187,10 +187,10 @@ class PlotWindow final : public QWidget { {"Cubic", alfi::dist::cubic(n, a, b)}, {"Chebyshev", alfi::dist::chebyshev(n, a, b)}, {"Stretched Chebyshev", alfi::dist::chebyshev_stretched(n, a, b)}, - {"Circle Projection", alfi::dist::circle_proj(n, a, b)}, - {"Chebyshev Ellipse", alfi::dist::chebyshev_ellipse(n, a, b, B)}, - {"Stretched Chebyshev Ellipse", alfi::dist::chebyshev_ellipse_stretched(n, a, b, B)}, - {"Ellipse Projection", alfi::dist::ellipse_proj(n, a, b, B)}, + {"Chebyshev Second Kind", alfi::dist::chebyshev_2(n, a, b)}, + {"Chebyshev Ellipse", alfi::dist::chebyshev_ellipse(n, a, b, ratio)}, + {"Stretched Chebyshev Ellipse", alfi::dist::chebyshev_ellipse_stretched(n, a, b, ratio)}, + {"Chebyshev Ellipse Second Kind", alfi::dist::chebyshev_ellipse_2(n, a, b, ratio)}, {"Logistic", alfi::dist::logistic(n, a, b, steepness)}, {"Stretched Logistic", alfi::dist::logistic_stretched(n, a, b, steepness)}, {"Error function", alfi::dist::erf(n, a, b, steepness)}, diff --git a/examples/dist_gnuplot/dist_gnuplot.cpp b/examples/dist_gnuplot/dist_gnuplot.cpp index cab33b4..e9f3afd 100644 --- a/examples/dist_gnuplot/dist_gnuplot.cpp +++ b/examples/dist_gnuplot/dist_gnuplot.cpp @@ -71,10 +71,10 @@ int main() { {"Cubic", alfi::dist::cubic(n, a, b)}, {"Chebyshev", alfi::dist::chebyshev(n, a, b)}, {"Stretched Chebyshev", alfi::dist::chebyshev_stretched(n, a, b)}, - {"Circle Projection", alfi::dist::circle_proj(n, a, b)}, + {"Chebyshev Second Kind", alfi::dist::chebyshev_2(n, a, b)}, {"Chebyshev Ellipse", alfi::dist::chebyshev_ellipse(n, a, b, ratio)}, {"Stretched Chebyshev Ellipse", alfi::dist::chebyshev_ellipse_stretched(n, a, b, ratio)}, - {"Ellipse Projection", alfi::dist::ellipse_proj(n, a, b, ratio)}, + {"Chebyshev Ellipse Second Kind", alfi::dist::chebyshev_ellipse_2(n, a, b, ratio)}, {"Logistic", alfi::dist::logistic(n, a, b, logistic_steepness)}, {"Stretched Logistic", alfi::dist::logistic_stretched(n, a, b, logistic_steepness)}, {"Error function", alfi::dist::erf(n, a, b, erf_steepness)}, diff --git a/examples/interpolation/interpolation.cpp b/examples/interpolation/interpolation.cpp index 591ca0f..7ab8c7b 100644 --- a/examples/interpolation/interpolation.cpp +++ b/examples/interpolation/interpolation.cpp @@ -85,9 +85,9 @@ class PlotWindow final : public QWidget { PlotWindow() { static const QStringList distribution_types { "Uniform", "Quadratic", "Cubic", "Chebyshev", "Stretched Chebyshev", - "Circle Projection", "Circle Projection Without Last", "Circle Projection Without First", - "Chebyshev Ellipse", "Stretched Chebyshev Ellipse", "Ellipse Projection", - "Ellipse Projection Without Last", "Ellipse Projection Without First", + "Chebyshev Second Kind", "Chebyshev Third Kind", "Chebyshev Fourth Kind", + "Chebyshev Ellipse", "Stretched Chebyshev Ellipse", "Chebyshev Ellipse Second Kind", + "Chebyshev Ellipse Third Kind", "Chebyshev Ellipse Fourth Kind", "Logistic", "Stretched Logistic", "Error Function", "Stretched Error Function" }; @@ -280,14 +280,14 @@ class PlotWindow final : public QWidget { case alfi::dist::Type::CUBIC: X = alfi::dist::cubic(N, a, b); break; case alfi::dist::Type::CHEBYSHEV: X = alfi::dist::chebyshev(N, a, b); break; case alfi::dist::Type::CHEBYSHEV_STRETCHED: X = alfi::dist::chebyshev_stretched(N, a, b); break; - case alfi::dist::Type::CIRCLE_PROJ: X = alfi::dist::circle_proj(N, a, b); break; - case alfi::dist::Type::CIRCLE_PROJ_NO_LAST: X = alfi::dist::circle_proj_no_last(N, a, b); break; - case alfi::dist::Type::CIRCLE_PROJ_NO_FIRST: X = alfi::dist::circle_proj_no_first(N, a, b); break; + case alfi::dist::Type::CHEBYSHEV_2: X = alfi::dist::chebyshev_2(N, a, b); break; + case alfi::dist::Type::CHEBYSHEV_3: X = alfi::dist::chebyshev_3(N, a, b); break; + case alfi::dist::Type::CHEBYSHEV_4: X = alfi::dist::chebyshev_4(N, a, b); break; case alfi::dist::Type::CHEBYSHEV_ELLIPSE: X = alfi::dist::chebyshev_ellipse(N, a, b, 2.0); break; case alfi::dist::Type::CHEBYSHEV_ELLIPSE_STRETCHED: X = alfi::dist::chebyshev_ellipse_stretched(N, a, b, 2.0); break; - case alfi::dist::Type::ELLIPSE_PROJ: X = alfi::dist::ellipse_proj(N, a, b, 2.0); break; - case alfi::dist::Type::ELLIPSE_PROJ_NO_LAST: X = alfi::dist::ellipse_proj_no_last(N, a, b, 2.0); break; - case alfi::dist::Type::ELLIPSE_PROJ_NO_FIRST: X = alfi::dist::ellipse_proj_no_first(N, a, b, 2.0); break; + case alfi::dist::Type::CHEBYSHEV_ELLIPSE_2: X = alfi::dist::chebyshev_ellipse_2(N, a, b, 2.0); break; + case alfi::dist::Type::CHEBYSHEV_ELLIPSE_3: X = alfi::dist::chebyshev_ellipse_3(N, a, b, 2.0); break; + case alfi::dist::Type::CHEBYSHEV_ELLIPSE_4: X = alfi::dist::chebyshev_ellipse_4(N, a, b, 2.0); break; case alfi::dist::Type::LOGISTIC: X = alfi::dist::logistic(N, a, b, 16.0); break; case alfi::dist::Type::LOGISTIC_STRETCHED: X = alfi::dist::logistic_stretched(N, a, b, 16.0); break; case alfi::dist::Type::ERF: X = alfi::dist::erf(N, a, b, 8.0); break; diff --git a/tests/dist/test_dist.cpp b/tests/dist/test_dist.cpp index 6af7b03..23d71e7 100644 --- a/tests/dist/test_dist.cpp +++ b/tests/dist/test_dist.cpp @@ -54,6 +54,18 @@ TEST(DistributionsTest, ChebyshevStretched) { test_distribution("chebyshev_stretched", alfi::dist::Type::CHEBYSHEV_STRETCHED, 1e-11); } +TEST(DistributionsTest, Chebyshev2) { + test_distribution("chebyshev_2", alfi::dist::Type::CHEBYSHEV_2, 1e-11); +} + +TEST(DistributionsTest, Chebyshev3) { + test_distribution("chebyshev_3", alfi::dist::Type::CHEBYSHEV_3, 1e-15); +} + +TEST(DistributionsTest, Chebyshev4) { + test_distribution("chebyshev_4", alfi::dist::Type::CHEBYSHEV_4, 1e-15); +} + TEST(DistributionsTest, ChebyshevEllipse) { test_distribution("chebyshev_ellipse", alfi::dist::Type::CHEBYSHEV_ELLIPSE, 1e-14); } @@ -62,12 +74,16 @@ TEST(DistributionsTest, ChebyshevEllipseStretched) { test_distribution("chebyshev_ellipse_stretched", alfi::dist::Type::CHEBYSHEV_ELLIPSE_STRETCHED, 1e-11); } -TEST(DistributionsTest, CircleProjection) { - test_distribution("circle_proj", alfi::dist::Type::CIRCLE_PROJ, 1e-11); +TEST(DistributionsTest, ChebyshevEllipse2) { + test_distribution("chebyshev_ellipse_2", alfi::dist::Type::CHEBYSHEV_ELLIPSE_2, 1e-14); +} + +TEST(DistributionsTest, ChebyshevEllipse3) { + test_distribution("chebyshev_ellipse_3", alfi::dist::Type::CHEBYSHEV_ELLIPSE_3, 1e-13); } -TEST(DistributionsTest, EllipseProjection) { - test_distribution("ellipse_proj", alfi::dist::Type::ELLIPSE_PROJ, 1e-14); +TEST(DistributionsTest, ChebyshevEllipse4) { + test_distribution("chebyshev_ellipse_4", alfi::dist::Type::CHEBYSHEV_ELLIPSE_4, 1e-14); } TEST(DistributionsTest, Logistic) { diff --git a/tests/poly/test_imp_lagrange.cpp b/tests/poly/test_imp_lagrange.cpp index 57b5ab6..153052b 100644 --- a/tests/poly/test_imp_lagrange.cpp +++ b/tests/poly/test_imp_lagrange.cpp @@ -28,7 +28,7 @@ TEST(ImprovedLagrangeTest, Functions) { [](double x) { return std::exp(x); }, 1e-8); test_case( - alfi::dist::circle_proj(31, -2*M_PI, 2*M_PI), + alfi::dist::chebyshev_2(31, -2*M_PI, 2*M_PI), alfi::dist::uniform(10, -2*M_PI, 2*M_PI), [](double x) { return std::sin(x) + std::cos(x); }, 1e-5); diff --git a/tests/poly/test_lagrange.cpp b/tests/poly/test_lagrange.cpp index d607b23..497aceb 100644 --- a/tests/poly/test_lagrange.cpp +++ b/tests/poly/test_lagrange.cpp @@ -28,7 +28,7 @@ TEST(LagrangeTest, Functions) { [](double x) { return std::exp(x); }, 1e-6); test_case( - alfi::dist::circle_proj(31, -2*M_PI, 2*M_PI), + alfi::dist::chebyshev_2(31, -2*M_PI, 2*M_PI), alfi::dist::uniform(10, -2*M_PI, 2*M_PI), [](double x) { return std::sin(x) + std::cos(x); }, 2e-2); diff --git a/tests/poly/test_newton.cpp b/tests/poly/test_newton.cpp index 30267d6..54819cb 100644 --- a/tests/poly/test_newton.cpp +++ b/tests/poly/test_newton.cpp @@ -28,7 +28,7 @@ TEST(NewtonTest, Functions) { [](double x) { return std::exp(x); }, 1e-8); test_case( - alfi::dist::circle_proj(31, -2*M_PI, 2*M_PI), + alfi::dist::chebyshev_2(31, -2*M_PI, 2*M_PI), alfi::dist::uniform(10, -2*M_PI, 2*M_PI), [](double x) { return std::sin(x) + std::cos(x); }, 1e-6); diff --git a/tests/spline/test_cubic.cpp b/tests/spline/test_cubic.cpp index 0326195..5195a8c 100644 --- a/tests/spline/test_cubic.cpp +++ b/tests/spline/test_cubic.cpp @@ -18,7 +18,7 @@ TEST(CubicSplineTest, BasicConditions) { const double a = -1, b = 1; const auto X = alfi::dist::uniform(n, a, b); const auto dX = alfi::util::arrays::diff(X); - const auto Y = alfi::dist::circle_proj(n, a, b); + const auto Y = alfi::dist::chebyshev_2(n, a, b); auto spline = alfi::spline::CubicSpline<>(X, Y, alfi::spline::CubicSpline<>::Types::Natural{}); EXPECT_NEAR(0, 2*spline.coeffs()[1], 1e-17); EXPECT_NEAR(0, 2*spline.coeffs()[4*8+1] + 6*spline.coeffs()[4*8]*dX[8], 1e-15); @@ -53,7 +53,7 @@ TEST(CubicSplineTest, CustomConditions) { const double a = -1, b = 1; const auto X = alfi::dist::uniform(n, a, b); const auto dX = alfi::util::arrays::diff(X); - const auto Y = alfi::dist::circle_proj(n, a, b); + const auto Y = alfi::dist::chebyshev_2(n, a, b); auto spline = alfi::spline::CubicSpline<>(); // one point for (size_t i = 0; i < n; ++i) { diff --git a/tests/test_data b/tests/test_data index 183aff9..dc35815 160000 --- a/tests/test_data +++ b/tests/test_data @@ -1 +1 @@ -Subproject commit 183aff9875c4203c60bd5ed90cd6c20618babed3 +Subproject commit dc35815caccab2252941d94b2300e3c298254736