In [122]:
%matplotlib inline
In [123]:
import numpy as np
import matplotlib.pyplot as plt
import time
In [124]:
def export_plot(plt,filename,format='pdf'):
    """
    Exports the figure into the project folder
    suported formats : eps, jpeg, jpg, pdf, pgf, png, ps, raw, rgba, svg, svgz, tif, tiff.
    """
    formated_filename = "{0}_{1}.{2}".format(time.strftime("%Y%m%d_%H%M%S"), filename, format)
    plt.savefig(formated_filename, format=format)
In [125]:
X = np.linspace(-1,1,150)*(np.pi + 0.5)
In [126]:
def threshold(x):
    y = np.zeros(x.size)
    y[x>0] = 1
    return y

plt.plot([X.min(), X.max()], [0.5, 0.5], 'r-')
plt.plot([0, 0], [-0.2,1.2], 'r-')
plt.ylim([-0.2,1.2])

plt.plot(X, threshold(X), 'b-', linewidth=3)

export_plot(plt, "threshold")
In [127]:
def identity(x):
    return x

plt.plot([X.min(), X.max()], [0, 0], 'r-')
plt.plot([0, 0], [-4,4], 'r-')
plt.ylim([-4,4])

plt.plot(X, identity(X), 'b-', linewidth=3)

export_plot(plt, "identity")
In [128]:
def linear(x,a):
    return x*a

plt.plot([X.min(), X.max()], [0, 0], 'r-')
plt.plot([0, 0], [-4,4], 'r-')
plt.ylim([-4,4])

plt.plot(X, linear(X,2), 'y-', linewidth=3)
plt.plot(X, linear(X,1), 'g-.', linewidth=3)
plt.plot(X, linear(X,0.5), 'b-', linewidth=3)

plt.annotate(r'Increasing $\alpha$', xy=(0.5, 3),  xycoords='data',
                xytext=(45, -120), textcoords='offset points',
                arrowprops=dict(arrowstyle="->",
                                connectionstyle="arc3,rad=-.3")
                )

export_plot(plt, "linear")
In [129]:
def linear_piecewise(x,a):
    y = np.copy(x)*a
    idx = y >= 1
    y[idx] = 1
    idx = y <= 0
    y[idx] = 0
    return y

plt.plot([X.min(), X.max()], [0.5, 0.5], 'r-')
plt.plot([0.25, 0.25], [-0.5,1.5], 'r-')
plt.plot([0.5, 0.5], [-0.5,1.5], 'r-')
plt.plot([1, 1], [-0.5,1.5], 'r-')
plt.ylim([-0.5,1.5])

plt.plot(X, linear_piecewise(X,2), 'y-', linewidth=3)
plt.plot(X, linear_piecewise(X,1), 'g-.', linewidth=3)
plt.plot(X, linear_piecewise(X,0.5), 'b-', linewidth=3)

plt.annotate(r'Increasing $\alpha$', xy=(0.5, 1.2),  xycoords='data',
                xytext=(45, -120), textcoords='offset points',
                arrowprops=dict(arrowstyle="->",
                                connectionstyle="arc3,rad=-.3")
                )

export_plot(plt, "linear_piecewise")
In [130]:
def linear_piecewise_symmetric(x,a):
    y = np.copy(x*a)
    idx = y >= 1
    y[idx] = 1
    idx = y <= -1
    y[idx] = -1
    return y

plt.plot([X.min(), X.max()], [0, 0], 'r-')
plt.plot([0, 0], [-1.5,1.5], 'r-')
plt.ylim([-1.5,1.5])

plt.plot(X, linear_piecewise_symmetric(X,2), 'y-', linewidth=3)
plt.plot(X, linear_piecewise_symmetric(X,1), 'g-.', linewidth=3)
plt.plot(X, linear_piecewise_symmetric(X,0.5), 'b-', linewidth=3)

plt.annotate(r'Increasing $\alpha$', xy=(0.5, 1.2),  xycoords='data',
                xytext=(45, -120), textcoords='offset points',
                arrowprops=dict(arrowstyle="->",
                                connectionstyle="arc3,rad=-.3")
                )

export_plot(plt, "linear_piecewise_symmetric")
In [131]:
def tanh(x):
    return np.tanh(x)

plt.plot([X.min(), X.max()], [0, 0], 'r-')
plt.plot([0, 0], [-1.2,1.2], 'r-')
plt.ylim([-1.2,1.2])

plt.plot(X, tanh(X), 'b-', linewidth=3)

export_plot(plt, "tanh")
In [132]:
def logistic(x,a=1):
    return 1/(1 + np.exp(-x*a))

plt.plot([X.min(), X.max()], [0.5, 0.5], 'r-')
plt.plot([0, 0], [-0.2,1.2], 'r-')
plt.ylim([-0.2,1.2])

