Logistic function (Sigmoid)DescriptionIn the context of artificial neural networks, the Logistic function is an activation function defined as:from matplotlib import pyplot as plt import numpy as np def sigmoid_forward(x): return 1 / (1 + np.exp(-x)) x = np.arange(-7,7) y = sigmoid_forward(x) plt.style.use('fivethirtyeight') fig, ax = plt.subplots() ax.plot(x, y) ax.set_title("Plot of the Logistic function") plt.show() tf.sigmoid( x, name=None )Pytorch form of Logistic function: class torch.nn.Sigmoid Forward propagation EXAMPLE/* ANSI C89, C99, C11 compliance */ /* The following example shows the usage of Logistic function forward propagation. */ #include <stdio.h> #include <math.h> float logistic_forward(float x){ return 1.0f / (1.0f + (float)exp(-x)); } int main() { float r_x, r_y; r_x = 0.1f; r_y = logistic_forward(r_x); printf("Logistic function forward propagation for value x: %f\n", r_y); return 0; } Backward propagation EXAMPLE/* ANSI C89, C99, C11 compliance */ /* The following example shows the usage of Logistic function backward propagation. */ #include <stdio.h> #include <math.h> float logistic_backward(float x){ float r_log = 1.0f / (1.0f + (float)exp(-x)); return r_log * (1.0f - r_log); } int main() { float r_x, r_y; r_x = 0.1f; r_y = logistic_backward(r_x); printf("Logistic function backward propagation for value x: %f\n", r_y); return 0; } REFERENCES: 0. LeCun, Y.; Bottou, L.; Orr, G.; Muller, K. (1998). Orr, G.; Muller, K., eds. Efficient BackProp. |