diff --git a/ALFI/ALFI/dist.h b/ALFI/ALFI/dist.h index ec5752e..d6ba31b 100644 --- a/ALFI/ALFI/dist.h +++ b/ALFI/ALFI/dist.h @@ -16,13 +16,17 @@ namespace alfi::dist { CHEBYSHEV_AUGMENTED, CHEBYSHEV_2, CHEBYSHEV_3, + CHEBYSHEV_3_STRETCHED, CHEBYSHEV_4, + CHEBYSHEV_4_STRETCHED, CHEBYSHEV_ELLIPSE, CHEBYSHEV_ELLIPSE_STRETCHED, CHEBYSHEV_ELLIPSE_AUGMENTED, CHEBYSHEV_ELLIPSE_2, CHEBYSHEV_ELLIPSE_3, + CHEBYSHEV_ELLIPSE_3_STRETCHED, CHEBYSHEV_ELLIPSE_4, + CHEBYSHEV_ELLIPSE_4_STRETCHED, LOGISTIC, LOGISTIC_STRETCHED, ERF, @@ -154,6 +158,11 @@ namespace alfi::dist { return points; } + template class Container = DefaultContainer> + Container chebyshev_3_stretched(SizeT n, Number a, Number b) { + return points::stretched(chebyshev_3(n, a, b), a, b); + } + template class Container = DefaultContainer> Container chebyshev_4(SizeT n, Number a, Number b) { Container points(n); @@ -164,6 +173,11 @@ namespace alfi::dist { return points; } + template class Container = DefaultContainer> + Container chebyshev_4_stretched(SizeT n, Number a, Number b) { + return points::stretched(chebyshev_4(n, a, b), a, b); + } + template class Container = DefaultContainer> Container chebyshev_ellipse(SizeT n, Number a, Number b, Number ratio) { Container points(n); @@ -224,6 +238,11 @@ namespace alfi::dist { return points; } + template class Container = DefaultContainer> + Container chebyshev_ellipse_3_stretched(SizeT n, Number a, Number b, Number ratio) { + return points::stretched(chebyshev_ellipse_3(n, a, b, ratio), a, b); + } + template class Container = DefaultContainer> Container chebyshev_ellipse_4(SizeT n, Number a, Number b, Number ratio) { Container points(n); @@ -235,6 +254,11 @@ namespace alfi::dist { return points; } + template class Container = DefaultContainer> + Container chebyshev_ellipse_4_stretched(SizeT n, Number a, Number b, Number ratio) { + return points::stretched(chebyshev_ellipse_4(n, a, b, ratio), a, b); + } + /** @brief Generates a distribution of \p n points on the interval `(a, b)` using the logistic function. @@ -350,8 +374,12 @@ namespace alfi::dist { return chebyshev_2(n, a, b); case Type::CHEBYSHEV_3: return chebyshev_3(n, a, b); + case Type::CHEBYSHEV_3_STRETCHED: + return chebyshev_3_stretched(n, a, b); case Type::CHEBYSHEV_4: return chebyshev_4(n, a, b); + case Type::CHEBYSHEV_4_STRETCHED: + return chebyshev_4_stretched(n, a, b); case Type::CHEBYSHEV_ELLIPSE: return chebyshev_ellipse(n, a, b, parameter); case Type::CHEBYSHEV_ELLIPSE_STRETCHED: @@ -362,8 +390,12 @@ namespace alfi::dist { 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_3_STRETCHED: + return chebyshev_ellipse_3_stretched(n, a, b, parameter); case Type::CHEBYSHEV_ELLIPSE_4: return chebyshev_ellipse_4(n, a, b, parameter); + case Type::CHEBYSHEV_ELLIPSE_4_STRETCHED: + return chebyshev_ellipse_4_stretched(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 740eecd..831b040 100644 --- a/ALFI/ALFI/misc.h +++ b/ALFI/ALFI/misc.h @@ -70,14 +70,14 @@ namespace alfi::misc { W[j] /= 2; } } - } else if (dist_type == dist::Type::CHEBYSHEV_3) { + } else if (dist_type == dist::Type::CHEBYSHEV_3 || dist_type == dist::Type::CHEBYSHEV_3_STRETCHED) { 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::CHEBYSHEV_4) { + } else if (dist_type == dist::Type::CHEBYSHEV_4 || dist_type == dist::Type::CHEBYSHEV_4_STRETCHED) { 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/interpolation/interpolation.cpp b/examples/interpolation/interpolation.cpp index 2805604..05e8c6a 100644 --- a/examples/interpolation/interpolation.cpp +++ b/examples/interpolation/interpolation.cpp @@ -84,10 +84,10 @@ class PlotWindow final : public QWidget { PlotWindow() { static const QStringList distribution_types { - "Uniform", "Quadratic", "Cubic", "Chebyshev", "Stretched Chebyshev", "Augmented Chebyshev", - "Chebyshev Second Kind", "Chebyshev Third Kind", "Chebyshev Fourth Kind", - "Chebyshev Ellipse", "Stretched Chebyshev Ellipse", "Augmented Chebyshev Ellipse", - "Chebyshev Ellipse Second Kind", "Chebyshev Ellipse Third Kind", "Chebyshev Ellipse Fourth Kind", + "Uniform", "Quadratic", "Cubic", "Chebyshev", "Stretched Chebyshev", "Augmented Chebyshev", "Chebyshev Second Kind", + "Chebyshev Third Kind", "Stretched Chebyshev Third Kind", "Chebyshev Fourth Kind", "Stretched Chebyshev Fourth Kind", + "Chebyshev Ellipse", "Stretched Chebyshev Ellipse", "Augmented Chebyshev Ellipse", "Chebyshev Ellipse Second Kind", + "Chebyshev Ellipse Third Kind", "Stretched Chebyshev Ellipse Third Kind", "Chebyshev Ellipse Fourth Kind", "Stretched Chebyshev Ellipse Fourth Kind", "Logistic", "Stretched Logistic", "Error Function", "Stretched Error Function" }; @@ -283,13 +283,17 @@ class PlotWindow final : public QWidget { case alfi::dist::Type::CHEBYSHEV_AUGMENTED: X = alfi::dist::chebyshev_augmented(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_3_STRETCHED: X = alfi::dist::chebyshev_3_stretched(N, a, b); break; case alfi::dist::Type::CHEBYSHEV_4: X = alfi::dist::chebyshev_4(N, a, b); break; + case alfi::dist::Type::CHEBYSHEV_4_STRETCHED: X = alfi::dist::chebyshev_4_stretched(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::CHEBYSHEV_ELLIPSE_AUGMENTED: X = alfi::dist::chebyshev_ellipse_augmented(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_3_STRETCHED: X = alfi::dist::chebyshev_ellipse_3_stretched(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::CHEBYSHEV_ELLIPSE_4_STRETCHED: X = alfi::dist::chebyshev_ellipse_4_stretched(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 14114dc..d8154c5 100644 --- a/tests/dist/test_dist.cpp +++ b/tests/dist/test_dist.cpp @@ -66,10 +66,18 @@ TEST(DistributionsTest, Chebyshev3) { test_distribution("chebyshev_3", alfi::dist::Type::CHEBYSHEV_3, 1e-15); } +TEST(DistributionsTest, Chebyshev3Stretched) { + test_distribution("chebyshev_3_stretched", alfi::dist::Type::CHEBYSHEV_3_STRETCHED, 1e-15); +} + TEST(DistributionsTest, Chebyshev4) { test_distribution("chebyshev_4", alfi::dist::Type::CHEBYSHEV_4, 1e-15); } +TEST(DistributionsTest, Chebyshev4Stretched) { + test_distribution("chebyshev_4_stretched", alfi::dist::Type::CHEBYSHEV_4_STRETCHED, 1e-15); +} + TEST(DistributionsTest, ChebyshevEllipse) { test_distribution("chebyshev_ellipse", alfi::dist::Type::CHEBYSHEV_ELLIPSE, 1e-14); } @@ -90,10 +98,18 @@ TEST(DistributionsTest, ChebyshevEllipse3) { test_distribution("chebyshev_ellipse_3", alfi::dist::Type::CHEBYSHEV_ELLIPSE_3, 1e-13); } +TEST(DistributionsTest, ChebyshevEllipse3Stretched) { + test_distribution("chebyshev_ellipse_3_stretched", alfi::dist::Type::CHEBYSHEV_ELLIPSE_3_STRETCHED, 1e-13); +} + TEST(DistributionsTest, ChebyshevEllipse4) { test_distribution("chebyshev_ellipse_4", alfi::dist::Type::CHEBYSHEV_ELLIPSE_4, 1e-14); } +TEST(DistributionsTest, ChebyshevEllipse4Stretched) { + test_distribution("chebyshev_ellipse_4_stretched", alfi::dist::Type::CHEBYSHEV_ELLIPSE_4_STRETCHED, 1e-13); +} + TEST(DistributionsTest, Logistic) { test_distribution("logistic", alfi::dist::Type::LOGISTIC, 1e-13); } diff --git a/tests/test_data b/tests/test_data index 1dd1b7d..615bbf9 160000 --- a/tests/test_data +++ b/tests/test_data @@ -1 +1 @@ -Subproject commit 1dd1b7ddb538140a938c380b2792c5db5e91cabf +Subproject commit 615bbf9b03840562e69db706b205ba8c7d8c128e