# Variational AutoEncoderΒΆ



# Author: Brigitta Sipocz
#   The figure produced by this code is published in the textbook
#   "Statistics, Data Mining, and Machine Learning in Astronomy" (2019)
#   To report a bug or issue, use the following forum:

import numpy as np
from matplotlib import pyplot as plt
import matplotlib
# ----------------------------------------------------------------------
# This function adjusts matplotlib settings for a uniform feel in the textbook.
# Note that with usetex=True, fonts are rendered with LaTeX.  This may
# result in an error if LaTeX is not installed on your system.  In that case,
# you can set usetex to False.
from astroML.plotting import setup_text_plots
# uselatex need to be False to be able to use bold fonts for text
setup_text_plots(fontsize=12, usetex=False)

matplotlib.rc('font', weight='bold')

fig = plt.figure(figsize=(6, 4), facecolor='w')
ax = fig.add_axes([0, 0, 1, 1],
xticks=[], yticks=[])
plt.box(False)
circ = plt.Circle((1, 1), 2)

# ----------------------------------------------------------------------
# function to draw arrows
'alpha': 0.5}):
theta = np.arctan2(circ2[1] - circ1[1],
circ2[0] - circ1[0])

starting_point = (circ1[0] + rad1 * np.cos(theta),

length = (circ2[0] - circ1[0] - (rad1 + 1.4 * rad2) * np.cos(theta),

ax.arrow(starting_point[0], starting_point[1],
length[0], length[1], **arrow_kwargs)

# function to draw circles
circ = plt.Circle(center, radius, fc='none', lw=1, **kwargs)

x1 = -3.4
x2 = -2
x3 = -0.5
x4 = 0.5
x5 = 2
x6 = 3.5

seq1 = np.linspace(2.5, -2, 4)
seq2 = np.linspace(1.75, -1.5, 3)
seq3 = np.hstack([np.linspace(2.5, 1, 2), np.linspace(-0.5, -2, 2)])
seq4 = np.linspace(1, -0.5, 3)
seq5 = np.linspace(1.75, -1.5, 3)
seq6 = np.linspace(2.5, -2, 4)

# ------------------------------------------------------------
# draw circles
for i, y1 in enumerate(seq1):

for i, y2 in enumerate(seq2):

for i, y3 in enumerate(seq3):
draw_circle(ax, (x3, y3), radius * 0.75)

seq3[0] - seq3[1] + 2 * radius, fc='b', alpha=0.5))
ax.text(x3, (seq3[0] + seq3[1]) / 2, r'$\sigma$', fontsize=12,
ha='center', va='center')

seq3[2] - seq3[3] + 2 * radius, fc='y', alpha=0.5))
ax.text(x3, (seq3[2] + seq3[3]) / 2, r'$\mu$', fontsize=12,
ha='center', va='center')

draw_connecting_arrow(ax, (x3 + radius, (seq3[0] + seq3[1]) / 2), radius * 0.15,
draw_connecting_arrow(ax, (x3 + radius, (seq3[2] + seq3[3]) / 2), radius * 0.15,

for i, y4 in enumerate(seq4):
draw_circle(ax, (x4, y4), radius * 0.75, alpha=0.5)

ax.text(x4, seq4[1], 'Sample', fontsize=12, ha='center',
va='center', rotation=90)

seq4[0] - seq4[2] + 2 * radius, fc='g', alpha=0.5))

for i, y5 in enumerate(seq5):

for i, y6 in enumerate(seq6):

# ------------------------------------------------------------
# draw connecting arrows
for i, y1 in enumerate(seq1):
for j, y2 in enumerate(seq2):

for i, y2 in enumerate(seq2):
for j, y3 in enumerate(seq3):

for i, y4 in enumerate(seq4):
for j, y5 in enumerate(seq5):

for i, y5 in enumerate(seq5):
for j, y6 in enumerate(seq6):

# ------------------------------------------------------------