In [8]:
import numpy as np
import random
from numpy import linalg as LA
import pylab

# Font
import os.path
import matplotlib
import matplotlib.pyplot as plt
font = {'family': 'IPAexGothic'}
matplotlib.rc('font', **font)
markerSize = 12
fontSize = 22
figureSize = (12, 9)

In [9]:
# PNGとEPSファイルを書き出す
def writePNGandEPS(name):
    plt.savefig("%s/%s.png" % ('../../../images/', name))
    plt.savefig("%s/%s.eps" % ('../../../images/', name))

In [10]:
# シグモイド関数
x = np.arange(-5, 5, 0.1)

pylab.figure(figsize=(18, 9))

plt.subplot(131)
a = 0.5
y = 1 / (1 + np.exp(-a*x))
plt.plot(x,y,'-')
plt.xlabel('x')
plt.ylabel('y')
plt.title('$a=0.5$')
plt.ylim(0, 1)

plt.subplot(132)
a = 1
y = 1 / (1 + np.exp(-a*x))
plt.plot(x,y,'-')
plt.xlabel('x')
plt.ylabel('y')
plt.title('$a=1$')
plt.ylim(0, 1)

plt.subplot(133)
a = 2
y = 1 / (1 + np.exp(-a*x))
plt.plot(x,y,'-')
plt.xlabel('x')
plt.ylabel('y')
plt.title('$a=2$')
plt.ylim(0, 1)

plt.rcParams["font.size"] = fontSize
writePNGandEPS('sigmoid')
plt.show()



In [11]:
# ReLU
x1 = np.arange(-5, 0, 0.1)
y1 = np.zeros(x1.shape)
x2 = np.arange(0, 5, 0.1)
y2 = x2

x = np.concatenate((x1, x2), axis=0)
y = np.concatenate((y1, y2), axis=0)

pylab.figure(figsize=figureSize)
plt.plot(x,y,'-')
plt.xlabel('x')
plt.ylabel('y')
plt.rcParams["font.size"] = fontSize
writePNGandEPS('RELU')
plt.show()