In [1]:
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np

The Gaussian Curve

The gaussian curve resembles a normalized histogram where most of the data is centered arount the mean of the curve and the curve is also called the bell curve or normal curve.

The formula is as follows:-

$$ e^{-{({x-\mu})^2}/({2{\sigma^2}})}{1/\sigma{\sqrt{2\pi}}} $$

In [2]:
sess = tf.InteractiveSession()

mean = 0.0 
sigma = 1.0

x = tf.linspace(-5.0,5.0,100)
z = (tf.exp(tf.neg((tf.pow(x-mean,2.0) /
                   2.0 * tf.pow(sigma , 2.0)))) * (1.0 / sigma*tf.sqrt(tf.multiply(2.0 , 3.1415))))
z


Out[2]:
<tf.Tensor 'mul_2:0' shape=(100,) dtype=float32>

In [3]:
gauss = z.eval()
gauss


Out[3]:
array([  9.34119635e-06,   1.54002664e-05,   2.51316742e-05,
         4.05961291e-05,   6.49106660e-05,   1.02734695e-04,
         1.60948213e-04,   2.49588542e-04,   3.83117091e-04,
         5.82113862e-04,   8.75492638e-04,   1.30336720e-03,
         1.92065537e-03,   2.80156685e-03,   4.04502591e-03,
         5.78110386e-03,   8.17841198e-03,   1.14523834e-02,
         1.58742052e-02,   2.17799470e-02,   2.95794830e-02,
         3.97642739e-02,   5.29132597e-02,   6.96955323e-02,
         9.08687040e-02,   1.17271483e-01,   1.49809524e-01,
         1.89432845e-01,   2.37104595e-01,   2.93760568e-01,
         3.60259980e-01,   4.37328070e-01,   5.25493741e-01,
         6.25023961e-01,   7.35859096e-01,   8.57554078e-01,
         9.89229977e-01,   1.12954068e+00,   1.27666032e+00,
         1.42829430e+00,   1.58171761e+00,   1.73384070e+00,
         1.88130009e+00,   2.02057981e+00,   2.14814067e+00,
         2.26057243e+00,   2.35473943e+00,   2.42793059e+00,
         2.47798419e+00,   2.50339651e+00,   2.50339651e+00,
         2.47798419e+00,   2.42793059e+00,   2.35473967e+00,
         2.26057243e+00,   2.14814138e+00,   2.02057981e+00,
         1.88130081e+00,   1.73384070e+00,   1.58171844e+00,
         1.42829478e+00,   1.27666104e+00,   1.12954104e+00,
         9.89230633e-01,   8.57554376e-01,   7.35859096e-01,
         6.25024259e-01,   5.25493741e-01,   4.37328279e-01,
         3.60259980e-01,   2.93760717e-01,   2.37104595e-01,
         1.89432934e-01,   1.49809524e-01,   1.17271565e-01,
         9.08687040e-02,   6.96956143e-02,   5.29132970e-02,
         3.97643335e-02,   2.95794960e-02,   2.17799786e-02,
         1.58742126e-02,   1.14523834e-02,   8.17840360e-03,
         5.78111224e-03,   4.04502964e-03,   2.80156685e-03,
         1.92065351e-03,   1.30336918e-03,   8.75494210e-04,
         5.82113862e-04,   3.83117091e-04,   2.49589008e-04,
         1.60948504e-04,   1.02734695e-04,   6.49106660e-05,
         4.05960491e-05,   2.51317470e-05,   1.54002664e-05,
         9.34119635e-06], dtype=float32)

In [6]:
plt.plot(gauss)
plt.show()


Two dimensional Gaussian

Gaussian Kernel

We multiply two vectors to get the final matrix


In [13]:
onedsize = z.get_shape().as_list()[0] #here we get the shape for the array of values created
twodz = tf.multiply(tf.reshape(z,[onedsize,1]),tf.reshape(z,[1,onedsize]))
# we multiply z with its transpose to get a n by n matrix

twodz


Out[13]:
<tf.Tensor 'Mul_3:0' shape=(100, 100) dtype=float32>

In [16]:
TDZ = twodz.eval()
TDZ


Out[16]:
array([[  8.72579509e-11,   1.43856912e-10,   2.34759906e-10, ...,
          2.34760572e-10,   1.43856912e-10,   8.72579509e-11],
       [  1.43856912e-10,   2.37168202e-10,   3.87034488e-10, ...,
          3.87035598e-10,   2.37168202e-10,   1.43856912e-10],
       [  2.34759906e-10,   3.87034488e-10,   6.31601049e-10, ...,
          6.31602881e-10,   3.87034488e-10,   2.34759906e-10],
       ..., 
       [  2.34760572e-10,   3.87035598e-10,   6.31602881e-10, ...,
          6.31604713e-10,   3.87035598e-10,   2.34760572e-10],
       [  1.43856912e-10,   2.37168202e-10,   3.87034488e-10, ...,
          3.87035598e-10,   2.37168202e-10,   1.43856912e-10],
       [  8.72579509e-11,   1.43856912e-10,   2.34759906e-10, ...,
          2.34760572e-10,   1.43856912e-10,   8.72579509e-11]], dtype=float32)

In [21]:
plt.plot(TDZ)
plt.show()
plt.imshow(TDZ)
plt.show()



In [ ]: