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
32 changes: 32 additions & 0 deletions ALFI/ALFI/dist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -154,6 +158,11 @@ namespace alfi::dist {
return points;
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> chebyshev_3_stretched(SizeT n, Number a, Number b) {
return points::stretched<Number,Container>(chebyshev_3(n, a, b), a, b);
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> chebyshev_4(SizeT n, Number a, Number b) {
Container<Number> points(n);
Expand All @@ -164,6 +173,11 @@ namespace alfi::dist {
return points;
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> chebyshev_4_stretched(SizeT n, Number a, Number b) {
return points::stretched<Number,Container>(chebyshev_4(n, a, b), a, b);
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> chebyshev_ellipse(SizeT n, Number a, Number b, Number ratio) {
Container<Number> points(n);
Expand Down Expand Up @@ -224,6 +238,11 @@ namespace alfi::dist {
return points;
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> chebyshev_ellipse_3_stretched(SizeT n, Number a, Number b, Number ratio) {
return points::stretched<Number,Container>(chebyshev_ellipse_3(n, a, b, ratio), a, b);
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> chebyshev_ellipse_4(SizeT n, Number a, Number b, Number ratio) {
Container<Number> points(n);
Expand All @@ -235,6 +254,11 @@ namespace alfi::dist {
return points;
}

template <typename Number = DefaultNumber, template <typename, typename...> class Container = DefaultContainer>
Container<Number> chebyshev_ellipse_4_stretched(SizeT n, Number a, Number b, Number ratio) {
return points::stretched<Number,Container>(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.

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions ALFI/ALFI/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Number>(2*j) * M_PI) / static_cast<Number>(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<Number>(2*j + 1) * M_PI) / static_cast<Number>(2*N - 1) / 2);
if (j == N - 1) {
Expand Down
12 changes: 8 additions & 4 deletions examples/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
};

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions tests/dist/test_dist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data
Submodule test_data updated 2 files
+128 −0 dist/dist.toml
+20 −2 dist/generate.py