import matplotlib.pyplot as plt 
import seaborn           as sns
import numpy             as np
from math import *

"""
Explanation: The Sigmoid Function
End of explanation
"""


def sigmoid(t):
    "Returns the sigmoid function S(t)"
    return 1 / (1 + np.exp(-t))

"""
Explanation: The sigmoid function $S:\mathbb{R} \rightarrow [0,1]$ is defined as:
$$ S(t) = \frac{1}{1 + \exp(-t)}. $$
End of explanation
"""


n = 1000
X = np.linspace(-8.0, 8.0, num=n)
Y = sigmoid(X)
plt.figure(figsize=(15, 10))
sns.set(style='darkgrid')
plt.margins(0.02)
plt.plot(X, Y)
plt.axvline(x=0.0, c='k')
plt.axhline(y=0.0, c='k')
plt.xlabel("x")
plt.ylabel("y")
plt.yticks(np.arange(0.0, 1.01, step=0.1))
plt.title("The Sigmoid Function.")

"""
Explanation: Let us plot this function.
End of explanation
"""


def sigmoidPrime(t):
    """
    compute the derivative of the sigmoid function
    """
    return sigmoid(t) * (1 - sigmoid(t))

"""
Explanation: It can be shown that the derivative of the sigmoid function satisfies the equation
$$ \frac{\mathrm{d}S}{\mathrm{d}x}(t) = S(t) \cdot \bigl(1 - S(t)\bigr) $$
End of explanation
"""


def gauss(t):
    "Return the Gauss function with standard deviation sqrt(1/3) * pi"
    s = sqrt(1/3) * pi
    return np.exp(-t*t/(2*s*s)) / sqrt(2 * pi) / s

"""
Explanation: The Gauss function with standard deviation $\sigma$ is defined as
$$ t \mapsto \frac{1}{\sqrt{2\cdot\pi}\cdot\sigma} \cdot \exp\left(-\frac{t^2}{2\cdot \sigma^2}\right)$$
End of explanation
"""


n = 1000
X = np.linspace(-8.0, 8.0, num=n)
Y = sigmoidPrime(X)
G = gauss(X)
Z = np.zeros((n,1))
sns.set(style='darkgrid')
plt.figure(figsize=(15, 10))
plt.margins(0.02)
plt.plot(X, Y, color='b', label='S´(t)')
plt.plot(X, G, color='r', label='G(t)')
plt.axvline(x=0.0, c='k')
plt.axhline(y=0.0, c='k')
plt.xlabel("x")
plt.ylabel("y")
plt.title("The derivative of the sigmoid function.")

"""
Explanation: Let us plot both the derivative of the sigmoid function and the Gauss function with standard deviation $\large\frac{\pi}{\sqrt{3}}$.
End of explanation
"""