plt.plot(X, logistic(X,4), 'y-', linewidth=3)
plt.plot(X, logistic(X,1), 'g-.', linewidth=3)
plt.plot(X, logistic(X,0.25), 'b-', linewidth=3)

plt.annotate(r'Increasing $\alpha$', xy=(0.5, 1),  xycoords='data',
                xytext=(45, -120), textcoords='offset points',
                arrowprops=dict(arrowstyle="->",
                                connectionstyle="arc3,rad=-.3")
                )

export_plot(plt, "logistic")
In [133]:
def gaussian(x,a=1):
    return np.exp(-x*a*x*a)

plt.plot([X.min(), X.max()], [1, 1], 'r-')
plt.plot([0, 0], [-0.2,1.2], 'r-')
plt.ylim([-0.2,1.2])

plt.plot(X, gaussian(X,4), 'y-', linewidth=3)
plt.plot(X, gaussian(X,1), 'g-.', linewidth=3)
plt.plot(X, gaussian(X,0.25), 'b-', linewidth=3)

plt.annotate(r'Increasing $\alpha$', xy=(1,0.2),  xycoords='data',
                xytext=(45, 120), textcoords='offset points',
                arrowprops=dict(arrowstyle="->",
                                connectionstyle="arc3,rad=.3")
                )

export_plot(plt, "gaussian")
In [134]:
def gaussian_symmetric(x,a=1):
    return np.exp(-x*a*x*a)*2-1

plt.plot([X.min(), X.max()], [1, 1], 'r-')
plt.plot([0, 0], [-0.2,1.2], 'r-')
plt.ylim([-0.2,1.2])

plt.plot(X, gaussian_symmetric(X,4), 'y-', linewidth=3)
plt.plot(X, gaussian_symmetric(X,1), 'g-.', linewidth=3)
plt.plot(X, gaussian_symmetric(X,0.25), 'b-', linewidth=3)

plt.annotate(r'Increasing $\alpha$', xy=(1,0.2),  xycoords='data',
                xytext=(45, 120), textcoords='offset points',
                arrowprops=dict(arrowstyle="->",
                                connectionstyle="arc3,rad=.3")
                )

export_plot(plt, "gaussian_symetric")
In [135]:
def elliot(x,a=1):
    return ((x*a)/2)/(1+np.abs(x*a))+0.5

plt.plot([X.min(), X.max()], [0.5, 0.5], 'r-')
plt.plot([0, 0], [-0.2,1.2], 'r-')
plt.ylim([-0.2,1.2])

plt.plot(X, elliot(X,4), 'y-', linewidth=3)
plt.plot(X, elliot(X,1), 'g-.', linewidth=3)
plt.plot(X, elliot(X,0.25), 'b-', linewidth=3)

plt.annotate(r'Increasing $\alpha$', xy=(0.5, 1),  xycoords='data',
                xytext=(45, -120), textcoords='offset points',
                arrowprops=dict(arrowstyle="->",
                                connectionstyle="arc3,rad=-.3")
                )

export_plot(plt, "elliot")
In [136]:
def elliot_symmetric(x,a=1):
    return ((x*a))/(1+np.abs(x*a))

plt.plot([X.min(), X.max()], [0, 0], 'r-')
plt.plot([0, 0], [-1.2,1.2], 'r-')
plt.ylim([-1.2,1.2])

plt.plot(X, elliot_symmetric(X,4), 'y-', linewidth=3)
plt.plot(X, elliot_symmetric(X,1), 'g-.', linewidth=3)
plt.plot(X, elliot_symmetric(X,0.25), 'b-', linewidth=3)

plt.annotate(r'Increasing $\alpha$', xy=(0.5, 1),  xycoords='data',
                xytext=(45, -120), textcoords='offset points',
                arrowprops=dict(arrowstyle="->",
                                connectionstyle="arc3,rad=-.3")
                )

export_plot(plt, "elliot_symmetric")
In [150]:
def sin(x):
    return np.sin(x)

plt.plot([X.min(), X.max()], [0, 0], 'r-')
plt.plot([0, 0], [-1.2,1.2], 'r-')

plt.plot([X.min(), X.max()], [1, 1], 'r-.')
plt.plot([np.pi/2, np.pi/2], [-1.2,1.2], 'r-.')

plt.ylim([-1.2,1.2])

plt.plot(X, sin(X), 'b-', linewidth=3)

export_plot(plt, "sin")
In [148]:
def cos(x):
    return np.cos(x)

plt.plot([X.min(), X.max()], [1, 1], 'r-')
plt.plot([0, 0], [-1.2,1.2], 'r-')

plt.plot([X.min(), X.max()], [0, 0], 'r-.')
plt.plot([np.pi/2, np.pi/2], [-1.2,1.2], 'r-.')

plt.ylim([-1.2,1.2])

plt.plot(X, cos(X), 'b-', linewidth=3)

export_plot(plt, "cos")
In []: