Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions ALFI/ALFI/dist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -115,7 +115,7 @@ namespace alfi::dist {
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> circle_proj(SizeT n, Number a, Number b) {
Container<Number> chebyshev_2(SizeT n, Number a, Number b) {
if (n == 1)
return {(a+b)/2};
Container<Number> points(n);
Expand All @@ -127,7 +127,7 @@ namespace alfi::dist {
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> circle_proj_no_last(SizeT n, Number a, Number b) {
Container<Number> chebyshev_3(SizeT n, Number a, Number b) {
Container<Number> points(n);
for (SizeT i = 0; i < n; ++i) {
const Number x = 1 - std::cos(M_PI * static_cast<Number>(2*i) / static_cast<Number>(2*n - 1));
Expand All @@ -137,7 +137,7 @@ namespace alfi::dist {
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> circle_proj_no_first(SizeT n, Number a, Number b) {
Container<Number> chebyshev_4(SizeT n, Number a, Number b) {
Container<Number> points(n);
for (SizeT i = 0; i < n; ++i) {
const Number x = 1 - std::cos(M_PI * static_cast<Number>(2*i + 1) / static_cast<Number>(2*n - 1));
Expand Down Expand Up @@ -166,7 +166,7 @@ namespace alfi::dist {
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> ellipse_proj(SizeT n, Number a, Number b, Number ratio) {
Container<Number> chebyshev_ellipse_2(SizeT n, Number a, Number b, Number ratio) {
Container<Number> points(n);
for (SizeT i = 0; i < n / 2; ++i) {
const Number theta = M_PI * static_cast<Number>(i) / (static_cast<Number>(n) - 1);
Expand All @@ -180,7 +180,7 @@ namespace alfi::dist {
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> ellipse_proj_no_last(SizeT n, Number a, Number b, Number ratio) {
Container<Number> chebyshev_ellipse_3(SizeT n, Number a, Number b, Number ratio) {
Container<Number> points(n);
for (SizeT i = 0; i < n; ++i) {
const Number theta = M_PI * static_cast<Number>(2*i) / static_cast<Number>(2*n - 1);
Expand All @@ -191,7 +191,7 @@ namespace alfi::dist {
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> ellipse_proj_no_first(SizeT n, Number a, Number b, Number ratio) {
Container<Number> chebyshev_ellipse_4(SizeT n, Number a, Number b, Number ratio) {
Container<Number> points(n);
for (SizeT i = 0; i < n; ++i) {
const Number theta = M_PI * static_cast<Number>(2*i + 1) / static_cast<Number>(2*n - 1);
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions ALFI/ALFI/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Number>(j) + 1) * M_PI) / (2 * static_cast<Number>(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<Number>(2*j) * M_PI) / static_cast<Number>(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<Number>(2*j + 1) * M_PI) / static_cast<Number>(2*N - 1) / 2);
if (j == N - 1) {
Expand Down
14 changes: 7 additions & 7 deletions examples/dist_QCustomPlot/dist_QCustomPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class PlotWindow final : public QWidget {
PlotWindow() {
static const VariableParams<int> n_params = {7, 1, 40, 1};

static const VariableParams<double> a_params = {0.0, 0.0, 100.0, 0.01};
static const VariableParams<double> b_params = {1.0, 0.0, 100.0, 0.01};
static const VariableParams<double> a_params = {0.0, -100.0, 100.0, 0.01};
static const VariableParams<double> b_params = {1.0, -100.0, 100.0, 0.01};
static const VariableParams<double> ratio_params = {2.0, 0.0, 4.0, 0.01};
static const VariableParams<double> steepness_params = {8.0, 0.0, 10.0, 0.01};

Expand Down Expand Up @@ -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<std::pair<QString, std::vector<double>>> distributions = {
Expand All @@ -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)},
Expand Down
4 changes: 2 additions & 2 deletions examples/dist_gnuplot/dist_gnuplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
18 changes: 9 additions & 9 deletions examples/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};

Expand Down Expand Up @@ -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;
Expand Down
24 changes: 20 additions & 4 deletions tests/dist/test_dist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/poly/test_imp_lagrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/poly/test_lagrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/poly/test_newton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/spline/test_cubic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data
Submodule test_data updated 2 files
+140 −12 dist/dist.toml
+23 −6 dist/generate.py