In [1]:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
%matplotlib inline
In [11]:
import sys
str(sys.version)
Out[11]:
In [5]:
import matplotlib
matplotlib.__version__
Out[5]:
In [3]:
np.__version__
Out[3]:
In [2]:
tf.__version__
Out[2]:
In [2]:
def plot_activation(i=1.0, activation=lambda x: x, session=None):
ws = np.arange(-0.5, 0.5, 0.05)
bs = np.arange(-0.5, 0.5, 0.05)
X, Y = np.meshgrid(ws, bs)
os = np.array([activation(tf.constant(w*i + b)).eval(session=session) for w, b in zip(np.ravel(X), np.ravel(Y))])
Z = os.reshape(X.shape)
fig = plt.figure(figsize=(10, 10), facecolor='white')
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1)
In [3]:
# Start tf session
sess = tf.Session()
In [4]:
plot_activation(2, activation=tf.sigmoid, session=sess)
In [16]:
plot_activation(2.0, activation=tf.tanh, session=sess)
In [12]:
plot_activation(1.0, activation=tf.nn.relu, session=sess)
In [13]:
plot_activation(1.0, activation=tf.nn.elu, session=sess)
In [4]:
# close tensorflow session
sess.close()