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
26 changes: 13 additions & 13 deletions ALFI/ALFI/dist.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace alfi::dist {
CHEBYSHEV_ELLIPSE_STRETCHED,
CIRCLE_PROJECTION,
ELLIPSE_PROJECTION,
SIGMOID,
SIGMOID_STRETCHED,
LOGISTIC,
LOGISTIC_STRETCHED,
ERF,
ERF_STRETCHED,
};
Expand Down Expand Up @@ -95,7 +95,7 @@ namespace alfi::dist {
}

/**
@brief Generates a distribution of \p n points on the interval `(a, b)` using the sigmoid function.
@brief Generates a distribution of \p n points on the interval `(a, b)` using the logistic function.

The following transform function \f(f\f):
\f[
Expand All @@ -118,20 +118,20 @@ namespace alfi::dist {
@return a container with \p n points distributed on the interval `(a, b)` according to the transform function
*/
template <typename Number = DefaultNumber, template <typename> class Container = DefaultContainer>
Container<Number> sigmoid(SizeT n, Number a, Number b, Number steepness) {
Container<Number> logistic(SizeT n, Number a, Number b, Number steepness) {
if (n == 1)
return {(a+b)/2};
Container<Number> points(n);
for (SizeT i = 0; i < n; ++i) {
const Number x = 2 * static_cast<Number>(i) / (static_cast<Number>(n) - 1) - 1;
const Number sigmoidValue = 1 / (1 + exp(-steepness * x));
points[i] = a + (b - a) * sigmoidValue;
const Number logisticValue = 1 / (1 + std::exp(-steepness * x));
points[i] = a + (b - a) * logisticValue;
}
return points;
}

template <typename Number = DefaultNumber, template <typename> class Container = DefaultContainer>
Container<Number> sigmoid_stretched(SizeT n, Number a, Number b, Number steepness) {
Container<Number> logistic_stretched(SizeT n, Number a, Number b, Number steepness) {
if (n == 0)
return {};
if (n == 1)
Expand All @@ -140,8 +140,8 @@ namespace alfi::dist {
const Number stretch_factor = 1 - 2 / (1 + std::exp(steepness));
for (SizeT i = 1; i < n - 1; ++i) {
const Number x = 2 * static_cast<double>(i) / (static_cast<Number>(n) - 1) - 1;
const Number sigmoid = 1 / (1 + std::exp(-steepness * x));
const Number stretched = (sigmoid - 1 / (1 + std::exp(steepness))) / stretch_factor;
const Number logisticValue = 1 / (1 + std::exp(-steepness * x));
const Number stretched = (logisticValue - 1 / (1 + std::exp(steepness))) / stretch_factor;
points[i] = a + (b - a) * stretched;
}
points[0] = a;
Expand Down Expand Up @@ -207,10 +207,10 @@ namespace alfi::dist {
return circle_proj(n, a, b);
case Type::ELLIPSE_PROJECTION:
return ellipse_proj(n, a, b, parameter);
case Type::SIGMOID:
return sigmoid(n, a, b, parameter);
case Type::SIGMOID_STRETCHED:
return sigmoid_stretched(n, a, b, parameter);
case Type::LOGISTIC:
return logistic(n, a, b, parameter);
case Type::LOGISTIC_STRETCHED:
return logistic_stretched(n, a, b, parameter);
case Type::ERF:
return erf(n, a, b, parameter);
case Type::ERF_STRETCHED:
Expand Down
4 changes: 2 additions & 2 deletions examples/dist_QCustomPlot/dist_QCustomPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ class PlotWindow final : public QWidget {
{"Stretched Chebyshev Ellipse", alfi::dist::chebyshev_ellipse_stretched(n, a, b, B)},
{"Circle Projection", alfi::dist::circle_proj(n, a, b)},
{"Ellipse Projection", alfi::dist::ellipse_proj(n, a, b, B)},
{"Sigmoid", alfi::dist::sigmoid(n, a, b, steepness)},
{"Stretched Sigmoid", alfi::dist::sigmoid_stretched(n, a, b, steepness)},
{"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)},
{"Stretched Error function", alfi::dist::erf_stretched(n, a, b, steepness)},
};
Expand Down
6 changes: 3 additions & 3 deletions examples/dist_gnuplot/dist_gnuplot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main() {
const double b = 1;

const double ratio = 2;
const double sigmoid_steepness = 8;
const double logistic_steepness = 8;
const double erf_steepness = 3;

plot_data({
Expand All @@ -73,8 +73,8 @@ int main() {
{"Stretched Chebyshev Ellipse", alfi::dist::chebyshev_ellipse_stretched(n, a, b, ratio)},
{"Circle Projection", alfi::dist::circle_proj(n, a, b)},
{"Ellipse Projection", alfi::dist::ellipse_proj(n, a, b, ratio)},
{"Sigmoid", alfi::dist::sigmoid(n, a, b, sigmoid_steepness)},
{"Stretched Sigmoid", alfi::dist::sigmoid_stretched(n, a, b, sigmoid_steepness)},
{"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)},
{"Stretched Error function", alfi::dist::erf_stretched(n, a, b, erf_steepness)},
});
Expand Down
6 changes: 3 additions & 3 deletions examples/interpolation/interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class PlotWindow final : public QWidget {
PlotWindow() {
static const QStringList distribution_types {
"Uniform", "Chebyshev", "Chebyshev Stretched", "Chebyshev Ellipse", "Chebyshev Ellipse Stretched",
"Circle Projection", "Ellipse Projection", "Sigmoid", "Stretched Sigmoid",
"Circle Projection", "Ellipse Projection", "Logistic", "Stretched Logistic",
"Error Function", "Stretched Error Function"
};

Expand Down Expand Up @@ -268,8 +268,8 @@ class PlotWindow final : public QWidget {
case alfi::dist::Type::CHEBYSHEV_ELLIPSE_STRETCHED: X = alfi::dist::chebyshev_ellipse_stretched(N, a, b, 2.0); break;
case alfi::dist::Type::CIRCLE_PROJECTION: X = alfi::dist::circle_proj(N, a, b); break;
case alfi::dist::Type::ELLIPSE_PROJECTION: X = alfi::dist::ellipse_proj(N, a, b, 2.0); break;
case alfi::dist::Type::SIGMOID: X = alfi::dist::sigmoid(N, a, b, 16.0); break;
case alfi::dist::Type::SIGMOID_STRETCHED: X = alfi::dist::sigmoid_stretched(N, a, b, 16.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;
case alfi::dist::Type::ERF_STRETCHED: X = alfi::dist::erf_stretched(N, a, b, 8.0); break;
default: return;
Expand Down
8 changes: 4 additions & 4 deletions tests/dist/test_dist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ TEST(DistributionsTest, EllipseProjection) {
test_distribution("ellipse_proj", alfi::dist::Type::ELLIPSE_PROJECTION, 1e-14);
}

TEST(DistributionsTest, Sigmoid) {
test_distribution("sigmoid", alfi::dist::Type::SIGMOID, 1e-13);
TEST(DistributionsTest, Logistic) {
test_distribution("logistic", alfi::dist::Type::LOGISTIC, 1e-13);
}

TEST(DistributionsTest, SigmoidStretched) {
test_distribution("sigmoid_stretched", alfi::dist::Type::SIGMOID_STRETCHED, 1e-11);
TEST(DistributionsTest, LogisticStretched) {
test_distribution("logistic_stretched", alfi::dist::Type::LOGISTIC_STRETCHED, 1e-11);
}

TEST(DistributionsTest, Erf) {
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data