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]:
'3.5.3 |Continuum Analytics, Inc.| (default, Mar  6 2017, 11:58:13) \n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]'

In [5]:
import matplotlib
matplotlib.__version__


Out[5]:
'2.0.0'

In [3]:
np.__version__


Out[3]:
'1.12.1'

In [2]:
tf.__version__


Out[2]:
'1.1.0'

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()

Sigmoid function


In [4]:
plot_activation(2, activation=tf.sigmoid, session=sess)


Hiperbolic tangent


In [16]:
plot_activation(2.0, activation=tf.tanh, session=sess)


Rectified Linear Unit


In [12]:
plot_activation(1.0, activation=tf.nn.relu, session=sess)


Exponential Linear Unit


In [13]:
plot_activation(1.0, activation=tf.nn.elu, session=sess)



In [4]:
# close tensorflow session
sess.close()