from setup import path,abspath
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
plt.figure(figsize=(8,3))
x = np.arange(-5,5,0.2)
x = np.around(x, decimals=6)
a = 1.0/(1+np.exp(-x))
a = np.around(a, decimals=6)
a1 = a*(1-a)
a1 = np.around(a1, decimals=6)
b = np.tanh(x)
b = np.around(b, decimals=6)
b1 = 1-b**2
b1 = np.around(b1, decimals=6)
c = np.exp((-x**2)/2)
c = np.around(c, decimals=6)
c1 = -x*c
c1 = np.around(c1, decimals=6)
d = x
d = np.around(d, decimals=6)
d1 = np.array([1.0]*50)
d1 = np.around(d1, decimals=6)
fig1,ax= plt.subplots(4,2,sharex = True)
ax[0,0].plot(x,a)
ax[0,1].plot(x,a1)
ax[1,0].plot(x,b)
ax[1,1].plot(x,b1)
ax[2,0].plot(x,c)
ax[2,1].plot(x,c1)
ax[3,0].plot(x,d)
ax[3,1].plot(x,d1)
# TODO Add your code here
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(8,3))
x = np.arange(-10,10,0.1)
a = 1.0/(1+np.exp(-x))
b = np.clip(x,a_min=0.,a_max=None)
fig2,ax= plt.subplots(2,1,sharex = True)
ax[0].plot(x,a,c='r')
plt.text(-5.,21.9,r'$y=sigma(x)$',fontsize = 13)
ax[1].plot(x,b,c='g')
plt.text(-3.0,9,r'$y=ReLU(x)$',fontsize = 13)
axis = plt.gca()
axis.xaxis.set_label_text('x',fontsize = 15)
axis.yaxis.set_label_text('y',fontsize = 15)
import matplotlib.pyplot as plt
import pandas as pd
import imageio
import pickle
import io
buf = io.BytesIO()
a = []
fig3 = plt.figure()
data = pd.read_csv(abspath('gdpallyear_color_en.csv'),header=None)
for year in range(1960,2018) :
plt.cla()
gdp = data[data[4]==year].head(10)[::-1]
gdp[3].index=gdp[1].values
ax = gdp[3].plot(kind='barh',color=gdp[5])
ax.set_title(year)
pickle.dump(plt.gca(), buf) #for test
plt.savefig(abspath('gdp.png'))
a.append(imageio.imread(abspath('gdp.png')))
imageio.mimsave(abspath('p3.gif'),a,fps=3)