4.3.5 ELU & SELU
Last updated
Last updated
#include <stdio.h>
#include <math.h>
double elu(double x, double alpha) {
return x >= 0 ? x : alpha * (exp(x) - 1);
}
double selu(double x, double alpha, double lambda) {
return lambda * (x >= 0 ? x : alpha * (exp(x) - 1));
}
int main() {
// ELU
{
double x = -0.5;
double alpha = 1.0;
double y = elu(x, alpha);
printf("The ELU of %f with alpha=%f is %f\n", x, alpha, y);
}
// SELU
{
double x = -0.5;
double alpha = 1.6732632423543772848170429916717;
double lambda = 1.0507009873554804934193349650124;
double y = selu(x, alpha, lambda);
printf("The SELU of %f with alpha=%f and lambda=%f is %f\n", x, alpha,
lambda, y);
}
return 0;
}The ELU of -0.500000 with alpha=1.000000 is -0.393469
The SELU of -0.500000 with alpha=1.673263 and lambda=1.050701 is -0.428348