37 return 1.0 / (1.0 + exp(-z));
41 double sig = sigmoid(z);
42 return sig * (1.0 - sig);
55 std::vector<double> result;
57 for (
double input : inputs) {
58 sum_exp += exp(input);
60 for (
double input : inputs) {
61 result.push_back(exp(input) / sum_exp);
66 std::vector<std::vector<double>>
68 std::vector<std::vector<double>> result(
70 std::vector<double>(inputs.size(), 0.0));
71 std::vector<double> softmax_values = softmax(inputs);
72 for (
size_t i = 0; i < inputs.size(); ++i) {
73 for (
size_t j = 0; j < inputs.size(); ++j) {
75 result[i][j] = softmax_values[i] * (1.0 - softmax_values[i]);
77 result[i][j] = -softmax_values[i] * softmax_values[j];
85 return z >= 0 ? 1 : 0;
93 double tanh_z = std::tanh(z);
94 return 1.0 - tanh_z * tanh_z;
98 return z / (1.0 + exp(-z));
102 double smht_z = smht(z);
103 return smht_z * (1.0 - smht_z);
108 (1.0 + tanh(sqrt(2.0 / M_PI) * (z + 0.044715 * z * z * z)));
113 0.5 * (1.0 + tanh(sqrt(2.0 / M_PI) * (0.044715 * z * z * z + 3 * z)));
114 double pdf = exp(-0.5 * z * z) / sqrt(2.0 * M_PI);
115 return 0.5 * (1.0 + cdf +
116 z * pdf * (1.0 / M_PI) *
117 (0.5 * (1.0 + tanh(sqrt(2.0 / M_PI) *
118 (0.044715 * z * z * z + 3 * z)))) +
119 (1.0 / M_PI) * (1.0 - cdf * cdf));
123 return log(1.0 + exp(z));
127 return z >= 0 ? z : alpha * (exp(z) - 1);
131 return z >= 0 ? 1 : elu(z, alpha) + alpha;
135 return scale * (z >= 0 ? z : alpha * (exp(z) - 1));
140 return scale * (z >= 0 ? 1 : alpha * exp(z));
144 return z >= 0 ? z : alpha * z;
148 return z >= 0 ? 1 : alpha;
152 return z >= 0 ? z : alpha * z;
156 return z >= 0 ? 1 : alpha;
160 return z / (1 + exp(-z));
164 double sig_z = sigmoid(z);
165 return sig_z + (1 - sig_z) * z * sig_z;
std::vector< std::vector< double > > softmax_derivative(const std::vector< double > &inputs)
Computes the derivative of the softmax activation function.
double gelu(double z)
Computes the Gaussian Error Linear Unit (GELU) activation function.
double gelu_derivative(double z)
Computes the derivative of the Gaussian Error Linear Unit (GELU) activation function.
double binary_step(double z)
Computes the binary step activation function.
double sigmoid_derivative(double z)
Computes the derivative of the sigmoid activation function.
double silu_derivative(double z)
Computes the derivative of the Sigmoid Linear Unit (SiLU or Swish) activation function.
double smht_derivative(double z)
Computes the derivative of the Soboleva modified hyperbolic tangent (smht) activation function.
double relu_derivative(double z)
Computes the derivative of the ReLU (Rectified Linear Unit) activation function.
double tanh_derivative(double z)
Computes the derivative of the hyperbolic tangent (tanh) activation function.
double silu(double z)
Computes the Sigmoid Linear Unit (SiLU or Swish) activation function.
double softplus(double z)
Computes the softplus activation function.
double sigmoid(double z)
Computes the sigmoid activation function.
double leaky_relu(double z, double alpha=001)
Computes the Leaky Rectified Linear Unit (Leaky ReLU) activation function.
double leaky_relu_derivative(double z, double alpha=001)
Computes the derivative of the Leaky Rectified Linear Unit (Leaky ReLU) activation function.
double selu(double z, double alpha=167326, double scale=10507)
Computes the Scaled Exponential Linear Unit (SELU) activation function.
double prelu(double z, double alpha)
Computes the Parametric Rectified Linear Unit (PReLU) activation function.
double elu(double z, double alpha=10)
Computes the Exponential Linear Unit (ELU) activation function.
double selu_derivative(double z, double alpha=167326, double scale=10507)
Computes the derivative of the Scaled Exponential Linear Unit (SELU) activation function.
double smht(double z)
Computes the Soboleva modified hyperbolic tangent (smht) activation function.
double tanh(double z)
Computes the hyperbolic tangent (tanh) activation function.
std::vector< double > softmax(const std::vector< double > &inputs)
Computes the softmax activation function.
double relu(double z)
Computes the ReLU (Rectified Linear Unit) activation function.
double elu_derivative(double z, double alpha=10)
Computes the derivative of the Exponential Linear Unit (ELU) activation function.
double prelu_derivative(double z, double alpha)
Computes the derivative of the Parametric Rectified Linear Unit (PReLU) activation function.