In [1]:
import tensorflow_probability as tfp
import tensorflow as tf
import collections


WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.


In [4]:
tfd = tfp.distributions
try:
  tf.compat.v1.enable_eager_execution()
except ValueError:
  pass

import matplotlib.pyplot as plt

In [8]:
normal_dist = tfd.Normal(loc=0,scale=1)

In [13]:
normal_dist.sample(10)


Out[13]:
<tf.Tensor: id=72, shape=(10,), dtype=float32, numpy=
array([ 1.1663766 ,  1.9076914 ,  0.38502967,  0.15422045, -0.2567685 ,
       -1.2692249 , -1.0362905 , -0.30548868,  0.10544258,  1.5178447 ],
      dtype=float32)>

In [19]:
normal_dist.log_prob(0.)


Out[19]:
<tf.Tensor: id=128, shape=(), dtype=float32, numpy=-0.9189385>

In [24]:
data_normal = normal_dist.sample(100)
plt.scatter(range(len(data_normal)),data_normal,color="blue",alpha=0.4)
plt.title("Normal Distribution")
plt.show()



In [25]:
gamma_dist = tfd.Gamma(concentration=3.0,rate=2.0)
data_gamma = gamma_dist.sample(100)

In [26]:
plt.scatter(range(len(data_gamma)),data_gamma,color="blue")
plt.title("Gamma Distribution")
plt.show()



In [49]:
#normal_dist.cdf(100.0),gamma_dist.cdf(value=100.0)
import numpy as np

np.std(data_gamma)
np.std(data_normal)


Out[49]:
0.9455218
Here is an example typesetting mathematics in \LaTeX
\begin{equation*} X(m,n) = \left\{\begin{array}{lr} x(n), & \text{for } 0\leq n\leq 1\\ \frac{x(n-1)}{2}, & \text{for } 0\leq n\leq 1\\ \log_2 \left\lceil n \right\rceil \qquad & \text{for } 0\leq n\leq 1 \end{array}\right\} = xy \end{equation*}