diff --git a/Python/Convexity_and_local_extrema.py b/Python/Convexity_and_local_extrema.py new file mode 100644 index 0000000..5ddf895 --- /dev/null +++ b/Python/Convexity_and_local_extrema.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Jan 13 22:56:40 2021 + +@author: Sarat Moka + +Python code for generating 3d-plots of +a convex function with a (unique) global minimum +and a non-convex function with several local extrema. + +""" + +import numpy as np +import matplotlib.pyplot as plt + +textsize = 20 + +#mycmap = plt.get_cmap('gist_earth') +#mycmap = plt.get_cmap('magma') + +# ============================================================================= +# Covex and non-convex functions +# ============================================================================= +f_non_convex = lambda t: 3*((1 - t[0])**2)*np.exp(-t[0]**2 - (t[1] + 1)**2) - 10*(t[0]/5 - t[0]**3 - t[1]**5)*np.exp(-t[0]**2 - t[1]**2) - (1/3)*np.exp(-(t[0]+1)**2 - t[1]**2) +f_convex = lambda t: t[0]**2 + t[1]**2 + + +#%% +# ============================================================================= +# This cell plots a convex function +# ============================================================================= + +t1_range = np.arange(-2.5, 2.5, 0.01) +t2_range = np.arange(-2.5, 2.5, 0.01) + +A = np.meshgrid(t1_range, t2_range) +Z = f_convex(A) +X, Y = np.meshgrid(t1_range, t2_range) + +fig = plt.figure() +ax = plt.axes(projection='3d') +ax.plot_surface(X, Y, Z, rstride=1, cstride=1, linewidth=5, antialiased=False, edgecolor='none', vmin =np.min(Z), vmax =2*np.max(Z)) +#ax.plot_surface(X, Y, Z, linewidth=2, rcount=50, ccount=50, antialiased=False, edgecolor='none', vmin =np.min(Z), vmax =1.5*np.max(Z)) + +ax.view_init(22, -56) +ax.set_xlabel(r'$\theta_1$', fontsize=textsize) +ax.set_ylabel(r'$\theta_2$', fontsize=textsize) +#plt.xticks(size=textsize) +#plt.yticks(size=textsize) +plt.show() + +#%% +# ============================================================================= +# This cell plots a non-convex function +# ============================================================================= + +t1_range = np.arange(-2.5, 2.5, 0.01) +t2_range = np.arange(-2.5, 2.5, 0.01) + +A = np.meshgrid(t1_range, t2_range) +Z = f_non_convex(A) +X, Y = np.meshgrid(t1_range, t2_range) + +fig = plt.figure() +ax = plt.axes(projection='3d') +ax.plot_surface(X, Y, Z, rstride=1, cstride=1, linewidth=5, antialiased=False, edgecolor='none', vmin =np.min(Z), vmax =2*np.max(Z), alpha=1) +ax.view_init(22, -56) +ax.set_xlabel(r'$\theta_1$', fontsize=textsize) +ax.set_ylabel(r'$\theta_2$', fontsize=textsize) +plt.show() \ No newline at end of file diff --git a/Python/Line-search-concepts.py b/Python/Line-search-concepts.py index d1ca60f..ce3f7ce 100644 --- a/Python/Line-search-concepts.py +++ b/Python/Line-search-concepts.py @@ -80,22 +80,43 @@ def GradientDescent(f, grad, t, alpha, niter): for i in range(size): y[i] = line(t, d, alpha[i]) +# plt.plot(alpha, y, '-r') +# #plt.xlabel(r'$\alpha$', fontsize=25, loc='right') +# plt.ylabel(r'$C\left(\theta^{(t)} + \alpha \, \theta_{\mathsf{d}}^{(t)}\right)$', fontsize=20) +# #plt.legend(fontsize=20) +# plt.xlim(0, 0.003) +# plt.ylim(-5, 45) +# plt.rcParams["figure.figsize"] = (10,10) +# ind_min = np.argmin(y) +# ind_min = np.argmin(y) +# alpha_opt = alpha[ind_min] +# plt.plot([alpha_opt, alpha_opt], [-5, y[ind_min]], '-g', linewidth=2) +# plt.text(alpha[ind_min]-0.00005, -11, r'$\alpha^{(t)}$', fontsize=20) +# plt.text(alpha[ind_min]+0.0007, -9, r'$\alpha$', fontsize=20) +# plt.xticks(fontsize=12) +# plt.show() + plt.plot(alpha, y, '-r') -#plt.xlabel(r'$\alpha$', fontsize=25, loc='right') plt.ylabel(r'$C\left(\theta^{(t)} + \alpha \, \theta_{\mathsf{d}}^{(t)}\right)$', fontsize=20) -#plt.legend(fontsize=20) plt.xlim(0, 0.003) plt.ylim(-5, 45) -plt.rcParams["figure.figsize"] = (10,10) -ind_min = np.argmin(y) +plt.rcParams["figure.figsize"] = (10, 10) + +# Mark the minimum point ind_min = np.argmin(y) alpha_opt = alpha[ind_min] plt.plot([alpha_opt, alpha_opt], [-5, y[ind_min]], '-g', linewidth=2) -plt.text(alpha[ind_min]-0.00005, -9, r'$\alpha^{(t)}$', fontsize=20) +plt.text(alpha_opt - 0.00005, -11, r'$\alpha^{(t)}$', fontsize=20) +plt.text(alpha_opt + 0.0007, -9, r'$\alpha$', fontsize=20) + +# Add arrow +arrow_start = (alpha_opt, -9.5) +arrow_end = (alpha_opt, -5) +plt.annotate('', xy=arrow_end, xytext=arrow_start, arrowprops=dict(arrowstyle='->', color='blue', linewidth=2)) + plt.xticks(fontsize=12) plt.show() - #%% # ============================================================================= # Run this cell for contour plot of Rosenbrock function along with the ray diff --git a/Python/Non-convex-landscapes.py b/Python/Non-convex-landscapes.py index f4b2677..0b9467e 100644 --- a/Python/Non-convex-landscapes.py +++ b/Python/Non-convex-landscapes.py @@ -57,8 +57,8 @@ def loss2(w1, w2): w2_min = -20 w2_max = 20 -w1_range = np.arange(w1_min, w1_max, 1) -w2_range = np.arange(w2_min, w2_max, 1) +w1_range = np.arange(w1_min, w1_max, 0.1) +w2_range = np.arange(w2_min, w2_max, 0.1) w1_grid, w2_grid = np.meshgrid(w1_range, w2_range) @@ -72,14 +72,17 @@ def loss2(w1, w2): # ============================================================================= # Plotting the landscape # ============================================================================= -fig = plt.figure() +fig = plt.figure(figsize=(30, 30)) +#fig = plt.figure() ax = plt.axes(projection='3d') #ax.plot_wireframe(t1_arr, t2_arr, cost_arr, color='black') -ax.plot_surface(w1_grid, w2_grid, loss_grid, cmap='Blues_r', linewidth=0, antialiased=False, edgecolor='none', vmin =np.min(loss_grid), vmax =1.5*np.max(loss_grid)) #cmap='Blues_r', +#ax.plot_surface(w1_grid, w2_grid, loss_grid, rstride=1, cstride=1, cmap='Blues_r', linewidth=0, antialiased=False, edgecolor='none', vmin =np.min(loss_grid), vmax =1.5*np.max(loss_grid)) #cmap='Blues_r', +ax.plot_surface(w1_grid, w2_grid, loss_grid, rstride=1, cstride=1, linewidth=0, antialiased=False, edgecolor='none', vmin =np.min(loss_grid), vmax =2*np.max(loss_grid), cmap='Blues_r') + ax.set_xlabel(r'$w1$', fontsize=20) ax.set_yticks(2*np.array([-10, -5, 0, 5, 10])) ax.set_xticks(2*np.array([-10, -5, 0, 5, 10])) ax.set_ylabel(r'$w2$', fontsize=20) ax.set_zlabel(r'$C(\theta)$', fontsize=20) -ax.view_init(25, -120) \ No newline at end of file +ax.view_init(44, -113) \ No newline at end of file diff --git a/Python/loss_landscapes_logistic.py b/Python/loss_landscapes_logistic.py new file mode 100644 index 0000000..65445e5 --- /dev/null +++ b/Python/loss_landscapes_logistic.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Wed Jan 24 19:02:58 2024 + +@author: z3538568 +""" + +import numpy as np +import matplotlib.pyplot as plt + +X = np.array([-3,-2,-1,1,2,3]) +y = np.array([1, 0, 0, 1, 1, 0]) + +def sigmoid(x, w, b): + return 1/(1 + np.exp(b + w*x)) + +def celoss(w, b): + n = y.shape[0] + s = 0.0 + + for i in range(n): + y_hat = sigmoid(X[i], w, b) + s += y[i]*np.log(y_hat) + (1 - y[i])*np.log(1 - y_hat) + + return -s/n + +def loss2(w, b): + n = y.shape[0] + s = 0.0 + for i in range(n): + s += (y[i] - sigmoid(X[i], w, b))**2 + + return s + +w_min = -5 +w_max = 5 +b_min = -10 +b_max = 10 + +w_range = np.arange(w_min, w_max, 0.01) +b_range = np.arange(b_min, b_max, 0.01) + +w_grid, b_grid = np.meshgrid(w_range, b_range) +loss_grid = loss2(w_grid, b_grid) +#loss_grid = celoss(w_grid, b_grid) + +#%% +fig = plt.figure() +ax = plt.axes(projection='3d') + +#ax.plot_wireframe(t1_arr, t2_arr, cost_arr, color='black') +ax.plot_surface(w_grid, b_grid, loss_grid, cmap='Blues_r', rstride=1, cstride=1, linewidth=0, antialiased=False, edgecolor='none', vmin =np.min(loss_grid), vmax =2*np.max(loss_grid)) +ax.set_xlabel(r'$w$', fontsize=20) +ax.set_ylabel(r'$b$', fontsize=20) +ax.set_zlabel(r'$C(\theta)$', fontsize=20) +ax.view_init(25, -120) + diff --git a/README.md b/README.md index 54f13b6..dd8f37e 100644 --- a/README.md +++ b/README.md @@ -1,140 +1,140 @@ # MathematicalEngineeringDeepLearning -Material for The Mathematical Engineering of Deep Learning. See the actual book content on [deeplearningmath.org](https://deeplearningmath.org) or (when it is out) purchase the book from CRC press. +Material for The Mathematical Engineering of Deep Learning. See the actual book content on [deeplearningmath.org](https://deeplearningmath.org) or purchase the book from [CRC Press](https://www.routledge.com/Chapman--HallCRC-Data-Science-Series/book-series/CHDSS) / [Amazon](https://www.amazon.com.au/Mathematical-Engineering-Learning-Chapman-Science-ebook/dp/B0DGW9RW1M/). This repository contains general supporting material for the book. -Below is a detailed list of the source code used for creating figures and tables in the book. We use [Julia](https://julialang.org/), [Python](https://www.python.org/), or [R](https://www.r-project.org/) and the code is sometimes in stand alone files, sometimes in [Jupyter](https://jupyter.org/) notebooks, sometimes as [R Markdown](https://rmarkdown.rstudio.com/), and sometimes in [Google Colab](https://research.google.com/colaboratory/). Many of our static illustrations were created using [TikZ](https://texample.net/tikz/examples/) by [Ajay Hemanth](https://www.linkedin.com/in/ajayhemanth/) and Vishnu Prasath with the [source of their illustrations](https://github.com/ajayhemanth/The-Mathematical-Engineering-of-Deep-Learning---TikZ) also available so you can adapt it for purposes. +Below is a detailed list of the source code used for creating figures and tables in the book. We use [Julia](https://julialang.org/), [Python](https://www.python.org/), or [R](https://www.r-project.org/) and the code is sometimes in stand alone files, sometimes in [Jupyter](https://jupyter.org/) notebooks, sometimes as [R Markdown](https://rmarkdown.rstudio.com/), and sometimes in [Google Colab](https://research.google.com/colaboratory/). Many of our static illustrations were created using [TikZ](https://texample.net/tikz/examples/) by [Ajay Hemanth](https://www.linkedin.com/in/ajayhemanth/) and Vishnu Prasath. The TikZ source files are in the [`tikz/`](tikz/) directory of this repository. ### Chapter 1 | Figure | Topic | Source Code | | ------- | ----------- | ----------- | -| 1.1 | Fast.ai example | [Python Google Colab](https://colab.research.google.com/drive/1YOjnlAqY71PspLn0QzoYl5SmcEmXr4GP?usp=sharing) | -| 1.3 | Architectures | [TikZ(a)](), [TikZ(b)](), [TikZ(c)](), [TikZ(d)](), [TikZ(e)](), [TikZ(f)](), [TikZ(g)](), [TikZ(h)]() | -| 1.4 | Neurons | [TikZ(b)](), [TikZ(d)]() | -| 1.5 | Data on earth | [Julia](Julia/data_world_in_zb.ipynb) | +| 1.1 | Fast.ai example | [Python Google Colab](https://colab.research.google.com/drive/1YOjnlAqY71PspLn0QzoYl5SmcEmXr4GP?usp=sharing) | +| 1.3 | Architectures | [TikZ(a)](tikz/figure1-3-a-in_out_neural_network.tex), [TikZ(c)](tikz/figure1-3-c-conv-nn-simple.tex), [TikZ(d)](tikz/figure1-3-d-recursive_graph.tex) | +| 1.4 | Neurons | [TikZ(b)](tikz/figure1-4-b-dendrites_with_synaptic_weights_axons.tex) | +| 1.5 | Data on earth | [Julia](Julia/world_data.ipynb) | ### Chapter 2 | Figure | Topic | Source Code | | ------ | --------------- | ----------- | -| 2.1 | Supervised Learning | [TikZ]() | -| 2.2 | Unsupervised Learning | [TikZ]() | -| 2.3 | Simple regression | [R](R/Simple_Regression.R) | -| 2.4 | Breast Cancer ROC curves | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/Breast_Cancer_ROC_curves.R) | -| 2.5 | Least Squares | [TikZ]() | -| 2.6 | Loss functions | [Julia](Julia/LossFunctions.ipynb) | -| Table 2.1 | Linear MNIST classification | [Julia](Julia/LinearMNIST_3_ways.ipynb) | -| 2.7 | Gradient Descent Learning Rate | [Python](Python/Learning-Rate-Matters-GD-linear.ipynb) | -| 2.8 | Loss Landscape | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/Loss_Landscape.R) | -| 2.9 | Generalization and Training | [TikZ]() or [Julia](Julia/Expected_Performance_Curves.ipynb) | -| 2.10 | Polynomial fit | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/Polynomial_fit.R) | -| 2.11 | K-fold cross validation | [TikZ]() | -| 2.12 | K-means clustering | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/kmeans-clustering.R) | -| 2.13 | K-means image segmentation | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/K-means-image-segmentation.R) | -| 2.14 | Breast Cancer PCA | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/Breast_Cancer_PCA.R) | -| 2.15 | SVD Compression | [Julia](Julia/SVD_compression.ipynb) | +| 2.1 | Supervised Learning | [TikZ](tikz/figure2-1-training_prediction.tex) | +| 2.2 | Unsupervised Learning | [TikZ](tikz/figure2-2-clustering_reduction.tex) | +| 2.3 | Simple regression | [R](R/Simple_Regression.R) | +| 2.4 | Breast Cancer ROC curves | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/Breast_Cancer_ROC_curves.R) | +| 2.5 | Least Squares | [TikZ](tikz/figure2-5-plot_sum_squares.tex) | +| 2.6 | Loss functions | [Julia](Julia/plots_env/LossFunctions.ipynb) | +| Table 2.1 | Linear MNIST classification | [Julia](Julia/MNIST_5_ways.ipynb) | +| 2.7 | Gradient Descent Learning Rate | [Python](Python/Learning-Rate-Matters-GD-linear.ipynb) | +| 2.8 | Loss Landscape | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/Loss_Landscape.R) | +| 2.9 | Generalization and Training | [TikZ](tikz/figure2-9-error_modelcomplexity.tex) or [Julia](Julia/plots_env/Expected_Performance_Curves.ipynb) | +| 2.10 | Polynomial fit | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/Polynomial_fit.R) | +| 2.11 | K-fold cross validation | [TikZ](tikz/figure2-11-kfold_cross_validation.tex) | +| 2.12 | K-means clustering | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/kmeans-clustering.R) | +| 2.13 | K-means image segmentation | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/K-means-image-segmentation.R) | +| 2.14 | Breast Cancer PCA | [R](https://github.com/yoninazarathy/MathematicalEngineeringDeepLearning/blob/master/R/Breast_Cancer_PCA.R) | +| 2.15 | SVD Compression | [Julia](Julia/plots_env/SVD_compression.ipynb) | ### Chapter 3 | Figure | Topic | Source Code | | ------ | --------------- | ----------- | -| 3.1 and 3.2 | Logistic regression model curves and boundary | [R](R/R-code-logistic-smooth-link.R) | -| 3.3 | Components of an artificial neuron | [TikZ]() | -| 3.4 | Loss landscape of MSE vs. CE on logistic regression | [Python]() | +| 3.1 and 3.2 | Logistic regression model curves and boundary | [R](R/R-code-logistic-smooth-link.R) | +| 3.3 | Components of an artificial neuron | [TikZ](tikz/figure3-3-logistic_architecture.tex) | +| 3.4 | Loss landscape of MSE vs. CE on logistic regression | [Python](Python/loss_landscapes_logistic.py) | | 3.5 | Evolution of gradient descent learning in logistic regression | [R(a,b) First file](R/Gradient_Descent_logistic.R), [R(a,b) Second file](R/Function-for-Gradient-Descent-Logistic.R) | -| 3.6 | Shallow multi-output neural network with softmax | [TikZ]() | +| 3.6 | Shallow multi-output neural network with softmax | [TikZ](tikz/figure3-6-softmax_layer.tex) | | 3.7 | Multinomial regression for classification | [R](R/Figure-softmax-boundary-4-classes.R) | -| Table 3.1 | Different approaches for creating an MNIST digit classifier. | [Julia]() | +| Table 3.1 | Different approaches for creating an MNIST digit classifier. | [Julia](Julia/MNIST_5_ways.ipynb) | | 3.8 | Feature engineering in simple logistic regression | [R](R/R-code-logistic-beyond-linearity.R) | | 3.9 | Non-linear classification decision boundaries with feature engineering in logistic regression | [R](R/R-code-Figure-versatile-Boundaries.R) | | 3.10 | Non-linear classification decision boundaries with feature engineering in multinomial regression | [R](R/Figure-softmax-boundary-4-classes.R) same as 3.7 | -| 3.11 | Single hidden layer autoencoder | [TikZ]() | -| 3.12 | Autoencoder projections of MNIST including using PCA | [R](R/R-code-section-autoencoder.R) [TikZ]() | -| 3.13 | Manifolds and autoencoders | [R](R/simple-autoencoder-experiment.R) [TikZ]() | +| 3.11 | Single hidden layer autoencoder | [TikZ](tikz/figure3-11-bottleneck_autoencoder.tex) | +| 3.12 | Autoencoder projections of MNIST including using PCA | [R](R/R-code-section-autoencoder.R) [TikZ](tikz/figure3-12-autoencoder_reconstruction.tex) | +| 3.13 | Manifolds and autoencoders | [R](R/simple-autoencoder-experiment.R) [TikZ](tikz/figure3-13-pca-ae-manifolds.tex) | | 3.14 | MNIST using autoencoders | [R](R/R-code-section-autoencoder.R) same as 3.12 | -| 3.15 | Denoising autoencoder | [TikZ]() | -| 3.16 | Interpolations with autoencoders | [R](R/R-code-section-autoencoder.R) same as 3.12, [Julia]() | +| 3.15 | Denoising autoencoder | [TikZ](tikz/figure3-15-reconstructing_input.tex) | +| 3.16 | Interpolations with autoencoders | [R](R/R-code-section-autoencoder.R) same as 3.12, [TikZ](tikz/figure3-16_interpolation.tex) | ### Chapter 4 | Figure | Topic | Source Code | | ------ | --------------- | ----------- | -| 4.1 | Convexity and local/global extrema | [Python]() | -| 4.2 | Gradient descent with fixed or time dependent learning rate | [Python]() | -| 4.3 | Stochastic gradient descent | [Python]() | -| 4.4 | Early stopping in deep learning | [Julia]() | -| 4.5 | Non-convex loss landscapes | [Python]() | -| 4.6 | Momentum enhancing gradient descent | [Python]() | -| 4.7 | The computational graph for automatic differentiation | [TikZ]() | -| 4.8 | Line search concepts | [Python]() | -| 4.9 | The zig-zagging property of line search | [Python]() | -| 4.10 | Newton's method in one dimension | [Python]() | +| 4.1 | Convexity and local/global extrema | [Python](Python/Convexity_and_local_extrema.py) | +| 4.2 | Gradient descent with fixed or time dependent learning rate | [Python](Python/GD-with-timde-dependent-alpha.py) | +| 4.3 | Stochastic gradient descent | [Python](Python/Stochastic-gradient-descent.py) | +| 4.4 | Early stopping in deep learning | [Julia](Julia/MNIST_train.ipynb) | +| 4.5 | Non-convex loss landscapes | [Python](Python/Momentum-enhanced-GD.py) | +| 4.6 | Momentum enhancing gradient descent | [Python](Python/Non-convex-landscapes.py) | +| 4.7 | The computational graph for automatic differentiation | [TikZ](tikz/figure4-7-computational_graph.tex) | +| 4.8 | Line search concepts | [Python](Python/Line-search-concepts.py) | +| 4.9 | The zig-zagging property of line search | [Python](Python/The-zig-zagging-of-exact-line-search.py) | +| 4.10 | Newton's method in one dimension | [Python](Python/Newton-method-in-one-dimension.py) | ### Chapter 5 | Figure | Topic | Source Code | | ------ | --------------- | ----------- | -| 5.1 | Fully Connected Feedforward Neural Networks | [TikZ(a)](), [TikZ(b)]() | -| 5.2 | Arbitrary function approximation with neural nets | [TikZ(a)](), [Julia(b,c)]() | +| 5.1 | Fully Connected Feedforward Neural Networks | [TikZ(a)](tikz/figure5-1-a-one_hidden_layer.tex), [TikZ(b)](tikz/figure5-1-b-deep_neural_network.tex) | +| 5.2 | Arbitrary function approximation with neural nets | [TikZ(a)](tikz/figure5-2-a-realvalue_function_approximation.tex), [Julia(b,c)](Julia/FunctionApprox.ipynb) | | 5.3 | Binary classification with increasing depth | [R](R/Figure_expressivity.R) | -| 5.4 | A continuous multiplication gate with 4 hidden units | [TikZ]() | -| 5.5 | A deep model with 10 layers | [TikZ]() | -| 5.6 | Several common scalar activation functions | [Julia(a,b)]() | -| 5.7 | Flow of information in general back propagation | [TikZ]() | -| 5.8 | Simple neural network hypothetical example | [TikZ]() | -| 5.9 | Flow of information in standard neural network back propagation | [TikZ]() | -| 5.10 | Computational graph for batch normalization | [TikZ]() | -| 5.11 | The effect of dropout | [TikZ]() | +| 5.4 | A continuous multiplication gate with 4 hidden units | [TikZ](tikz/figure5-4-multiplication_gate.tex) | +| 5.5 | A deep model with 10 layers | [TikZ](tikz/figure5-5-deep_polynomial_model.tex) | +| 5.6 | Several common scalar activation functions | [Julia(a,b)](Julia/plots_env/ActivationPlots.ipynb) | +| 5.7 | Flow of information in general back propagation | [TikZ](tikz/figure5-7-initial_gradient_values.tex) | +| 5.8 | Simple neural network hypothetical example | [TikZ](tikz/figure5-8-scalar_hidden_units.tex) | +| 5.9 | Flow of information in standard neural network back propagation | [TikZ](tikz/figure5-9-advanced_gradient_values.tex) | +| 5.10 | Computational graph for batch normalization | [TikZ](tikz/figure5-10-batch_norm_comp_graph.tex) | +| 5.11 | The effect of dropout | [TikZ](tikz/figure5-11-dropout.tex) | ### Chapter 6 | Figure | Topic | Source Code | | ------ | --------------- | ----------- | -| 6.2 | VGG19 architecture | [TikZ]() | -| 6.3 | Convolutions | [TikZ(a)](), [TikZ(b)]() | -| 6.6 | Convolution padding | [TikZ]() | -| 6.7 | Convolution stride | [TikZ]() | -| 6.8 | Convolution dilation | [TikZ]() | -| 6.9 | Convolution input channels | [TikZ]() | -| 6.10 | Convolution output channels | [TikZ]() | -| 6.11 | Pooling | [TikZ(a)](), [TikZ(b)]() | -| 6.13 | Inception module | [TikZ]() | -| 6.14 | Resnets | [TikZ]() | -| 6.17 | Siamese network | [TikZ]() | +| 6.2 | VGG19 architecture | [TikZ](tikz/figure6-2-vgg19.tex) | +| 6.3 | Convolutions | [TikZ(a)](tikz/figure6-3-a-convolution.tex), [TikZ(b)](tikz/figure6-3-b-element-of-convolution.tex) | +| 6.6 | Convolution padding | [TikZ](tikz/figure6-6-padding.tex) | +| 6.7 | Convolution stride | [TikZ](tikz/figure6-7-stride.tex) | +| 6.8 | Convolution dilation | [TikZ](tikz/figure6-8-dilation.tex) | +| 6.9 | Convolution input channels | [TikZ](tikz/figure6-9-input-channels.tex) | +| 6.10 | Convolution output channels | [TikZ](tikz/figure6-10-output-channels.tex) | +| 6.11 | Pooling | [TikZ(a)](tikz/figure6-11-a-max-pooling.tex), [TikZ(b)](tikz/figure6-11-b-average-pooling.tex) | +| 6.13 | Inception module | [TikZ](tikz/figure6-13-inception-module.tex) | +| 6.14 | Resnets | [TikZ](tikz/figure6-14-resnet.tex) | +| 6.17 | Siamese network | TikZ — not yet available | -### Chapter 7 +### Chapter 7 | Figure | Topic | Source Code | | ------ | --------------- | ----------- | -| 7.1 | Sequence RNN tasks | [TikZ(a)](), [TikZ(b)](), [TikZ(c)](), [TikZ(d)]() | -| 7.2 | Sequence RNN input output paradigms | [TikZ(a)](), [TikZ(b)](), [TikZ(c)](), [TikZ(d)]() | -| 7.3 | RNN recursive graph and unfolded graph | [TikZ]() | -| 7.4 | RNN unit | [TikZ]() | -| 7.5 | RNN language prediction training | [TikZ]() | -| 7.6 | Backpropagation through time | [TikZ]() | -| 7.7 | Alternative RNN configurations | [TikZ(a)](), [TikZ(b)]() | -| 7.8 | LSTM and GRU | [TikZ(a)](), [TikZ(b)]() | -| 7.9 | Encoder decoder architectures | [TikZ(a)](), [TikZ(b)]() | -| 7.10 | Encoder decoder with attention | [TikZ]() | -| 7.11 | Attention weights | [TikZ]() | -| 7.12 | Flow of information with self attention | [TikZ]() | -| 7.13 | Multi-head self attention | [TikZ]() | -| 7.14 | Positional embedding | [Julia(a,b)]() | -| 7.15 | Transformer blocks | [TikZ(a)](), [TikZ(b)]() | -| 7.16 | Transformer encoder decoder architecture | [TikZ]() | -| 7.17 | Transfomer auto-regressive application | [TikZ]() | +| 7.1 | Sequence RNN tasks | [TikZ(a)](tikz/figure7-1-a-look-ahead-prediction.tex), [TikZ(b)](tikz/figure7-1-b-recurrent-sentiment.tex), [TikZ(c)](tikz/figure7-1-c-basic-encoder-decoder.tex), [TikZ(d)](tikz/figure7-1-d-image-to-text.tex) | +| 7.2 | Sequence RNN input output paradigms | [TikZ(a)](tikz/figure7-2-a-one-to-many.tex), [TikZ(b)](tikz/figure7-2-b-many-to-one.tex), [TikZ(c)](tikz/figure7-2-c-many-to-many-1.tex), [TikZ(d)](tikz/figure7-2-d-many-to-many-2.tex) | +| 7.3 | RNN recursive graph and unfolded graph | [TikZ](tikz/figure7-3-unrolling-rnn.tex) | +| 7.4 | RNN unit | [TikZ](tikz/figure7-4-rnn-unit.tex) | +| 7.5 | RNN language prediction training | [TikZ](tikz/figure7-5-rnn-simple-example.tex) | +| 7.6 | Backpropagation through time | [TikZ](tikz/figure7-6-back-prop-through-time.tex) | +| 7.7 | Alternative RNN configurations | [TikZ(a)](tikz/figure7-7-a-bidirectional-rnn.tex), [TikZ(b)](tikz/figure7-7-b-stacked-rnn.tex) | +| 7.8 | LSTM and GRU | [TikZ(a)](tikz/figure7-8-a-lstm.tex), [TikZ(b)](tikz/figure7-8-b-gru.tex) | +| 7.9 | Encoder decoder architectures | [TikZ(a)](tikz/figure7-9-a-encoder-decoder-basic.tex), [TikZ(b)](tikz/figure7-9-b-encoder-decoer-enriched.tex) | +| 7.10 | Encoder decoder with attention | [TikZ](tikz/figure7-10-encoder-decoder-attention.tex) | +| 7.11 | Attention weights | [TikZ](tikz/figure7-11-attention-matrix.tex) | +| 7.12 | Flow of information with self attention | [TikZ](tikz/figure7-12-self-attention.tex) | +| 7.13 | Multi-head self attention | [TikZ](tikz/figure7-13-Multi-head-self-attention.tex) | +| 7.14 | Positional embedding | [Julia(a,b)](Julia/plots_env/positional.ipynb) | +| 7.15 | Transformer blocks | [TikZ(a)](tikz/figure7-15-a-transformer-block.tex), [TikZ(b)](tikz/figure7-15-b-transformer-decoder-block.tex) | +| 7.16 | Transformer encoder decoder architecture | [TikZ](tikz/figure7-16-transformer-encoder-decoder.tex) | +| 7.17 | Transfomer auto-regressive application | [TikZ](tikz/figure7-17-transformer-encoder-decoder-unrolling.tex) | ### Chapter 8 | Figure | Topic | Source Code | | ------ | --------------- | ----------- | -| 8.1 | Generative modelling | [TikZ]() | -| 8.2 | Variational autoencoder | [TikZ]() | -| 8.4 | Diffusion encoder and decoder | [TikZ]() | -| 8.6 | GAN architectures | [TikZ]() | -| 8.7 | Separation of GAN distributions | [TikZ]() | -| 8.8 | Wasserstein distance | [TikZ]() | -| 8.9 | Reinforcement learning | [TikZ]() | -| Equation (8.72) | An MDP optimal policy | [Julia]() | -| 8.10 | Applications of GNN | [TikZ(a)](), [TikZ(b)](), [TikZ(c)]() | -| 8.11 | Directed and undirected graphs | [TikZ(a)](), [TikZ(b)]() | -| 8.12 | Transductive inductive learning | [TikZ(a)](), [TikZ(b)]() | -| 8.13 | Types of GNN tasks | [TikZ(a)](), [TikZ(b)](), [TikZ(c)]() | -| 8.14 | Aggregation in message passing | [TikZ(a)](), [TikZ(b)]() | \ No newline at end of file +| 8.1 | Generative modelling | [TikZ](tikz/figure8-1-general-generative-diff-gan.tex) | +| 8.2 | Variational autoencoder | [TikZ](tikz/figure8-2-vae-encoder-decoder.tex) | +| 8.4 | Diffusion encoder and decoder | [TikZ](tikz/figure8-4-markovian-vae-latent-steps.tex) | +| 8.6 | GAN architectures | [TikZ](tikz/figure8-6-GAN-architecture.tex) | +| 8.7 | Separation of GAN distributions | [TikZ](tikz/figure8-7-GAN-Generator-Distributions-Signal.tex) | +| 8.8 | Wasserstein distance | [TikZ](tikz/figure8-8-DIFFERENT-LATEX-COMPILER-wgan-joint-distribution.tex) | +| 8.9 | Reinforcement learning | [TikZ](tikz/figure8-9-RL-agent-envior.tex) | +| Equation (8.72) | An MDP optimal policy | Julia — not yet available | +| 8.10 | Applications of GNN | [TikZ(a)](tikz/figure8-10-a-social-networks-data.tex), [TikZ(b)](tikz/figure8-10-b-knowledge-graphs-data.tex), [TikZ(c)](tikz/figure8-10-c-molecules.tex) | +| 8.11 | Directed and undirected graphs | [TikZ(a)](tikz/figure8-11-a-undirected-graphs.tex), [TikZ(b)](tikz/figure8-11-b-directed-graphs.tex) | +| 8.12 | Transductive inductive learning | [TikZ(a)](tikz/figure8-12-a-big-graph-for-transductive-learning.tex), [TikZ(b)](tikz/figure8-12-b-several-small-graphs-for-inductive-learning.tex) | +| 8.13 | Types of GNN tasks | TikZ(a), TikZ(b), TikZ(c) — not yet available | +| 8.14 | Aggregation in message passing | [TikZ(a)](tikz/figure8-14-a-message-passing-input-graph.tex), TikZ(b) — not yet available | diff --git a/tikz/figure1-3-a-in_out_neural_network.tex b/tikz/figure1-3-a-in_out_neural_network.tex new file mode 100644 index 0000000..b8e04d6 --- /dev/null +++ b/tikz/figure1-3-a-in_out_neural_network.tex @@ -0,0 +1,89 @@ +\documentclass[border = 0.2cm]{standalone} + +% Required package +\usepackage{tikz} +\usepackage{medl_colors} +\begin {document} + +% Input layer neurons'number +\newcommand{\inputnum}{8} + +% Hidden layer neurons'number +\newcommand{\hiddennum}{9} + +% Total Hidden layers +\newcommand{\hiddenlayers}{3} + +% Output layer neurons'number +\newcommand{\outputnum}{4} + +\begin{tikzpicture} + +% Input Layer +\foreach \i in {1,...,\inputnum} +{ + \node[greenshape, circle, draw, minimum size = 6mm] (Input-\i) at (0,-\i) {}; +} + +\node[above of=Input-1, node distance=1cm] (AInputLayer) {{\Huge Input layer}}; + +% Hidden Layer +\foreach \i in {1,...,\hiddenlayers} +{ + \foreach \j in {1,...,\hiddennum} + { + \node[blueshape, circle, draw, minimum size = 6mm, yshift=(\hiddennum-\inputnum)*5 mm ] (Hidden-\i\j) at (5*\i,-\j) {}; + } + \node[above of=Hidden-\i1, node distance=1cm] (AHiddenLayer\i) {{\Huge Layer \i}}; +} + +% Output Layer +\foreach \i in {1,...,\outputnum} +{ + \node[redshape, circle, draw, minimum size = 6mm, yshift=(\outputnum-\inputnum) * 5mm ] (Output-\i) at (20,-\i) {}; +} + +\node[above of=Output-1, node distance=1.4cm] (AOutputLayer) {{\Huge Output layer}}; + +% Connect neurons In-Hidden +\foreach \i in {1,...,\inputnum} +{ + \foreach \j in {1,...,\hiddennum} + { + \draw[line] (Input-\i) -- (Hidden-1\j); + } +} + +%\foreach \x[evaluate=\x as \evalx using int(\x+1)] + +% Connect neurons between hidden layers +\foreach \i [evaluate=\i as \in using int(\i+1) ] in {1,2} +{ + \foreach \j in {1,...,\hiddennum} + { + \foreach \k in {1,...,\hiddennum} + { + \draw[line] (Hidden-\i\j) -- (Hidden-\in\k); + } + } +} + +% Connect neurons Hidden-Out +\foreach \i in {1,...,\hiddennum} +{ + \foreach \j in {1,...,\outputnum} + { + \draw[line] (Hidden-\hiddenlayers\i) -- (Output-\j); + } +} + +% Outputs +\foreach \i in {1,...,\outputnum} +{ + \draw[-Triangle, thickline, shorten <=1pt] (Output-\i) -- ++(1,0) + node[right]{}; +} + +\end{tikzpicture} + +\end {document} \ No newline at end of file diff --git a/tikz/figure1-3-c-conv-nn-simple.tex b/tikz/figure1-3-c-conv-nn-simple.tex new file mode 100644 index 0000000..ad2a41f --- /dev/null +++ b/tikz/figure1-3-c-conv-nn-simple.tex @@ -0,0 +1,152 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{graphicx} +\usepackage{color} +\usepackage{tikz} +\usepackage{geometry} +\usepackage{medl_colors} +\usetikzlibrary{calc} + +% Use sans everywhere, first line for sans text and second two for sans math +\renewcommand{\familydefault}{\sfdefault} +\usepackage{sansmath} +\sansmath + +\usetikzlibrary{arrows.meta,calc,positioning,shapes.arrows,3d} +\graphicspath{ {./images/} } + +\begin{document} + + %\noindent\resizebox{\textwidth}{!}{ + \begin{tikzpicture}[ + Arrow/.style = {single arrow,draw, + minimum height=8mm, + minimum width=2mm, + rotate=0}] + % can also specify z axis slope eg [scale=.8, z={(-.707,-.3)}] + %\draw[use as bounding box, transparent] (-1.8,-1.8) rectangle (17.2, 3.2); + + \newcommand{\networkLayer}[5]{ + \def\q{0.02} %parameter for filling + + \def\s{#1} % Size of square + \def\x{#2} % X distance + \def\y{#3} % Y distance + \def\z{#4} % Z distance + + % NOTE: X axis passes through centre of default square (if Y and Z are both zero) + % Construct clockwise from bottom back + \coordinate (A) at (\x,-\s/2+\q/2+\y,-\s/2+\q+\z); + \coordinate (B) at (\x,-\s/2+\q/2+\y,\s/2-\q+\z); + \coordinate (C) at (\x,\s/2-\q/2+\y,\s/2-\q+\z); + \coordinate (D) at (\x,\s/2-\q/2+\y,-\s/2+\q+\z); + + \filldraw[#5] (A) -- (B) -- (C) -- (D); % Fill before draw edges + + \draw[line width=0.3mm, fill-blue] (A) -- (B); % Bottom line + \draw[line width=0.3mm, fill-blue] (B) -- (C); % Vertical front + \draw[line width=0.3mm, fill-blue] (C) -- (D); % Top line + \draw[line width=0.3mm, fill-blue] (D) -- (A); % Vertical back + + } + + \newcommand{\pyramid}[6]{ + \def\q{0.02} %parameter for filling + + \def\s{#1} % Size of square + \def\x{#2} % X distance + \def\y{#3} % Y distance + \def\z{#4} % Z distance + + % NOTE: X axis passes through centre of default square (if Y and Z are both zero) + % Construct clockwise from bottom back + \coordinate (A) at (\x,-\s/2+\q/2+\y,-\s/2+\q+\z); + \coordinate (B) at (\x,-\s/2+\q/2+\y,\s/2-\q+\z); + \coordinate (C) at (\x,\s/2-\q/2+\y,\s/2-\q+\z); + \coordinate (D) at (\x,\s/2-\q/2+\y,-\s/2+\q+\z); + + % Use 'fill=none' if needed + %\filldraw[#5] (A) -- (B) -- (C) -- (D); % Fill before draw edges + + \draw[line width=0.2mm, color=border-red] (A) -- (B); % Bottom line + \draw[line width=0.2mm, color=border-red] (B) -- (C); % Vertical front + \draw[line width=0.2mm, color=border-red] (C) -- (D); % Top line + \draw[line width=0.2mm, color=border-red] (D) -- (A); % Vertical back + + \def\d{#6} % Distance to point of pyramid + \coordinate (E) at (\x+\d,\y,\z); + \draw[line width=0.2mm, color=border-red] (A) -- (E); % + \draw[line width=0.2mm, color=border-red] (B) -- (E); % + \draw[line width=0.2mm, color=border-red] (C) -- (E); % + \draw[line width=0.2mm, color=border-red] (D) -- (E); % + + } + + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + % INPUT + % \networkLayer{6.0}{0}{0}{0}{color=gray!80}; + \node[canvas is zy plane at x=0,draw,fill=white] at (0,0) {\includegraphics[scale=.14]{images/bird.jpeg}}; + + \pyramid{1.28}{0}{1.79}{1.43}{color=blue!50, opacity=0.5}{4}; + + % First convolutional layer + \foreach \i in {0,...,5} + \networkLayer{5}{4+\i*2/10}{0}{0}{color=fill-light-blue}; + + \pyramid{0.5}{5.4}{1}{1}{color=gray!10}{3}; % Last arument is depth to point + + + % First maxpool layer + \foreach \i in {0,...,7} + \networkLayer{3}{8.4+\i*2/10}{0}{0}{color=fill-light-blue}; + + \pyramid{0.8}{9.8}{1}{0.8}{color=gray!10}{3}; + + + % Second convolutional layer + \foreach \i in {0,...,11} + \networkLayer{2.5}{12.8+\i*2/10}{0}{0}{color=fill-light-blue}; + + \pyramid{0.5}{15.3}{1}{1.2}{color=gray!10}{3}; + + % Second maxpool layer + \foreach \i in {0,...,15} + \networkLayer{1.5}{17.8+\i*2/10}{0}{0}{color=fill-light-blue}; + + \coordinate (A1) at (22.8,-3,0) ; + \coordinate (A2) at (22.8,3,0) ; + \coordinate (B1) at (24.8,-1,0) ; + \coordinate (B2) at (24.8,1,0) ; + \coordinate (C1) at (26.8,-1,0) ; + \coordinate (C2) at (26.8,1,0) ; + \coordinate (A11) at (20.5,-1,0) ; + \coordinate (A12) at (20.5,0.45,0) ; + + % Reshape + \draw[line width=1mm] (A1) -- (A2); + \draw[line width=0.1mm] (A) -- (A1); + \draw[line width=0.1mm] (D) -- (A2); + + % Fully connected Dense (dim of 10!) + \draw[line width=1mm] (B1) -- (B2); + \draw[line width=0.1mm] (A1) -- (A11); + \draw[line width=0.1mm] (A2) -- (A12); + \draw[line width=0.1mm] (A1) -- (B1); + \draw[line width=0.1mm] (A1) -- (B2); + \draw[line width=0.1mm] (A2) -- (B1); + \draw[line width=0.1mm] (A2) -- (B2); + + \node[Arrow] at (25.8,0,0) {}; + + \node[text width=3cm, align=center%, font=\fontsize{45}{1}\selectfont + ] at (27.5,0,0) {\Huge {\texttt{Bird}}}; + + \end{tikzpicture} + %} + +\end{document} diff --git a/tikz/figure1-3-d-recursive_graph.tex b/tikz/figure1-3-d-recursive_graph.tex new file mode 100644 index 0000000..ab36cd4 --- /dev/null +++ b/tikz/figure1-3-d-recursive_graph.tex @@ -0,0 +1,60 @@ +\documentclass[border=0.2cm]{standalone} + +% More defined colors +\usepackage[dvipsnames]{xcolor} +\usepackage{tikz} +\usepackage{xstring} +\usepackage{pgfmath,pgffor} +\usepackage{arrayjob} +\usepackage{medl_colors} + +\usetikzlibrary{arrows.meta,shapes.arrows, shapes.misc} +\usetikzlibrary{positioning} +\usetikzlibrary{cd, fit, calc} +\usepackage{textcomp} + +\begin{document} +\begin{tikzpicture} + +\newcommand{\numlayerA}{3} +\newcommand{\nodedis}{8} + +\newarray\indicesarray +\readarray{indicesarray}{-1&&+1} + + +\node [blueshape, rounded corners, minimum width=2cm, minimum height=1cm] (controller1) at (0, 0) {$ h ^{\langle{} t \rangle{} } $ }; +\node [redshape, circle, minimum size=1.5cm, above of=controller1, node distance=2cm ] (circlea1) {$ y ^{\langle{} t \rangle{} } $ }; +\node [greenshape, circle, minimum size=1.5cm, below of=controller1, node distance=2cm ] (circleb1) {$ x ^{\langle{} t \rangle{} } $ }; + +\draw [Triangle-, bthickline] (circlea1.south) -- (controller1.north) node[midway,right] {}; +\draw [-Triangle, bthickline] (circleb1.north) -- (controller1.south) node[midway,right] {}; + +\draw[-Triangle, bthickline] ($(controller1.north west)+(0.5,0)$) -- ++ (0,0) arc[start angle=20, end angle=331, x radius=1.2cm, y radius =1.2cm] node[midway, right] (feedbackcircle) {}; + +\node[right of=controller1, node distance=2.5cm] (arrowh) {}; + +\node[right of=arrowh, thick, node distance=1.5cm, yshift=-1pt] (dot1) {- -}; +\draw [-Triangle, bthickline] (dot1.east)+(.1cm,1pt) -- node[below] (arrow1) {} ++(.6,1pt); +\node[below of=circleb1, node distance=1.7cm] (textrecgraph) {\Huge Recursive graph}; + +\node [greylayer, inner sep = 3mm, fit={(feedbackcircle) (controller1) (circlea1) (textrecgraph)} ] {}; + +\foreach \i in {1,...,\numlayerA} +{ + \node [blueshape, rounded corners, minimum width=2cm, minimum height=1cm] (controller\i) at (3 + \i*3, 0) {$ h ^{\langle{} t\indicesarray(\i) \rangle{} } $}; + \node [redshape, circle, minimum size=1.5cm, above of=controller\i, node distance=2cm ] (circlea\i) {$ y ^{\langle{} t\indicesarray(\i) \rangle{} } $ }; + \node [greenshape, circle, minimum size=1.5cm, below of=controller\i, node distance=2cm ] (circleb\i) { $ x ^{\langle{} t\indicesarray(\i) \rangle{} } $ }; + \draw [Triangle-, bthickline] (circlea\i.south) -- (controller\i.north) node[midway,right] {}; + \draw [-Triangle, bthickline] (circleb\i.north) -- (controller\i.south) node[midway,right] {}; + \draw [-Triangle, bthickline] (controller\i.east)+(.1cm,1pt) -- node[] (arrow\i) {} ++(.8,1pt); +} + +\node[below of=circleb2, node distance=1.7cm] (textunfoldgraph) {\Huge Unfolded graph}; + +\node[right of=controller3, node distance=2.3cm](dot2) {- -}; +\node [greylayer, inner sep = 3mm, fit={(dot1) (dot2) (circlea2) (textunfoldgraph)}] {}; + + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure1-4-b-dendrites_with_synaptic_weights_axons.tex b/tikz/figure1-4-b-dendrites_with_synaptic_weights_axons.tex new file mode 100644 index 0000000..9597de1 --- /dev/null +++ b/tikz/figure1-4-b-dendrites_with_synaptic_weights_axons.tex @@ -0,0 +1,28 @@ +\documentclass[border = 0.2cm]{standalone} + +% Required package +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usepackage{medl_colors} +\begin {document} + +% Layer A neurons'number +\newcommand{\numlayerA}{5} + +\newcommand{\numlayerB}{1} + +\begin{tikzpicture} + +\node[blueshape, ellipse, minimum width = 2cm, minimum height = 1cm] (layerB) at (6,-6) {\large Neuron}; + +\foreach \i in {1,...,\numlayerA} +{ + \node[blueshape, circle, minimum size = 10mm] (layerA\i) at (0,-\i*2) {}; + \draw [-Triangle, thickline] (layerA\i) -- (layerB) node[pos=.2, above] {$w_\i$}; +} + +\draw [-Triangle, thickline, double] (layerB.east) -- node[above] {\large } ++(2,0); + +\end{tikzpicture} + +\end {document} \ No newline at end of file diff --git a/tikz/figure2-1-training_prediction.tex b/tikz/figure2-1-training_prediction.tex new file mode 100644 index 0000000..79fda48 --- /dev/null +++ b/tikz/figure2-1-training_prediction.tex @@ -0,0 +1,59 @@ +\documentclass[tikz, border=20pt]{standalone} + +\usepackage{tikz} +\usepackage{geometry} +\usepackage{medl_colors} +\usepackage{graphicx} +\graphicspath{ {./images/} } + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit} + +\begin{document} + +\begin{tikzpicture} + + \newcommand\cube[6] + { +\fill[yellowshape] (#1+#4,#2,#3) -- (#1+#4,#2+#5,#3) -- (#1,#2+#5,#3) --(#1,#2,#3) -- cycle; +\fill[yellowshape] (#1+#4,#2,#3) -- (#1+#4,#2,#3+#6) -- (#1+#4,#2+#5,#3+#6) -- (#1+#4,#2+#5,#3) -- cycle; +\fill[yellowshape] (#1+#4,#2+#5,#3) -- (#1,#2+#5,#3) -- (#1,#2+#5,#3+#6) -- (#1+#4,#2+#5,#3+#6) -- cycle; +} + + +%Training Data +\node[thickline, rectangle split, rectangle split parts=2, rectangle split horizontal, rectangle split draw splits=false, rectangle split part fill={fill-green, fill-red}, minimum height=3cm, draw] (rect1) { + \nodepart[text width=1.2cm]{one} + \nodepart[text width=.3cm]{two} +}; + +\draw[densely dashed] (rect1.one split north) -- (rect1.one split south); +\draw[draw, -] ([yshift=-0.1cm]rect1.two north) -- ([yshift=0.1cm]rect1.two south) node[midway, anchor=center, fill=fill-red] {\large $y$}+(0,1mm); +\draw[draw, -] ([yshift=-0.1cm]rect1.one north) -- ([yshift=0.1cm]rect1.one south) node[midway, anchor=center, fill=fill-green] {\large $x$}; +\node[above of=rect1, align=center, node distance=2cm] (training) {\large Training Data}; + +%Learning Algorithm Cube +\cube{3}{-1.2}{0}{3}{2}{-1.5} +\node[align=center] at (4.6,-.1) {\large Learning\\\large Algorithm}; + +%model +\node[blueshape, ellipse, minimum width = 3.5cm, minimum height = 2.5cm, align=center] (model) at (11,0) {\large Model\\(Prediction \\ Algorithm)}; + +%\node[blueshape, ellipse, minimum width = 4cm, minimum height = 2.5cm, align=center] (model) at (10.5,3) {\large Model\\(Clustering\\Rule)}; + + +%Real world +\node[scale = .3] (inputpic) at (18,0) {\includegraphics {images/earth.jpeg}}; +\node[right of=inputpic, align=center, node distance=1.6cm] {\large Real\\ \large World}; + +%Arrows +\draw [-Triangle, ubthickline] (rect1.east)+(.1cm,0) -- node[] {} ++(1.7,0); +\draw [-Triangle, ubthickline] (model.west)+(-2.9cm,0) to (model.west) node[] (arrow1) {}; +\path (model) edge [-Triangle,out=270,in=270, ubthickline] node [midway, anchor=center, fill=white] {\Large $\hat{y}$} (inputpic); +\path (model) edge [Triangle-,out=90,in=90,ubthickline] node [midway, anchor=center, fill=white] {\Large $[ -\hspace{.3cm} x^\star \hspace{.3cm} - ] $} (inputpic); +\path (inputpic) edge [-Triangle,dashed, out=80,in=80,ubthickline] node [] {} (training); + +\end{tikzpicture} + +\end{document} + diff --git a/tikz/figure2-11-kfold_cross_validation.tex b/tikz/figure2-11-kfold_cross_validation.tex new file mode 100644 index 0000000..5abf5e3 --- /dev/null +++ b/tikz/figure2-11-kfold_cross_validation.tex @@ -0,0 +1,49 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{geometry, amsmath} +\usepackage{medl_colors} +\usepackage{pgfplots} + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit} +\usetikzlibrary{positioning} + +\pgfplotsset{compat=1.17} +\begin{document} + +\begin{tikzpicture} +\newcommand\medlblock[5] +{ + \node[below of=#4, thickline, node distance=#5, rectangle split, rectangle split parts=5, rectangle split horizontal, rectangle split draw splits=true, rectangle split part fill={#2}, minimum height=1cm, draw] (#1) { + \nodepart[text width=2cm]{one} + \nodepart[text width=2cm]{two} + \nodepart[text width=2cm]{three} + \nodepart[text width=4cm, align=center]{four} ... + \nodepart[text width=2cm]{five} +}; +\draw [-Triangle, thickline] (#1.east)+(.1cm,0) -- node[] (arrow#1) {} ++(.8,0); +\node[align=center, right of=arrow#1, node distance=1.3cm] {\large $E^{(#3)}_{\text{validation}}$}; +\node[align=center, left of=#1, node distance=7.3cm] {$k = $ #3}; +} + +%root +\node[draw] (root){}; +\medlblock{A}{fill-light-red,fill-light-blue}{1}{root}{0}; +\draw[decorate, uthickline, decoration={brace, raise=.8cm, amplitude=15pt}] (-6.5,0) -- (-4.5,0) node[pos=0.5, above=1.4cm]{\large Validation Data}; +\draw[decorate, uthickline, decoration={brace, raise=.8cm, amplitude=15pt}] (-4.3,0) -- (6.5,0) node[pos=0.5,above=1.4cm]{\large Training Data}; + +%Bar 2 +\medlblock{B}{fill-light-blue, fill-light-red, fill-light-blue}{2}{A}{2.5cm}; + +%seperator +\node[align=center, below of=B, node distance=1.5cm, font=\bfseries] (sep) {.\\.\\.}; + +%Bar 3 +\medlblock{C}{fill-light-blue, fill-light-blue, fill-light-blue, fill-light-blue, fill-light-red}{K}{sep}{1.5cm}; +\draw[decorate, uthickline, decoration={brace, raise=.8cm, amplitude=15pt, mirror}] (-6.5,-5.5) -- (4.3,-5.5) node[pos=0.5,below=1.4cm]{\large Training Data}; +\draw[decorate, uthickline, decoration={brace, raise=.8cm, amplitude=15pt,mirror}] (4.5, -5.5) -- (6.5, -5.5) node[pos=0.5, below=1.4cm]{\large Validation Data}; + +\end{tikzpicture} +\end{document} + diff --git a/tikz/figure2-2-clustering_reduction.tex b/tikz/figure2-2-clustering_reduction.tex new file mode 100644 index 0000000..5083885 --- /dev/null +++ b/tikz/figure2-2-clustering_reduction.tex @@ -0,0 +1,92 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{geometry} +\usepackage{medl_colors} +\usepackage{graphicx} + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit} + +\graphicspath{ {./images/} } + +\begin{document} + +\begin{tikzpicture} + +\newcommand\cube[7] +{ +\fill[yellowshape] (#1+#4,#2,#3) -- (#1+#4,#2+#5,#3) -- (#1,#2+#5,#3) --(#1,#2,#3) -- cycle; +\fill[yellowshape] (#1+#4,#2,#3) -- (#1+#4,#2,#3+#6) -- (#1+#4,#2+#5,#3+#6) -- (#1+#4,#2+#5,#3) -- cycle; +\fill[yellowshape] (#1+#4,#2+#5,#3) -- (#1,#2+#5,#3) -- (#1,#2+#5,#3+#6) -- (#1+#4,#2+#5,#3+#6) -- cycle; + +\coordinate (#7B) at (#1+#4, #2+#5/2, #3+#6/2); +} + +%Clustering Blocks +%Input Data +\node (rect) [greenshape, minimum width=1.5cm,minimum height=3cm] (rect) at (0,0) {}; +\draw[draw, -] ([yshift=-0.1cm]rect.north) -- ([yshift=0.1cm]rect.south) node[midway, anchor=center, fill=fill-green] {\large $x$}+(0,1mm); +\node[above of=rect, align=center, node distance=2cm] (training) {\large Input Data}; + +%Cube +\cube{3}{-1.2}{0}{3}{2}{-1.5}{cube1} +\node[align=center] at (4.5,-.2) {\large Clustering\\Algorithm}; + +%Model +\node[blueshape, ellipse, minimum width = 4cm, minimum height = 2.5cm, align=center] (model) at (10.5,3) {\large Model\\(Clustering\\Rule)}; + +%Clustered Data +\node[redshape, rectangle split, rectangle split parts=7, rectangle split draw splits=false, minimum height=7cm, draw] (rect1) at (10.5, -3) { + Cluster 1 + \nodepart{two} Cluster 2 + \nodepart{three} .\\. + \nodepart{four} .\\. + \nodepart{five} .\\. + \nodepart{six} .\\. + \nodepart{seven} Cluster k +}; +\draw[draw, -] (rect1.text split east) -- (rect1.text split west) node[] {}; +\draw[draw, -] (rect1.two split east) -- (rect1.two split west) node[] {}; +\draw[draw, -] (rect1.six split east) -- (rect1.six split west) node[] {}; +\node[above of=rect1, align=center, node distance=2.8cm] (cluster) {\large Clustered Data}; + +%World +\node[scale = .5] (inputpic) at (16,-6) {\includegraphics {images/earth.jpeg}}; +\node[right of=inputpic, align=center, node distance=2.5cm] {\large Real\\World}; + +%Arrows +\draw [-Triangle, ubthickline] (rect.east) -- ($(rect.east)+(2.2,0)$) node[] {}; +\path (cube1B) edge [-Triangle, out=0,in=180,ubthickline] node [] {} (model); +\path (cube1B) edge [-Triangle, out=0,in=180,ubthickline] node [] {} (rect1); +\path (inputpic) edge [Triangle-Triangle, out=90,in=0,ubthickline] node [] {} (model); +\path (inputpic) edge [Triangle-Triangle, out=175,in=0,ubthickline] node [] {} (rect1); + +%Data Reduction + +%Input data +\node (rect) [greenshape, minimum width=1.5cm,minimum height=3cm] (rect2) at (0,-11) {}; +\draw[draw, -] ([yshift=-0.1cm]rect2.north) -- ([yshift=0.1cm]rect2.south) node[midway, anchor=center, fill=fill-green] {\large $x$}+(0,1mm); +\node[above of=rect2, align=center, node distance=2cm] (training) {\large Input Data}; + +%Cube +\cube{3}{-12.2}{0}{3}{2}{-1.5}{cube2} +\node[align=center] at (4.5,-11.2) {\large Data Reduction\\Algorithm}; + +\node[blueshape, ellipse, minimum width = 4cm, minimum height = 2.5cm, align=center] (model1) at (10.5,-15) {\large Model\\(Data Reduction\\Rule)}; + +%low dimensional data +\node (rect) [redshape, minimum width=.75cm,minimum height=3cm] (rect3) at (10.5, -9) {}; +\draw[draw, -] ([yshift=-0.1cm]rect3.north) -- ([yshift=0.1cm]rect3.south) node[midway, anchor=center, fill=fill-red] {\large $\tilde{x}$}; +\node[above of=rect3, align=center, node distance=2.2cm] (cluster) {\large Low Dimensional\\Data}; + +%Arrows +\draw [-Triangle, ubthickline] (rect2.east) -- ($(rect2.east)+(2.2,0)$) node[] {}; +\path (cube2B) edge [-Triangle, out=0,in=180, ubthickline] node [] {} (model1); +\path (cube2B) edge [-Triangle, out=0,in=180,ubthickline] node [] {} (rect3); +\path (inputpic) edge [Triangle-Triangle, out=270,in=0,ubthickline] node [] {} (model1); +\path (inputpic) edge [Triangle-Triangle, out=180,in=0,ubthickline] node [] {} (rect3); + +\end{tikzpicture} + +\end{document} diff --git a/tikz/figure2-5-plot_sum_squares.tex b/tikz/figure2-5-plot_sum_squares.tex new file mode 100644 index 0000000..0d19972 --- /dev/null +++ b/tikz/figure2-5-plot_sum_squares.tex @@ -0,0 +1,53 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{geometry} +\usepackage{medl_colors} +\usepackage{pgfplots} + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit} +\usetikzlibrary{positioning} + +\pgfplotsset{compat=1.18} + +\begin{document} +\begin{tikzpicture} + +\newcommand\medlsquare[6] +{ + \coordinate (#4A) at (#1, #2); + \coordinate (#4B) at (#1+#3, #2); + \coordinate (#4C) at (#1+#3, #2+#3); + \coordinate (#4D) at (#1, #2+#3); + \filldraw[blueshape] plot coordinates {(#4A) (#4B) (#4C) (#4D) (#4A)}; + \filldraw [black] (#4#5) circle (2pt); + \draw[thick, densely dotted] (#4#5) -- (#4#6); +} + +\begin{axis}[ +axis line style = thick, +xmin = 0, xmax = 10, +ymin = 0, ymax = 10, +xlabel={$x$}, +ylabel={$y$}, +xtick={2,4,6,8,10}, +ytick={2,4,6,8,10}, +tick style={thick}, +xtick pos=bottom, +ytick pos=left, +x=.8cm, +y=.8cm, +axis lines* = left +] + +\addplot[color = border-red, ultra thick] coordinates {(0, 1) (10, 8)}; +\filldraw [black] (3,3.2) circle (2pt); +\medlsquare{4.3}{2.8}{1.2}{square}{A}{D} +\medlsquare{4.7}{4.7}{.6}{square}{C}{B} +\medlsquare{5}{5.8}{1.8}{square}{C}{B} +\medlsquare{8.2}{5.3}{1.4}{square}{A}{D} + +\end{axis} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure2-9-error_modelcomplexity.tex b/tikz/figure2-9-error_modelcomplexity.tex new file mode 100644 index 0000000..005ce5f --- /dev/null +++ b/tikz/figure2-9-error_modelcomplexity.tex @@ -0,0 +1,53 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{geometry, amsmath} +\usepackage{medl_colors} +\usepackage{pgfplots} + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix,decorations.pathreplacing, calc, positioning,fit} +\usetikzlibrary{positioning} + +\pgfplotsset{compat=1.17} + +\begin{document} +\begin{tikzpicture} + +\newcommand\medlsquare[7] +{ + \addplot[thick, draw=gray!20,fill=#6] coordinates { (#1, #2) (#1+#3, #2) (#1+#3, #2+#4) (#1, #2+#4) (#1, #2)} node[] {}; + \path[draw, Triangle-Triangle] ([yshift=-0.4cm]#1+#3, #2+#4) -- ([yshift=-0.4cm]#1, #2+#4) node[midway,anchor=center, fill=#6] {#7}; +} + +\begin{axis}[ + axis line style = ultra thick, + xlabel={\Large Model Complexity}, + ylabel={\Large Error}, + xticklabels={}, + yticklabels={}, + ytick style={draw=none}, + xtick style={draw=none}, + x label style={at={(.6,-.03)}}, + xmin = 0, xmax = 22, + ymin = 0.1, ymax = 14, + x=22, + y=14, + legend cell align=left, + legend style={at={(.58,.95)},column sep=10pt}, + axis lines* = left +] + +\medlsquare{1}{.2}{5}{14}{A}{fill-light-green}{\Large Underfitting} +\medlsquare{14}{.2}{7}{14}{B}{fill-light-red}{\Large Overfitting} + +\addplot[thick, loosely dashed] coordinates {(7.7, .4) (7.7, 6)} node[align=center] at (8.1,7) {\Large Optimal Model}; + +\path (1.5,13) edge [out=280,in=200,draw=border-red, line width=.7mm] node [pos=.85, above=.8] {\LARGE $\tilde{E}_{\text{unseen}}$} (21,11); + +\path (1.5,13) edge [out=280,in=175,draw=border-green, line width=.7mm] node [pos=.9, above=.5] {\LARGE $\tilde{E}_{\text{train}}$} (21,1); + +\end{axis} +\end{tikzpicture} +\end{document} + diff --git a/tikz/figure3-11-bottleneck_autoencoder.tex b/tikz/figure3-11-bottleneck_autoencoder.tex new file mode 100644 index 0000000..c868503 --- /dev/null +++ b/tikz/figure3-11-bottleneck_autoencoder.tex @@ -0,0 +1,50 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usepackage{amsmath} + +\begin{document} +\begin{tikzpicture} + +%Encoder - Input Layer +\node[bluelayer, inner xsep = 4cm, inner ysep=6cm] (encoderlayer){}; +\node [greenshape, circle, minimum size=1.2cm ] (incircle1) at (-2.5, 4) {\large $ x_1 $}; +\node [greenshape, circle, minimum size=1.2cm, below of=incircle1, node distance=3cm] (incircle2){\large $ x_2 $}; +\node [greenshape, circle, minimum size=1.2cm, below of=incircle2, node distance=5cm] (incircle3){\large $ x_p $}; +\draw[ultra thick, dotted] ([yshift=-3mm]incircle2.south) -- ([yshift=3mm]incircle3.north); +\node[above of=incircle1, align=center, node distance=1.4cm] {\large Input Layer}; +\node[below left= 8mm and -9mm of incircle3] {\large Encoder}; + +%Bottleneck - hidden layer +\node[draw=fill-grey, ultra thick, rounded corners, inner xsep = 1.2cm, inner ysep=4cm] at (2.5,0)(hiddenlayer){}; +\node [blueshape, circle, minimum size=1.2cm ] (hidcircle1) at (2.5, 3) {\large $\tilde x_1$}; +\node [blueshape, circle, minimum size=1.2cm, below of=hidcircle1, node distance=2.5cm ] (hidcircle2){\large $\tilde x_2$}; +\node [blueshape, circle, minimum size=1.2cm, below of=hidcircle2, node distance=3.5cm ] (hidcircle3){\large $\tilde x_m$}; +\draw[draw, ultra thick, dotted] ([yshift=-3mm]hidcircle2.south) -- ([yshift=3mm]hidcircle3.north); +\node[above of=hidcircle1, align=center, node distance=1.5cm] {\large Bottleneck}; + +%Decode - Output Layer +\node[redlayer, rounded corners, inner xsep = 4cm, inner ysep=6cm] at(5,-.2)(encoderlayer){}; +\node [redshape, circle, minimum size=1.2cm] (outcircle1) at (7.5, 4) {\large $\hat x_1 $}; +\node [redshape, circle, minimum size=1.2cm, below of=outcircle1, node distance=3cm] (outcircle2){\large $\hat x_2 $}; +\node [redshape, circle, minimum size=1.2cm, below of=outcircle2, node distance=5cm] (outcircle3){\large $\hat x_p $}; +\draw[ultra thick, dotted] ([yshift=-3mm]outcircle2.south) -- ([yshift=3mm]outcircle3.north); +\node[above of=outcircle1, align=center, node distance=1.3cm] {\large Output Layer}; +\node[below right = 1.1cm and -9mm of outcircle3] {\large Decoder}; + +%Arrows +\foreach \i in {1,2,3} +{ + \foreach \j in {1,2,3} + { + \draw[-Triangle, thickline] (incircle\i) -- (hidcircle\j); + \draw[-Triangle, thickline] (hidcircle\i) -- (outcircle\j); + } +} + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure3-12-autoencoder_reconstruction.tex b/tikz/figure3-12-autoencoder_reconstruction.tex new file mode 100644 index 0000000..38d1ad4 --- /dev/null +++ b/tikz/figure3-12-autoencoder_reconstruction.tex @@ -0,0 +1,23 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{graphicx} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usepackage{xstring} + +\begin{document} +\begin{tikzpicture} + +%input picture +\node[scale = .67] (outputpic) {\includegraphics {images/mnist_predict.pdf}}; + +%lables +\node[left of = outputpic, node distance = 10.65cm, yshift=3.2cm, align=right] {\huge MNIST test set}; +\node[left of = outputpic, node distance = 12.1cm, yshift=1cm, align=right] {\huge Reconstruction with PCA}; +\node[left of = outputpic, node distance = 14.4cm, yshift=-1.1cm, align=right] {\huge Reconstruction with shallow autoencoder}; +\node[left of = outputpic, node distance = 14.0cm, yshift=-3.3cm, align=right] {\huge Reconstruction with deep autoencoder}; + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure3-13-pca-ae-manifolds.tex b/tikz/figure3-13-pca-ae-manifolds.tex new file mode 100644 index 0000000..aad5aaa --- /dev/null +++ b/tikz/figure3-13-pca-ae-manifolds.tex @@ -0,0 +1,34 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{graphicx} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usepackage{xstring} + +\begin{document} +\begin{tikzpicture} + +%input picture +\node[scale = .5] (aepoints) {\includegraphics {images/ae_points.pdf}}; + +\node[scale = .2, below of=aepoints, node distance=30cm, xshift=-14cm] (pcacodepoints) {\includegraphics[trim={0 6cm 0 5cm},clip] {images/pca_code_points.pdf}}; +\node[scale = .2, below of=aepoints, node distance=30cm, xshift=14cm, rotate=180] (aecodepoints) {\includegraphics[trim={0 5cm 0 6cm},clip] {images/ae_code_points.pdf}}; + +\node[scale = .2, below of=pcacodepoints, node distance=20cm, xshift=-11cm] (pcaprojectionpoints) {\includegraphics{images/pca_projection_points.pdf}}; +\node[scale = .2, below of=aecodepoints, node distance=20cm, xshift=11cm] (aeprojectionpoints) {\includegraphics {images/ae_projection_points.pdf}}; + +%lables +\node[above of=aepoints, align=center, node distance=4cm](toutput) {\large Original Data}; +\draw[-Triangle, bthickline] (aepoints) -- (pcacodepoints) node[midway, anchor=east, yshift=.2cm, align=center]{\large PCA Encoding}; +\draw[-Triangle, bthickline] (aepoints) -- (aecodepoints)node[midway, anchor=west, align=center]{\large Non-linear\\\large Encoding}; +\draw[-Triangle, bthickline] (pcacodepoints) -- (pcaprojectionpoints)node[midway, anchor=east, align=center, yshift=.3cm]{\large PCA Decoding}; +\draw[-Triangle, bthickline] (aecodepoints) -- (aeprojectionpoints)node[midway, anchor=west, align=center]{\large Non-linear\\\large Decoding}; + +%markings on the plots +\node[above of=pcaprojectionpoints, align=center, yshift=-0.8cm, xshift=-1cm, rotate=40](toutput) {\large Projection on a \\\large hyperplane}; +\node[above of=aeprojectionpoints, align=center, yshift=-1cm, xshift=-1cm, rotate=40](toutput) {\large Projection on a \\\large manifold}; + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure3-15-reconstructing_input.tex b/tikz/figure3-15-reconstructing_input.tex new file mode 100644 index 0000000..a3b6e93 --- /dev/null +++ b/tikz/figure3-15-reconstructing_input.tex @@ -0,0 +1,121 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{graphicx} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usepackage{xstring} + +\newif\ifmember +\makeatletter +\newcommand{\MemberQ}[2]{\global\memberfalse% +\@for\next:=#1\do{\ifnum\next=#2\global\membertrue\fi}} +\makeatother + +\begin{document} +\begin{tikzpicture} + +\newcommand\circles[4] +{ + \foreach \i in {1,2,3,4,5,6,7} + { + \IfEq{#3}{1}% + { + \node [#4, circle, minimum size=.6cm] (circle#1\i) at(#2, -\i+4) {}; + } + { + \MemberQ{2,5,6}{\i} + \ifmember + { + \node [draw=border-green, thick, circle, minimum size=.6cm] (circle#1\i) at(#2, -\i+4) {}; + \begin{scope} + \clip(#2, -\i+4) circle(.3cm); + \foreach \p in {.03, .06, .09, .12, .15, .18, .20, .24, .22} + { + \foreach \q in {.04, .08, .12, .15, .18, .21} + { + \fill (#2, -\i+4) circle (0.01); + \fill (#2, -\i+4+\q) circle (0.01); + \fill (#2, -\i+4-\q) circle (0.01); + \fill (#2+\p, -\i+4) circle (0.01); + \fill (#2+\p, -\i+4+\q) circle (0.01); + \fill (#2+\p, -\i+4-\q) circle (0.01); + \fill (#2-\p, -\i+4) circle (0.01); + \fill (#2-\p, -\i+4+\q) circle (0.01); + \fill (#2-\p, -\i+4-\q) circle (0.01); + } + } + \end{scope} + + } + \else% + { + \node [#4, circle, minimum size=.6cm] (circle#1\i) at(#2, -\i+4) {}; + } + \fi + } + } +} + +%center part +\node (rect) at (0,0) [blueshape, minimum width=1.5cm,minimum height=1.2cm] (rectangle) {\Large Bottleneck}; + +\node[greenshape, trapezium, align=center, trapezium angle=75,minimum height=4cm, shape border rotate=270, left of = rectangle, node distance = 4cm, text=black] (t1) { \Large Encoder}; + +%\node[trapezium, + % greenshape, + % text = black, + % align=center, + % trapezium angle=80, + % minimum height=3cm, + % shape border rotate=270, + % left of = rectangle, node distance = 4cm ] (t1) { \large Encoder}; +\node[redshape, trapezium, align=center, trapezium angle=75,minimum height=4cm, shape border rotate=90, right of = rectangle, node distance = 4cm, text=black] (t2) { \Large Decoder}; + +% \node[trapezium, +% blueshape, +% text = black, +% align=center, +% trapezium angle=80, +% minimum height=3cm, +% shape border rotate=90, +% right of = rectangle, node distance = 4cm ] (t2) {\large Decoder}; + +%input +\node[left of = t1, node distance = 4cm, lightgreenshape, minimum width=1cm,minimum height=8cm ] (input) {}; +\circles{1}{-8}{2}{greenshape}; +\circles{2}{-10}{2}{greenshape}; +\circles{3}{-12}{1}{greenshape}; + +%output +\node[right of = t2, node distance = 4cm, lightredshape, minimum width=1cm,minimum height=8cm] (output) {}; +\circles{4}{8}{1}{redshape}; + +%arrows +\draw [-Triangle, thickline] (t1.east) -- (rectangle.west) node[midway,right] {}; +\draw [-Triangle, thickline] (rectangle.east) -- (t2.west) node[midway,right] {}; +\draw [-Triangle, thickline] (input.east) -- (t1.west) node[midway,right] {}; +\draw [-Triangle, thickline] (t2.east) -- (output.west) node[midway,right] {}; +\draw [-Triangle, thickline] ([xshift=1mm]circle34.east) -- ([xshift=-1mm]circle24.west) node[midway,right] {}; +\draw [-Triangle, thickline] ([xshift=1mm]circle24.east) -- ([xshift=-2mm]circle14.west) node[midway,right] {}; + +%production system +\node[redlayer, rounded corners, inner xsep = 9.2cm, inner ysep=6cm] at(0.2, 0) (production){}; +\node[below of=production, align=center, node distance=5.5cm] {\Large Production System}; + +%bottom images +\node[scale = .3, below of = circle17, node distance = 6cm] (inputpic1) {\includegraphics {images/partially_destroyed_input.png}}; +\node[scale = .3, below of = circle27, node distance = 6cm] (inputpic2) {\includegraphics {images/partially_destroyed_input.png}}; +\node[scale = .3, below of = circle37, node distance = 6cm] (inputpic3) {\includegraphics {images/original_input.png}}; +\node[scale = .3, below of = output, node distance = 16cm] (outputpic) {\includegraphics {images/original_input.png}}; + +%lables +\node[above of=circle11, align=center, node distance=2cm] {\large Input}; +\node[above of=circle21, align=center, node distance=2cm] {\large Partially\\\large Destroyed\\\large Training\\\large Data}; +\node[above of=circle31, align=center, node distance=2cm] (tinput) {\large Original\\\large Training \\\large Data}; +\node[above of=output, align=center, node distance=5cm](toutput) {\large Reconstructed\\\large Input}; + + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure3-16_interpolation.tex b/tikz/figure3-16_interpolation.tex new file mode 100644 index 0000000..c1ba7f6 --- /dev/null +++ b/tikz/figure3-16_interpolation.tex @@ -0,0 +1,27 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{graphicx, amsmath} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usepackage{xstring} + +\begin{document} +\begin{tikzpicture} + +%images +\node[scale = .4] (interpolation3_1) {\includegraphics {images/interpolation3_1.png}}; +\node[scale = .4, right of=interpolation3_1, node distance=10cm] (interpolation3_3) {\includegraphics {images/interpolation3_3.png}}; +\node[scale = .4, above of = interpolation3_1, node distance = 8cm, xshift=5cm] (interpolation3_2) {\includegraphics {images/interpolation3_2.png}}; +\node[scale = .4, below of = interpolation3_2, node distance = 16cm] (interpolation3_4) {\includegraphics {images/interpolation3_4.png}}; + +%labels +\node[node distance = 1.5cm, align=center, below of = interpolation3_1] { \large $x^{(i)}$}; +\node[node distance = 1.5cm, align=center, below of = interpolation3_2] {{\large $x_\lambda^{\text{naive}}$}}; +\node[node distance = 1.5cm, align=center, below of = interpolation3_3] { \large $x^{(j)}$}; +\node[node distance = 1.5cm, align=center, below of = interpolation3_4] { \large $x_\lambda^{\text{encoder}}$}; + + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure3-3-logistic_architecture.tex b/tikz/figure3-3-logistic_architecture.tex new file mode 100644 index 0000000..6f44c0d --- /dev/null +++ b/tikz/figure3-3-logistic_architecture.tex @@ -0,0 +1,54 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usetikzlibrary{angles,quotes} +\usepackage{amsmath} + +\begin{document} +\begin{tikzpicture} + +%Input matrix +\matrix (m1) [ + row sep=0.8cm, + matrix of math nodes, + nodes in empty cells, + left delimiter={[},right delimiter={]} + ] { + {x_1}\\ + {x_2}\\ + \vdots \\ + {x_p}\\ + } ; + +%Center rectangles and circles +\node[rounded corners, draw, inner xsep = 3cm, inner ysep=1.2cm, fill=fill-light-grey, right of = m1, node distance = 6cm] (rec){}; +\node [draw, circle, minimum size=22mm, left of = rec, node distance=14mm, fill=fill-light-yellow] (circle2) {$ \sum $}; +\node [fill=fill-light-yellow, draw, circle, minimum size=22mm, right of = rec, node distance=14mm ] (circle1) {}; +\draw[draw=border-blue,looseness=1.4, line width=.5mm] ([yshift=-4mm, xshift=3mm]circle1.west) to [out = 0,in =260] (circle1.center) to [out=80,in=180] ([yshift=4mm, xshift=-3mm]circle1.east); + +%Arrrows +\draw [-Triangle, thickline] ([xshift=1.8cm,yshift=5mm]m1.north east) -- (rec.north west) node[pos=0, fill=white] (B) {$b$}; +\draw [-Triangle, thickline] ([xshift=7mm]$(m1-1-1)$) -- ($(rec.north west)!0.25!(rec.south west)$) node[pos=.5, below] {$w_1$}; +\draw [-Triangle, thickline] ([xshift=7mm]$(m1-2-1)$) -- ($(rec.north west)!0.50!(rec.south west)$) node[pos=.5, below] {$w_2$}; +\draw [-Triangle, thickline] ([xshift=7mm]$(m1-3-1)$) -- ($(rec.north west)!0.75!(rec.south west)$) node[] {}; +\draw [-Triangle, thickline] ([xshift=7mm]$(m1-4-1)$) -- (rec.south west) node[pos=.5, below] {$w_p$}; +\draw [-Triangle, thickline] (rec.east) -- node[pos=4.1] {\large $ \hat{y} = \sigma(b + w^\top x)$} ++(.5,0); + +%input formulas +\draw[dashed] ([yshift=-5mm]circle2.south) -- node[pos=1.3] {\large $ z = b + \sum_{i=1}^p w_i x_i$} ++(-1,-1.5); +\draw[dashed] ([yshift=-5mm]circle1.south) -- node[pos=1.3] (output) {\large $ \sigma(z) = \dfrac{1}{1+e^{-z}} \in (0,1)$} ++(1,-1.5); + +%titles +\node[above of=m1-1-1, align=center, node distance=2 cm] {\large Input \\ x}; +\node[above right = 3.4mm and -18mm of B, align=center] {\large Weight, Bias \\ $(w, b)$}; +\node[above of=circle2, align=center, node distance=3.88 cm, xshift=0.1cm] {\large Affine\\ \large Transformation\\z}; +\node[above of=circle1, align=center, node distance=4 cm] (tact) {\large Activation \\ $\sigma(z)$}; +\node[right of = tact, node distance = 2.5cm, align=center] {\large Output \\ $ \hat{y}$}; + +\end{tikzpicture} +\end{document} + diff --git a/tikz/figure3-6-softmax_layer.tex b/tikz/figure3-6-softmax_layer.tex new file mode 100644 index 0000000..63db522 --- /dev/null +++ b/tikz/figure3-6-softmax_layer.tex @@ -0,0 +1,74 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usepackage{amsmath} + +\begin{document} +\begin{tikzpicture} + +\newcommand\semicircleunit[4] +{ + %circle 2 + \begin{scope} + \clip(#1, #2+#3) rectangle(#1-#3, #2-#3); + \node [lightblueshape, circle, minimum size=#3*2 cm] (circle#4) at (#1,#2) {}; + \draw[ubthickline] (#1,#2+#3) -- (#1,#2-#3); + \end{scope} + + %circle 2 + \begin{scope} + \clip(#1, #2+#3) rectangle(-#1+#3, #2-#3); + \node [lightblueshape, redlayer, circle, minimum size=#3*2 cm] (circle1#4) at (#1,#2) {}; + \end{scope} + + %formulas + \node[left of=circle#4, node distance=1.5cm, align=center, text=black, font=\bfseries, yshift=-2.5mm] (text1#4) { \Large $\underbrace{b_#4 + w_{(#4)}^\top x}$ \\ \Large $z_#4$}; + \node[right of=circle#4, node distance=1.6cm, align=center, text=black, font=\bfseries] (text2#4) { \Large $a_#4 = \dfrac{e^{z_#4}}{\sum_{i=1}^K e^{z_i}}$}; + + %output + \draw [-Triangle, bthickline] (circle1#4) -- node[pos=1.3](text3#4) { \Huge $\hat{\phi}_#4(x) $} ++(7,0); + \path (#1,#2) ++(215:#3) coordinate (A#4); +} + +%softmax layer +\node[bluelayer, inner xsep = 4cm, inner ysep=14cm] (largerec) at(0,-9.5){}; +\semicircleunit{0}{0}{3.2}{1}; +\semicircleunit{0}{-8}{3.2}{2}; +\semicircleunit{0}{-19}{3.2}{K}; +\draw [uthickline, loosely dashed] ([yshift=-.5cm]circle2.south) -- ([yshift=.5cm]circleK.north) node[] {}; + +%Input layer +\coordinate (c1) at (-10, 2.5); +\coordinate (c2) at (-10, .5); +\coordinate (c3) at (-10, -1.5); +\coordinate (c4) at (-10, -21.5); + +\foreach \i in {1,2,3} +{ + \foreach \j in {1,2,K} + { + \node[left of=c\i, node distance=5mm, align=center] (t\i) {\huge $x_\i$}; + \draw [-Triangle, bthickline, thick] (c\i) -- (circle\j) {}; + } +} + +%Arrows from input to softmax +\node[left of=c4,node distance=5mm, align=center] (t4) {\huge $x_p$}; +\node[right of=t4, node distance=13cm, yshift=-1.5cm]{\LARGE Softmax}; + +\foreach \i in {1,2,K} +{ + \draw [-Triangle, bthickline, thick] (c4) -- (A\i) {}; +} +\draw [uthickline, loosely dashed, shorten <=4cm, shorten >= 4cm] (t3) -- (t4) node[] {}; + +%output +\draw[uthickline] (9,1) -- (10,1) -- (10,-20.5) -- (9,-20.5); +\draw [-Triangle, bthickline, thick] (10, -10) -- node[pos=1.3] {\Huge $\hat{y}$} ++(2,0); + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure4-7-computational_graph.tex b/tikz/figure4-7-computational_graph.tex new file mode 100644 index 0000000..12d0fcc --- /dev/null +++ b/tikz/figure4-7-computational_graph.tex @@ -0,0 +1,62 @@ +\documentclass[border=0.2cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +%Nodes +\matrix[row sep=2cm,column sep=1.8cm] { + \node [align=center] (node11) {$\theta_1$}; & + \node [blueshape, circle, align=center, minimum size=1.2cm] (node12) {$\times$}; + & + \node [blueshape, circle, align=center, minimum size=1.2cm] (node13) {sin}; & + \\ + \node [align=center] (node21) {$\theta_2$}; & + \node [blueshape, circle, align=center, minimum size=1.2cm] (node22) {+}; & + \node [blueshape, circle, align=center, minimum size=1.2cm] (node23) {exp}; & + \node [blueshape, circle, align=center, minimum size=1.2cm] (node24) {+}; & + \node [align=center] (node25) {$C(\theta)$}; & + \\ + \node [align=center] (node31) {$\theta_3$}; & + \node [blueshape, circle, align=center, minimum size=1.2cm] (node32) {$\times$}; & + \node [] (node33) { }; & + \\ + & + \node [] (node42) {$-2$}; & + \\ + }; + +%Lables for nodes +\node[above of=node12, align=center, node distance=8mm] {\scriptsize 1}; +\node[above of=node22, align=center, node distance=8mm] {\scriptsize 2}; +\node[above of=node32, align=center, node distance=8mm] {\scriptsize 3}; +\node[above of=node13, align=center, node distance=8mm] {\scriptsize 4}; +\node[above of=node23, align=center, node distance=8mm] {\scriptsize 5}; +\node[above of=node24, align=center, node distance=8mm] {\scriptsize 6}; + +%Arrows +\draw [-Triangle, thickline] (node11) -- (node12); +\draw [-Triangle, thickline] (node12) -- (node13) node[pos=.2, above] {$a_1$}; +\draw [-Triangle, thickline] (node13) -- (node24) node[pos=.2, above] {$a_4$}; + +\draw [-Triangle, thickline] (node21) -- (node22); +\draw [-Triangle, thickline] (node21) -- (node12); +\draw [-Triangle, thickline] (node22) -- (node23) node[pos=.2, above] {$a_2$}; +\draw [-Triangle, thickline] (node23) -- (node24) node[pos=.2, above] {$a_5$}; +\draw [-Triangle, thickline] (node24) -- (node25) node[pos=.2, above] {$a_6$}; + +\draw [-Triangle, thickline] (node31) -- (node32); +\draw [-Triangle, thickline] (node31) -- (node22); +\draw (node32) -- (node33.center) node[pos=.2, above] {$a_3$}; +\draw [-Triangle, thickline] (node33.center) -- (node24); + +\draw [-Triangle, thickline] (node42) -- (node32); + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure5-1-a-one_hidden_layer.tex b/tikz/figure5-1-a-one_hidden_layer.tex new file mode 100644 index 0000000..6037f1b --- /dev/null +++ b/tikz/figure5-1-a-one_hidden_layer.tex @@ -0,0 +1,63 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} + +\begin {document} + +% Layer A neurons'number +\newcommand{\numlayerA}{4} + +% Layer B neurons'number +\newcommand{\numlayerB}{5} + +% Layer C neurons'number +\newcommand{\numlayerC}{1} + +\begin{tikzpicture} + +% Layer A +\foreach \i in {1,...,\numlayerA} +{ + \node[greenshape, circle, minimum size = 1cm] (layerA\i) at (0,-\i*2-1) {\Large $x_\i$}; +} + +% Layer B +\foreach \i in {1,...,\numlayerB} +{ + \node[blueshape, circle, minimum size = 1cm] (layerB\i) at (4,-\i*2) {}; +} + +% Layer C +\foreach \i in {1,...,\numlayerC} +{ + \node[redshape, circle, minimum size = 1cm] (layerC\i) at (8,-6) {\Large $\hat y$}; +} + +%connect Layer A and Layer B +\foreach \i in {1,...,\numlayerA} +{ + \foreach \j in {1,...,\numlayerB} + { + \draw[-Triangle, thickline] (layerA\i) -- (layerB\j); + } +} + +%connect Layer B and Layer C +\foreach \i in {1,...,\numlayerB} +{ + \foreach \j in {1,...,\numlayerC} + { + \draw[-Triangle, thickline] (layerB\i) -- (layerC\j); + } +} + +\node[above of=layerA1, align=center, node distance=2.5cm] {\Large Input\\\Large Layer}; +\node[above of=layerB1, align=center, node distance=1.5cm] {\Large Hidden\\\Large Layer}; +\node[above of=layerC1, align=center, node distance=5.5cm] {\Large Output\\\Large Layer}; + +\end{tikzpicture} + +\end {document} \ No newline at end of file diff --git a/tikz/figure5-1-b-deep_neural_network.tex b/tikz/figure5-1-b-deep_neural_network.tex new file mode 100644 index 0000000..31a2b17 --- /dev/null +++ b/tikz/figure5-1-b-deep_neural_network.tex @@ -0,0 +1,101 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} + +\begin {document} + +% Layer A neurons'number +\newcommand{\numlayerA}{4} + +% Layer B neurons'number +\newcommand{\numlayerB}{4} + +% Layer C neurons'number +\newcommand{\numlayerC}{3} + +% Layer C neurons'number +\newcommand{\numlayerD}{5} + +% Layer C neurons'number +\newcommand{\numlayerE}{1} + +\begin{tikzpicture} + +% Layer A +\foreach \i in {1,...,\numlayerA} +{ + \node[greenshape, circle, minimum size = 1cm] (layerA\i) at (0,-\i*2-1) {\Large $x_\i$}; +} + +% Layer B +\foreach \i in {1,...,\numlayerB} +{ + \node[blueshape, circle, minimum size = 1cm] (layerB\i) at (3,-\i*2-1) {}; +} + +% Layer C +\foreach \i in {1,...,\numlayerC} +{ + \node[blueshape, circle, minimum size = 1cm] (layerC\i) at (6,-\i*2-2) {}; +} + +% Layer D +\foreach \i in {1,...,\numlayerD} +{ + \node[blueshape, circle, minimum size = 1cm] (layerD\i) at (9,-\i*2) {}; +} + +% Layer E +\foreach \i in {1,...,\numlayerE} +{ + \node[redshape, circle, minimum size = 1cm] (layerE\i) at (12,-6) {\Large $\hat y$}; +} + +%connect Layer A and Layer B +\foreach \i in {1,...,\numlayerA} +{ + \foreach \j in {1,...,\numlayerB} + { + \draw[-Triangle, thickline] (layerA\i) -- (layerB\j); + } +} + +%connect Layer B and Layer C +\foreach \i in {1,...,\numlayerB} +{ + \foreach \j in {1,...,\numlayerC} + { + \draw[-Triangle, thickline] (layerB\i) -- (layerC\j); + } +} + +%connect Layer C and Layer D +\foreach \i in {1,...,\numlayerC} +{ + \foreach \j in {1,...,\numlayerD} + { + \draw[-Triangle, thickline] (layerC\i) -- (layerD\j); + } +} + +%connect Layer D and Layer E +\foreach \i in {1,...,\numlayerD} +{ + \foreach \j in {1,...,\numlayerE} + { + \draw[-Triangle, thickline] (layerD\i) -- (layerE\j); + } +} + +\node[above of=layerA1, align=center, node distance=2.5cm] {\Large Input\\\Large Layer}; +\node[above of=layerB1, align=center, node distance=2.5cm] {\Large Hidden\\\Large Layer 1}; +\node[above of=layerC1, align=center, node distance=3.5cm] {\Large Hidden\\\Large Layer 2}; +\node[above of=layerD1, align=center, node distance=1.5cm] {\Large Hidden\\\Large Layer 3}; +\node[above of=layerE1, align=center, node distance=5.5cm] {\Large Output\\\Large Layer}; + +\end{tikzpicture} + +\end {document} \ No newline at end of file diff --git a/tikz/figure5-10-batch_norm_comp_graph.tex b/tikz/figure5-10-batch_norm_comp_graph.tex new file mode 100644 index 0000000..4f6c390 --- /dev/null +++ b/tikz/figure5-10-batch_norm_comp_graph.tex @@ -0,0 +1,69 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +%Nodes +\matrix[row sep=5mm, column sep=1cm] (m1) { + \node [blueshape, circle, minimum size=1.3cm, align=center] (node11) {\Large $z^{(1)}$}; & + \node [blueshape, circle, minimum size=1.3cm, align=center] (node12) {\Large $\bar z^{(1)}$}; & + \node [blueshape, circle, minimum size=1.3cm, align=center] (node13) {\Large $\hat z^{(1)}$}; & + & + \\ + \node [yellowshape, circle, minimum size=1.3cm, align=center, xshift=3cm] (node21) {\Large $\hat{\mu}$}; & + \node [yellowshape, circle, minimum size=1.3cm, align=center, xshift=-3cm] (node22) {\Large $\hat{\sigma}^2$}; & + \node [yellowshape, circle, minimum size=1.3cm, align=center, xshift=-3cm, yshift=2cm] (node23) {\Large $\gamma$}; + \node [yellowshape, circle, minimum size=1.3cm, align=center, xshift=-3cm, yshift=-2cm] (node24) {\Large $\beta$}; & + \node [redshape, circle, align=center, xshift=4cm] (node25) {\Large $C(\cdot)$}; & + \\ + \node [blueshape, circle, minimum size=1.3cm, align=center] (node31) {\Large $z^{(n_b)}$}; & + \node [blueshape, circle, minimum size=1.3cm, align=center] (node32) {\Large $\bar z^{(n_b)}$}; & + \node [blueshape, circle, minimum size=1.3cm, align=center] (node33) {\Large $\tilde z^{(n_b)}$}; & + & + \\ + }; + +\draw[-Triangle, thickline] (node11) -- (node21); +\draw[-Triangle, thickline] (node31) -- (node21); +\draw[-Triangle, thickline] (node11) -- (node12); +\draw[-Triangle, thickline] (node21) -- (node12); +\draw[-Triangle, thickline] (node21) -- (node32); +\draw[-Triangle, thickline] (node21) -- (node22); +\draw[-Triangle, thickline] (node22) -- (node12); +\draw[-Triangle, thickline] (node22) -- (node32); +\draw[-Triangle, thickline] (node12) -- (node13); +\draw[-Triangle, thickline] (node32) -- (node33); +\draw[-Triangle, thickline] (node32) -- (node33); +\draw[-Triangle, thickline] (node23) -- (node13); +\draw[-Triangle, thickline] (node24) -- (node33); +\draw[-Triangle, thickline] (node24) -- (node13); +\draw[-Triangle, thickline] (node23) -- (node33); +\draw[-Triangle, thickline] (node11) -- (node22); +\draw[-Triangle, thickline] (node31) -- (node22); + +\draw[dashed, uthickline] ([yshift=-1cm]node11.south) -- ([yshift=1cm]node31.north); +\draw[dashed, uthickline] ([yshift=-1cm]node12.south) -- ([yshift=1cm]node32.north); +\draw[dashed, uthickline] ([yshift=-1cm]node13.south) -- ([yshift=1cm]node33.north); +\draw[dashed, shorten >=5mm, shorten <=1cm, -Triangle, uthickline] (node13) -- (node25); +\draw[dashed, shorten >=5mm, shorten <=1cm, -Triangle, uthickline] (node33) -- (node25); + +\draw[Triangle-, thickline] (node21) -- ++(-2.7, 0){}; +\draw[Triangle-, thickline] (node21) -- ++(-2.7, 1){}; +\draw[Triangle-, thickline] (node21) -- ++(-2.7, -1){}; +\draw[Triangle-, thickline] (node22) -- ++(-5, 2){}; +\draw[Triangle-, thickline] (node22) -- ++(-5, -2){}; + +\draw[-Triangle, thickline] (node23) -- ++(2.7, -.9){}; +\draw[-Triangle, thickline] (node23) -- ++(2.7, -2.9){}; +\draw[-Triangle, thickline] (node24) -- ++(2.7, 1){}; +\draw[-Triangle, thickline] (node24) -- ++(2.7, 3){}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure5-11-dropout.tex b/tikz/figure5-11-dropout.tex new file mode 100644 index 0000000..535cd15 --- /dev/null +++ b/tikz/figure5-11-dropout.tex @@ -0,0 +1,111 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} + +\begin {document} +\begin{tikzpicture} + +% type of circles in every node +\def\circleorder{{{1,3,4,0},{2,4,3,0},{2,3,4,5},{1,3,3,0},{1,4,4,0}}} +\def\circleAorder{{{1,4,4,0},{1,4,4,0},{1,4,4,5},{1,4,4,0},{1,4,4,0}}} + +\newcommand\circlecolor[5] +{ + \node[#5, circle, minimum size = .7cm] (#4) at (#2,#3) {#1}; +} + +\newcommand\circlecross[4] +{ + \node[thickline, circle, minimum size = .7cm] (#4) at (#2,#3) {#1}; + \begin{scope} + \clip(#2, #3) circle(.5cm); + \draw[draw=border-red, ultra thick] (#2-1/2, #3+1/2) -- (#2+1/2, #3-1/2); + \draw[draw=border-red, ultra thick] (#2+1/2, #3+1/2) -- (#2-1/2, #3-1/2); + \end{scope} +} + +\foreach \i in {0,1,2,3,4} +{ + \foreach \j in {0,1,2,3} + { + \pgfmathparse{int(\i+1)} \edef\pval{\pgfmathresult}; + + %First set on the left + \pgfmathparse{int(\circleAorder[\i][\j])} \edef\acase{\pgfmathresult}; + + \IfEq{\acase}{1}% + { + \circlecolor{\Large $x_\pval$}{\j*2}{-\i*2}{A\i\j}{greenshape}; + }{} + \IfEq{\acase}{4}% + { + \circlecolor{}{\j*2}{-\i*2}{A\i\j}{blueshape}; + }{} + \IfEq{\acase}{5}% + { + \circlecolor{}{\j*2}{-\i*2}{A\i\j}{redshape}; + }{} + + %second set - on the right + \pgfmathparse{int(\circleorder[\i][\j])} \edef\pcase{\pgfmathresult}; + \IfEq{\pcase}{1}% + { + \circlecolor{\Large $x_\pval$}{10+\j*2}{-\i*2}{B\i\j}{greenshape}; + }{} + \IfEq{\pcase}{2}% + { + \circlecross{\Large $x_\pval$}{10+\j*2}{-\i*2}{B\i\j}; + }{} + \IfEq{\pcase}{3}% + { + \circlecross{}{10+\j*2}{-\i*2}{B\i\j}; + }{} + \IfEq{\pcase}{4}% + { + \circlecolor{}{10+\j*2}{-\i*2}{B\i\j}{blueshape}; + }{} + \IfEq{\pcase}{5}% + { + \circlecolor{}{10+\j*2}{-\i*2}{B\i\j}{redshape}; + }{} + } +} + +\foreach \i in {0,1,2,3,4} +{ + \foreach \j in {1,2,3} + { + \foreach \k in {0,1,2,3,4} + { + \pgfmathparse{int(\j-1)} \edef\in{\pgfmathresult}; + + %arrows for left set + \pgfmathparse{int(\circleAorder[\k][\j])} \edef\acp{\pgfmathresult}; + \ifthenelse{\acp=0}{} + { + \draw[-Triangle, line] (A\i\in) -- (A\k\j); + } + + %arrows for right set + \pgfmathparse{int(\circleorder[\i][\in])} \edef\cr{\pgfmathresult}; + \pgfmathparse{int(\circleorder[\k][\j])} \edef\cp{\pgfmathresult}; + \ifthenelse{\cr=1 \OR \cr=4 \OR \cr=5}{ + \ifthenelse{\cp=1 \OR \cp=4 \OR \cp=5}{ + \draw[-Triangle, line] (B\i\in) -- (B\k\j); + }{} + }{} + } + } +} + +\draw [-Triangle,line, double] ([xshift=.3cm]A23.east) -- ([xshift=-.3cm]B20.west) node[pos=.5, above] {\Large dropout}; + +\end{tikzpicture} + +\end {document} \ No newline at end of file diff --git a/tikz/figure5-2-a-realvalue_function_approximation.tex b/tikz/figure5-2-a-realvalue_function_approximation.tex new file mode 100644 index 0000000..ed3c653 --- /dev/null +++ b/tikz/figure5-2-a-realvalue_function_approximation.tex @@ -0,0 +1,38 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usepackage{arrayjob} + +\begin {document} + +\def\negationorder{{{"1","2","r-1"},{"0","1","r-2"}}} + +\begin{tikzpicture} + +% Layer A +\node[greenshape, circle, minimum size = 1cm] (layerA0) at (0,-5) {\large {$x$}}; + +% Layer B +\node[blueshape, circle, minimum size = 2.5cm] (layerB0) at (6, 0) {bias = $-u_1$}; +\node[blueshape, circle, minimum size = 2.5cm] (layerB1) at (6, -3) {bias = $-u_2$}; +\node[blueshape, circle, minimum size = 2.5cm] (layerB2) at (6, -10) {bias = $-u_{r-1}$}; + +%layer C +\draw [thick, dashed] ([yshift=-.3cm]layerB1.south) -- ([yshift=.3cm]layerB2.north); +\node[redshape, circle, minimum size = 1cm, align=center] (layerC0) at (12, -5) {\large {$\hat y$}}; + +%connecting between the nodes +\foreach \i in {0,1,2} +{ + \pgfmathparse{\negationorder[0][\i]} \edef\lsign{\pgfmathresult}; + \pgfmathparse{\negationorder[1][\i]} \edef\rsign{\pgfmathresult}; + + \draw[-Triangle, thickline] (layerA0) -- (layerB\i) node[pos=.5, above, sloped] {$w^{[1]}_{1,\lsign}=1$}; + \draw[-Triangle, thickline] (layerB\i) -- (layerC0) node[pos=.5, above, sloped] {$w^{[2]}_{\lsign,1}=s_{\lsign}-s_{\rsign}$}; +} + +\end{tikzpicture} +\end {document} \ No newline at end of file diff --git a/tikz/figure5-4-multiplication_gate.tex b/tikz/figure5-4-multiplication_gate.tex new file mode 100644 index 0000000..9ca4526 --- /dev/null +++ b/tikz/figure5-4-multiplication_gate.tex @@ -0,0 +1,65 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usepackage{arrayjob} + +\begin {document} + +% Layer A neurons'number +\newcommand{\numlayerA}{2} +\def\negationorder{{{" ","-"," ","-"},{" ","-","-"," "},{"+","-","-","+"},{"","","-","-"}}} + +% Layer B neurons'number +\newcommand{\numlayerB}{4} + +% Layer C neurons'number +\newcommand{\numlayerC}{1} + +\begin{tikzpicture} + +% Layer A +\foreach \i in {1,...,\numlayerA} +{ + \node[greenshape, circle, minimum size = 2cm] (layerA\i) at (0,-\i*4) {\large {$x_\i$}}; +} + +% Layer B +\foreach \i in {1,...,\numlayerB} +{ + \pgfmathparse{\negationorder[0][\i-1]} \edef\lsign{\pgfmathresult} + \pgfmathparse{\negationorder[2][\i-1]} \edef\rsign{\pgfmathresult} + + \node[blueshape, circle, minimum size = 3cm] (layerB\i) at (7, 4-\i*4) {$\sigma^{[1]}( \lsign \lambda x_1 \rsign \lambda x_2) $}; +} + +% Layer C +\foreach \i in {1,...,\numlayerC} +{ + \node[redshape, circle, minimum size = 2cm] (layerC\i) at (13,-6) {$\hat{y}=f_\theta(x_1, x_2)$}; +} + +%connect Layer A and Layer B +\foreach \i in {1,...,\numlayerA} +{ + \foreach \j in {1,...,\numlayerB} + { + \pgfmathparse{\negationorder[\i-1][\j-1]} \edef\lsign{\pgfmathresult} + \draw[-Triangle, thickline] (layerA\i) -- (layerB\j) node[pos=.8, above, sloped] {$w_{\j, \i}^{[1]} = \lsign \lambda$}; + } +} + +%connect Layer B and Layer C +\foreach \i in {1,...,\numlayerB} +{ + \foreach \j in {1,...,\numlayerC} + { + \pgfmathparse{\negationorder[3][\i-1]} \edef\lsign{\pgfmathresult} + \draw[-Triangle, thickline] (layerB\i) -- (layerC\j) node[pos=.6, above, sloped] {$w_{1, \i}^{[2]} = \lsign \mu $}; + } +} + +\end{tikzpicture} +\end {document} \ No newline at end of file diff --git a/tikz/figure5-5-deep_polynomial_model.tex b/tikz/figure5-5-deep_polynomial_model.tex new file mode 100644 index 0000000..e532fc3 --- /dev/null +++ b/tikz/figure5-5-deep_polynomial_model.tex @@ -0,0 +1,53 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} + +\begin {document} + +\newcommand{\columns}{10} +\newcommand{\mcolumns}{9} +\newcommand{\rows}{3} + +\begin{tikzpicture} + +\node[greenshape, circle, minimum size = 1cm] (column-01) at (0,-.5) {$x_1$}; +\node[greenshape, circle, minimum size = 1cm] (column-02) at (0,-2) {$x_2$}; +\node[greenshape, circle, minimum size = 1cm] (column-03) at (0,-4.5) {$x_{1000}$}; +\node[redshape, circle, minimum size = 1cm] (column-111) at (22,-2) {$\hat y$}; + +% Layer B +\foreach \i in {1,...,\columns} +{ + \foreach \j in {1,...,\rows} + { + \node[blueshape, circle, minimum size = 1cm] (column-\i\j) at (\i*2,-\j*\j/2) {}; + } +} + +\foreach \i [evaluate=\i as \in using int(\i+1) ] in {0,...,\mcolumns} +{ + \foreach \j in {1,...,\rows} + { + \foreach \k in {1,...,\rows} + { + \draw[-Triangle, thickline] (column-\i\j) -- (column-\in\k); + } + } +} + +\foreach \j in {1,...,\rows} +{ + \draw[-Triangle, thickline] (column-10\j) -- (column-111); +} + +\foreach \i in {0,...,\columns} +{ + \draw[thick, dashed] ([yshift=-3mm]column-\i2.south) -- ([yshift=3mm]column-\i3.north); +} + +\end{tikzpicture} + +\end {document} \ No newline at end of file diff --git a/tikz/figure5-7-initial_gradient_values.tex b/tikz/figure5-7-initial_gradient_values.tex new file mode 100644 index 0000000..c059d8a --- /dev/null +++ b/tikz/figure5-7-initial_gradient_values.tex @@ -0,0 +1,79 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +%Nodes +\matrix[row sep=2.2cm,column sep=2cm] (m1) { + & + \node [align=center, xshift=-.5cm] (node11) {\large $\theta^{[1]}$}; & + \node [align=center, xshift=-.5cm] (node12) {\large $\theta^{[2]}$}; & + \node [align=center, xshift=-.5cm] (node13) {\large $\theta^{[L-1]}$}; & + \node [align=center, xshift=-.5cm] (node14) {\large $\theta^{[L]}$}; & + \\ + \node [align=center] (node20) {\large $x = a^{[0]}$}; & + \node [align=center] (node21) {\large $a^{[1]}$}; & + \node [align=center] (node22) {\large $a^{[2]}$}; & + \node [align=center] (node23) {\large $a^{[L-1]}$}; & + \node [align=center] (node24) {\large $a^{[L]}$}; & + \\ + & + \node [align=center, xshift=-.5cm] (node31) {\large $\zeta^{[1]}$}; & + \node [align=center, xshift=-.5cm] (node32) {\large $\zeta^{[2]}$}; & + \node [align=center, xshift=-.5cm] (node33) {\large $\zeta^{[L-1]}$}; & + \node [align=center, xshift=-.5cm] (node34) {\large $\zeta^{[L]}$}; & + \\ + & + \node [align=center] (node41) {\large $\,\, g_{\theta}^{[1]}$}; & + \node [align=center] (node42) {\large $\,\, g_{\theta}^{[2]}$}; & + \node [align=center] (node43) {\large $\,\, g_{\theta}^{[L-1]}$}; & + \node [align=center] (node44) {\large $\,\, g_{\theta}^{[L]}$}; & + \\ + }; + +\draw [dashed] ([xshift=.5cm]node12.east) -- ([xshift=-.5cm]node13.west) node[] {}; +\draw [dashed] ([xshift=.5cm]node22.east) -- ([xshift=-.5cm]node23.west) node[] {}; +\draw [dashed] ([xshift=.5cm]node32.east) -- ([xshift=-.5cm]node33.west) node[] {}; +\draw [dashed] ([xshift=.5cm]node42.east) -- ([xshift=-.5cm]node43.west) node[] {}; + +\draw [-Triangle, thickline] ([xshift=1.8cm]node20.west) -- ([xshift=-1.2cm]node21.east); +\draw [-Triangle, thickline] ([xshift=1.1cm]node21.west) -- ([xshift=-1.1cm]node22.east); +\draw [-Triangle, thickline] ([xshift=1.4cm]node23.west) -- ([xshift=-1.4cm]node24.east); + +\draw [-Triangle, thickline] ([xshift=-.5cm]node32.west) -- ([xshift=.5cm]node31.east); +\draw [-Triangle, thickline] ([xshift=-.5cm]node34.west) -- ([xshift=.5cm]node33.east); + +\draw [-Triangle, thickline] ([yshift=-2mm]node11.south) -- ([yshift=2mm]node21.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node12.south) -- ([yshift=2mm]node22.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node13.south) -- ([yshift=2mm]node23.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node14.south) -- ([yshift=2mm]node24.north); + +\draw [-Triangle, thickline] ([yshift=-2mm]node31.south) -- ([yshift=2mm]node41.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node32.south) -- ([yshift=2mm]node42.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node33.south) -- ([yshift=2mm]node43.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node34.south) -- ([yshift=2mm]node44.north); + + +\node[below right = .7cm and -10cm of m1, align=center] {\large Gradient Values}; +\node[above right = .7cm and -10cm of m1, align=center] {\large Parameter Values}; + +\node[below right = 0mm and 1mm of node22, align=center] (textforward) {\large Forward}; +\node[above right = 0mm and 5mm of node32, align=center] {\large Backward}; + +\node[rounded corners, bthickline, below right = 9mm and 1cm of node24] (nodec) {\large Loss : $C$}; +\node[above left = 1.5cm and -1.85cm of nodec.west] (nodey) {\large $y, \, \hat{y}$}; +\draw [-Triangle, thickline] ([yshift=-2mm]nodey.south) -- ([yshift=2mm, xshift=5mm]nodec.north); + +\path (node24.east)edge [-Triangle, thickline, out=0,in=90] node [midway, anchor=center] {} (nodec.north); + +\path (nodec.south)edge [-Triangle, thickline, out=270,in=0] node [midway, anchor=center] {} (node34.east); + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure5-8-scalar_hidden_units.tex b/tikz/figure5-8-scalar_hidden_units.tex new file mode 100644 index 0000000..07c2f88 --- /dev/null +++ b/tikz/figure5-8-scalar_hidden_units.tex @@ -0,0 +1,50 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{xfp} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit} +\usepackage{amsmath,amsfonts,xstring} + +\begin{document} +\begin{tikzpicture} + +\newcommand\semicircleunit[4] +{ + \node [lightblueshape, bthickline, circle, minimum size = #3cm] (circle#4) at (#1,#2){}; + \draw [bthickline](#1-.4,#2+#3/2.05) -- (#1-.4,#2-#3/2.05); + + \pgfmathparse{int(#4-1)} \edef\prev{\pgfmathresult} + \IfEq{\prev}{0}% + { + \node[above left = .1cm and 1.5cm of circle#4, align=center,font=\boldmath] (text2#4) {\large $\theta^{[#4]} \in \mathbb R^p$}; + \node[left of=circle#4, node distance=1.2cm, align=center, text=black,font=\boldmath] (text1#4) {$\theta^{{[#4]}^\top}x$}; + \node[below right=-2cm and -2cm of circle#4, align=center, text=black,font=\boldmath] (text1#4) { $\underbrace{\sigma^{[#4]}(\theta^{{[#4]}^\top}a^{[\prev]})}$ \\ $a^{[#4]}$}; + } + { + \node[above left = .1cm and 1.5cm of circle#4, align=center,font=\boldmath] (text2#4) {\large $\theta^{[#4]} \in \mathbb R$}; + \node[left of=circle#4, node distance=1.2cm, align=center, text=black,font=\boldmath] (text1#4) {$\theta^{{[#4]}}a^{[\fpeval{#4-1}]}$}; + \IfEq{\prev}{3}% + { + \node[below right=-2cm and -1.5cm of circle#4, align=center, text=black,font=\boldmath] (text1#4) { $\underbrace{\theta^{{[#4]}}a^{[\prev]}}$ \\ $\hat y=a^{[#4]}$}; + } + { + \node[below right=-2cm and -1.8cm of circle#4, align=center, text=black,font=\boldmath] (text1#4) { $\underbrace{\sigma^{[#4]}(\theta^{{[#4]}}a^{[\prev]})}$ \\ $a^{[#4]}$}; + } + } + + \draw [-Triangle, thickline] (circle#4.west)+(-2.3cm,0) -- ([xshift=-.2cm]circle#4.west); + \draw [-Triangle, thickline] (text2#4) -- ++(0, -1.7cm); + +} + +\node[align=center] (circle0) at (-5.5,-.35) {\Large $\underbrace{x}_{\huge {\in \mathbb R^p}}$}; +\semicircleunit{0}{0}{4.5}{1}; +\semicircleunit{7}{0}{4.5}{2}; +\semicircleunit{14}{0}{4.5}{3}; +\semicircleunit{21}{0}{4.5}{4}; +\draw [-Triangle, thickline] (text24) -- ++(0, -1.7cm); +\draw [-Triangle, thickline] (circle4.east) -- ++(+2cm, 0); +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure5-9-advanced_gradient_values.tex b/tikz/figure5-9-advanced_gradient_values.tex new file mode 100644 index 0000000..aa5715e --- /dev/null +++ b/tikz/figure5-9-advanced_gradient_values.tex @@ -0,0 +1,85 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +%Nodes +\matrix[row sep=2cm,column sep=1.8cm] (m1) { + \node [align=center, xshift=-.5cm] (node11) {\large $W^{[1]},b^{[1]}$}; & + \node [align=center, xshift=-.5cm] (node12) {\large $W^{[2]},b^{[2]}$}; & + \node [align=center, xshift=-.5cm] (node13) {\large $W^{[L-1]},b^{[L-1]}$}; & + \node [align=center, xshift=-.5cm] (node14) {\large $W^{[L]},b^{[L]}$}; & + \\ + \node [align=center] (node21) {\large $z^{[1]}$}; & + \node [align=center] (node22) {\large $z^{[2]}$}; & + \node [align=center] (node23) {\large $z^{[L-1]}$}; & + \node [align=center] (node24) {\large $z^{[L]}$}; & + \\ + \node [align=center, xshift=-.5cm] (node31) {\large $\delta^{[1]}$}; & + \node [align=center, xshift=-.5cm] (node32) {\large $\delta^{[2]}$}; & + \node [align=center, xshift=-.5cm] (node33) {\large $\delta^{[L-1]}$}; & + \node [align=center, xshift=-.5cm] (node34) {\large $\delta^{[L]}$}; & + \\ + \node [align=center] (node41) {\large ($g^{[1]}_W,g^{[1]}_b$)}; & + \node [align=center] (node42) {\large ($g^{[2]}_W,g^{[2]}_b$)}; & + \node [align=center] (node43) {\large ($g^{[L-1]}_W,g^{[L-1]}_b$)}; & + \node [align=center] (node44) {\large ($g^{[L]}_W,g^{[L]}_b$)}; & + \\ + }; + +\node [left of = node21, node distance = 2.5cm] (node20) {\large $x = a^{[0]}$}; +\node [right of = node21, node distance = 2cm] (node21_1) {\large $a^{[1]}$}; +\node [right of = node22, node distance = 1.6cm] (node22_1) {\large $a^{[2]}$}; +\node [right of = node23, node distance = 2.2cm] (node23_1) {\large $a^{[L-1]}$}; +\node [right of = node24, node distance = 1.8cm] (node24_1) {\large $a^{[L]}$}; + +\draw [-Triangle, thickline] ([xshift=1.5cm]node20.west) -- ([xshift=-.9cm]node21.east); +\draw [-Triangle, thickline] ([xshift=.8cm]node21.west) -- ([xshift=-.8cm]node21_1.east); +\draw [-Triangle, thickline] ([xshift=.8cm]node21_1.west) -- ([xshift=-.8cm]node22.east); +\draw [-Triangle, thickline] ([xshift=.8cm]node22.west) -- ([xshift=-.8cm]node22_1.east); +\draw [-Triangle, thickline] ([xshift=1.2cm]node23.west) -- ([xshift=-1.2cm]node23_1.east); +\draw [-Triangle, thickline] ([xshift=1.2cm]node23_1.west) -- ([xshift=-.8cm]node24.east); +\draw [-Triangle, thickline] ([xshift=.8cm]node24.west) -- ([xshift=-.8cm]node24_1.east); + +\draw [dashed] ([xshift=.5cm]node12.east) -- ([xshift=-.5cm]node13.west) node[] {}; +\draw [dashed] ([xshift=.1cm]node22_1.east) -- ([xshift=-.1cm]node23.west) node[] {}; +\draw [dashed] ([xshift=.5cm]node32.east) -- ([xshift=-.5cm]node33.west) node[] {}; +\draw [dashed] ([xshift=.5cm]node42.east) -- ([xshift=-.5cm]node43.west) node[] {}; + +\draw [-Triangle, thickline] ([xshift=-.5cm]node32.west) -- ([xshift=.5cm]node31.east); +\draw [-Triangle, thickline] ([xshift=-.5cm]node34.west) -- ([xshift=.5cm]node33.east); + +\draw [-Triangle, thickline] ([yshift=-2mm]node11.south) -- ([yshift=2mm]node21.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node12.south) -- ([yshift=2mm]node22.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node13.south) -- ([yshift=2mm]node23.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node14.south) -- ([yshift=2mm]node24.north); + +\draw [-Triangle, thickline] ([yshift=-2mm]node31.south) -- ([yshift=2mm]node41.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node32.south) -- ([yshift=2mm]node42.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node33.south) -- ([yshift=2mm]node43.north); +\draw [-Triangle, thickline] ([yshift=-2mm]node34.south) -- ([yshift=2mm]node44.north); + + +\node[below right = .7cm and -10.5cm of m1, align=center] {\large Gradient Values}; +\node[above right = .7cm and -11cm of m1, align=center] {\large Parameter Values}; + +\node[below right = 0mm and 10mm of node22, align=center] (textforward) {\large Forward}; +\node[above right = 0mm and 15mm of node32, align=center] {\large Backward}; + +\node[rounded corners, bthickline, below right = .8cm and 2cm of node24] (nodec) {\large Loss : $C$}; +\node[above left = 2cm and -1.85cm of nodec.west] (nodey) {\large $y, \, \hat{y}$}; +\draw [-Triangle, thickline] ([yshift=-2mm]nodey.south) -- ([yshift=2mm, xshift=5mm]nodec.north); + +\path (node24_1.east)edge [-Triangle, thickline, out=0,in=90] node [midway, anchor=center] {} (nodec.north); + +\path (nodec.south)edge [-Triangle, thickline, out=270,in=0] node [midway, anchor=center] {} (node34.east); + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure6-10-output-channels.tex b/tikz/figure6-10-output-channels.tex new file mode 100644 index 0000000..91f1471 --- /dev/null +++ b/tikz/figure6-10-output-channels.tex @@ -0,0 +1,75 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\begin {document} + +\begin{tikzpicture}%[fontsize=24pt] + +\begin{scope} +\newcommand\slantarray[8]{ + \draw[#6, line width=#7] (#1,#2) grid (#1+#3+1, #2-#4-1) rectangle (#1,#2); + \pgfmathparse{#1+((#3+1)/2)}\edef\ni{\pgfmathresult}; + \pgfmathparse{#2-#4-1.6}\edef\nj{\pgfmathresult}; + \node[] at(\ni,\nj){\huge $#8$}; +} + +\newcommand\matrixset[9]{ + \draw[#5, line width=2] (#1,#2) grid (#1+#3+1, #2-#3-1) rectangle (#1,#2); + \draw[#6, line width=2] (#1-1,#2-1) grid (#1+#3, #2-#3-2) rectangle (#1-1,#2-1); + \draw[#7, line width=2] (#1-2,#2-2) grid (#1+#3-1, #2-#3-3) rectangle (#1-2,#2-2); + \draw[Triangle-Triangle, thickline] (#1-2, #2-#3-4) -- (#1+#3-1, #2-#3-4) node [midway,anchor=center, fill=white] {\Huge $#9_v$}; + \draw[Triangle-Triangle, thickline] (#1-3, #2-2) -- (#1-3, #2-#3-3) node [midway,anchor=center, fill=white] {\Huge $#9_h$}; + \draw[Triangle-Triangle, thickline] (#1+#3-.5, #2-#3-3.5) -- (#1+#3+1.5, #2-#3-1.5) node [midway,anchor=center, fill=white] {\Huge $#9_c$}; + \ifthenelse{#3=8} + { \node at (#1+#3-12.5, #2-#3/2-2.5) {\Huge $\star$}; } {} + \pgfmathparse{#1-2+((#3+1)/2)}\edef\ni{\pgfmathresult}; + \pgfmathparse{#2-5.3-#3}\edef\nj{\pgfmathresult}; + \node[] at(\ni,\nj-0.2){\huge $#8$}; +} + +\newcommand\matrixsett[9]{ + \draw[#5, line width=2] (#1,#2) grid (#1+#3+1, #2-#3-1) rectangle (#1,#2); + \draw[#6, line width=2] (#1-1,#2-1) grid (#1+#3, #2-#3-2) rectangle (#1-1,#2-1); + \draw[#7, line width=2] (#1-2,#2-2) grid (#1+#3-1, #2-#3-3) rectangle (#1-2,#2-2); + \ifthenelse{#3=8} + { \node at (#1+#3-12, #2-#3/2-2.5) {\Huge $\star$}; } {} + \pgfmathparse{#1-2+((#3+1)/2)}\edef\ni{\pgfmathresult}; + \pgfmathparse{#2-5.3-#3}\edef\nj{\pgfmathresult}; + \node[] at(\ni,\nj+0.5){\huge $#8$}; +} + +\matrixset{8}{0}{8}{}{blueshape}{greenshape}{redshape}{x}{M^{[0]}}; +\matrixset{-1}{2}{2}{[1]}{blueshape}{greenshape}{redshape}{W_{(1)}}{K}; +\matrixset{-1}{-8}{2}{[2]}{blueshape}{greenshape}{redshape}{W_{(2)}}{K}; +\draw[greylayer] (-5,4) rectangle ++(23,-20); + +\matrixsett{35}{9}{8}{[1]}{blueshape}{greenshape}{redshape}{x}{M^{[0]}}; +\matrixsett{26}{6}{2}{[1]}{blueshape}{greenshape}{redshape}{W_{(1)}}{K}; +\draw[greylayer] (22,11) rectangle ++(23,-16); + +\matrixsett{35}{-8}{8}{[2]}{blueshape}{greenshape}{redshape}{x}{M^{[0]}}; +\matrixsett{26}{-11}{2}{[2]}{blueshape}{greenshape}{redshape}{W_{(2)}}{K}; +\draw[greylayer] (22,-7) rectangle ++(23,-15); + +\draw[greylayer] (21,12) rectangle ++(25,-35); + +\node at (19.5,-5.5) {\Huge =}; +\node at (48,-5.5) {\Huge =}; +\node at (54,-10.5) {\Huge $W \star x$}; + +\slantarray{51}{-2}{6}{5}{0}{tealshape}{2}{}; +\slantarray{50}{-3}{6}{5}{0}{yellowshape}{2}{}; + +\draw[greylayer] (49,-1) rectangle ++(10,-9); + +\path (47,4) edge [-Triangle, thickline, out=0,in=90, looseness=1.5] node [] {} (54, -1.8); +\path (47,-15) edge [-Triangle, thickline, out=0,in=270, looseness=1.5] node [] {} (52, -9.2); + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-11-a-max-pooling.tex b/tikz/figure6-11-a-max-pooling.tex new file mode 100644 index 0000000..5cfda09 --- /dev/null +++ b/tikz/figure6-11-a-max-pooling.tex @@ -0,0 +1,98 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usepackage{etoolbox} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds, shapes} + +\pgfdeclarelayer{layer1} +\pgfdeclarelayer{layer2} +\pgfdeclarelayer{layer3} +\pgfdeclarelayer{layer4} +\pgfsetlayers{layer4,layer3,layer2,layer1} + +\def\arrayA{ + { + %Array x + { + {2, 4, 10, 13}, {6, -4, 3, -2}, {7, -2, 0, -11}, {8, 3, -1, 0} + }, + %Array z + { + {6,13}, {8,0} + } + } +} + +\begin {document} + +\newcommand\fillnumbers[4]{ + \foreach \i in {0,...,#3}{ + \foreach \j in {0,...,#3}{ + \pgfmathparse{int(\arrayA[#4][\j][\i])} \edef\ele{\pgfmathresult}; + \node[thick] at (#1+.5+\i,#2-.5-\j) {$\ele$}; + } + } +} + +\newcommand\slantarray[8]{ + \draw[#6, line width=#7, opacity=0.8] (#1,#2) grid (#1+#3+1, #2-#4-1); + \pgfmathparse{#1+((#3+1)/2)}\edef\ni{\pgfmathresult}; + \pgfmathparse{#2-#4-1.8}\edef\nj{\pgfmathresult}; + \node[#6] at(\ni,\nj){\huge $#8$}; +} + +\newcommand\lines[8]{ + \draw[#7, dashed, ultra thick, opacity=0.8] (#1,#2) -- (#3,#4); + \draw[#7, dashed, ultra thick, opacity=0.8] (#1+#5,#2) -- (#3+#6,#4); + \draw[#7, dashed, ultra thick, opacity=0.8] (#1,#2-#5) -- (#3,#4-#6); + \draw[#7, dashed, ultra thick, opacity=0.8] (#1+#5,#2-#5) -- (#3+#6,#4-#6); +} + +\newcommand\fillbg[6]{ + \begin{scope} + \node[rectangle,uthickline, minimum size=1cm,fill=#5, draw=#5] at (#1+.5+#3,#2-.5-#4){#6}; + \end{scope} +} + +\begin{tikzpicture}[remember picture, every node/.style={minimum size=1cm},on grid] + +\begin{scope}[every node/.append style={yslant=0.3},yslant=0.3] + +\begin{pgfonlayer}{layer4} + \slantarray{0}{0}{3}{3}{0}{border-grey}{2}{x}; + \fillnumbers{0}{0}{3}{0}; +\end{pgfonlayer} + +\begin{pgfonlayer}{layer3} + \slantarray{2}{0}{1}{1}{1}{fill-red}{3}{}; + \lines{2}{0}{8}{-5}{2}{1}{border-red}{border-red}; + + \slantarray{2}{-2}{1}{1}{1}{fill-yellow}{3}{}; + \lines{2}{-2}{8}{-6}{2}{1}{border-yellow}{border-yellow}; +\end{pgfonlayer} + +\begin{pgfonlayer}{layer2} + \slantarray{0}{0}{1}{1}{0}{fill-blue}{3}{}; + \lines{0}{0}{7}{-5}{2}{1}{border-blue}{border-blue}; + + \slantarray{0}{-2}{1}{1}{1}{fill-green}{3}{}; + \lines{0}{-2}{7}{-6}{2}{1}{border-green}{border-green}; +\end{pgfonlayer} + +\begin{pgfonlayer}{layer1} + \slantarray{7}{-5}{1}{1}{1}{border-grey}{2}{z}; + \fillbg{7}{-6}{0}{0}{fill-green}{}; + \fillbg{7}{-5}{0}{0}{fill-blue}{}; + \fillbg{8}{-6}{0}{0}{fill-yellow}{}; + \fillbg{8}{-5}{0}{0}{fill-red}{}; + \fillnumbers{7}{-5}{1}{1}; +\end{pgfonlayer} + + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-11-b-average-pooling.tex b/tikz/figure6-11-b-average-pooling.tex new file mode 100644 index 0000000..bf72808 --- /dev/null +++ b/tikz/figure6-11-b-average-pooling.tex @@ -0,0 +1,98 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usepackage{etoolbox} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds, shapes} + +\pgfdeclarelayer{layer1} +\pgfdeclarelayer{layer2} +\pgfdeclarelayer{layer3} +\pgfdeclarelayer{layer4} +\pgfsetlayers{layer4,layer3,layer2,layer1} + +\def\arrayA{ + { + %Array x + { + {2, 4, 10, 13}, {6, -4, 3, -2}, {7, -2, 0, -11}, {8, 3, -1, 0} + }, + %Array z + { + {2, 6}, {4, -3} + } + } +} + +\begin {document} + +\newcommand\fillnumbers[4]{ + \foreach \i in {0,...,#3}{ + \foreach \j in {0,...,#3}{ + \pgfmathparse{int(\arrayA[#4][\j][\i])} \edef\ele{\pgfmathresult}; + \node[thick] at (#1+.5+\i,#2-.5-\j) {$\ele$}; + } + } +} + +\newcommand\slantarray[8]{ + \draw[#6, line width=#7, opacity=0.8] (#1,#2) grid (#1+#3+1, #2-#4-1); + \pgfmathparse{#1+((#3+1)/2)}\edef\ni{\pgfmathresult}; + \pgfmathparse{#2-#4-1.8}\edef\nj{\pgfmathresult}; + \node[#6] at(\ni,\nj){\huge $#8$}; +} + +\newcommand\lines[8]{ + \draw[#7, dashed, ultra thick, opacity=0.8] (#1,#2) -- (#3,#4); + \draw[#7, dashed, ultra thick, opacity=0.8] (#1+#5,#2) -- (#3+#6,#4); + \draw[#7, dashed, ultra thick, opacity=0.8] (#1,#2-#5) -- (#3,#4-#6); + \draw[#7, dashed, ultra thick, opacity=0.8] (#1+#5,#2-#5) -- (#3+#6,#4-#6); +} + +\newcommand\fillbg[6]{ + \begin{scope} + \node[rectangle,uthickline, minimum size=1cm,fill=#5, draw=#5] at (#1+.5+#3,#2-.5-#4){#6}; + \end{scope} +} + +\begin{tikzpicture}[remember picture, every node/.style={minimum size=1cm},on grid] + +\begin{scope}[every node/.append style={yslant=0.3},yslant=0.3] + +\begin{pgfonlayer}{layer4} + \slantarray{0}{0}{3}{3}{0}{border-grey}{2}{x}; + \fillnumbers{0}{0}{3}{0}; +\end{pgfonlayer} + +\begin{pgfonlayer}{layer3} + \slantarray{2}{0}{1}{1}{1}{fill-red}{3}{}; + \lines{2}{0}{8}{-5}{2}{1}{border-red}{border-red}; + + \slantarray{2}{-2}{1}{1}{1}{fill-yellow}{3}{}; + \lines{2}{-2}{8}{-6}{2}{1}{border-yellow}{border-yellow}; +\end{pgfonlayer} + +\begin{pgfonlayer}{layer2} + \slantarray{0}{0}{1}{1}{0}{fill-blue}{3}{}; + \lines{0}{0}{7}{-5}{2}{1}{border-blue}{border-blue}; + + \slantarray{0}{-2}{1}{1}{1}{fill-green}{3}{}; + \lines{0}{-2}{7}{-6}{2}{1}{border-green}{border-green}; +\end{pgfonlayer} + +\begin{pgfonlayer}{layer1} + \slantarray{7}{-5}{1}{1}{1}{border-grey}{2}{z}; + \fillbg{7}{-6}{0}{0}{fill-green}{}; + \fillbg{7}{-5}{0}{0}{fill-blue}{}; + \fillbg{8}{-6}{0}{0}{fill-yellow}{}; + \fillbg{8}{-5}{0}{0}{fill-red}{}; + \fillnumbers{7}{-5}{1}{1}; +\end{pgfonlayer} + + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-13-inception-module.tex b/tikz/figure6-13-inception-module.tex new file mode 100644 index 0000000..5fe92ef --- /dev/null +++ b/tikz/figure6-13-inception-module.tex @@ -0,0 +1,70 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\begin {document} + +\begin{tikzpicture}[node distance=3.5cm] + +\tikzstyle{red_rect} = [redshape, text = black, minimum width=1.6cm, align=center] +\tikzstyle{blue_rect} = [blueshape, text = black, minimum width=1.6cm, align=center] +\tikzstyle{green_rect} = [greenshape, text = black, minimum width=1.6cm, align=center] + + +\newcommand\cube[9] +{ +\filldraw[fill=#7, draw=#8] (#1+#4,#2,#3) -- (#1+#4,#2+#5,#3) -- (#1,#2+#5,#3) -- (#1,#2,#3) -- cycle; +\filldraw[fill=#7, draw=#8] (#1+#4,#2,#3) -- (#1+#4,#2,#3+#6) -- (#1+#4,#2+#5,#3+#6) -- (#1+#4,#2+#5,#3) -- cycle; +\filldraw[fill=#7, draw=#8] (#1+#4,#2+#5,#3) -- (#1,#2+#5,#3) -- (#1,#2+#5,#3+#6) -- (#1+#4,#2+#5,#3+#6) -- cycle; +\node at (#1+#4+.25, #2+#5/2-.5, #3+#6/2) {\tiny $#9$}; +} + +\begin{scope} +\sffamily + +%nodes +\node[green_rect] (node-11) {Previous \\activations}; +\node[blue_rect,right of = node-11, node distance = 3cm, ,yshift=+0.5cm] (node-21) { $1 \times 1$\\Conv}; +\node[blue_rect, below of = node-21, node distance = 2cm, align=center] (node-22) { $1 \times 1$\\Conv}; +\node[red_rect, below of = node-22, node distance = 2cm, draw, align=center] (node-23) { $3 \times 3$\\ Max-pooling}; %,s=1\\same}; + +\node[blue_rect,right of = node-21, node distance = 4cm, draw, align=center] (node-31) { $3 \times 3$\\Conv}; +\node[blue_rect,right of = node-22, node distance = 4cm, draw, align=center] (node-32) { $5 \times 5$\\Conv}; +\node[blue_rect,right of = node-23, node distance = 4cm, draw, align=center] (node-33) { $1 \times 1$\\Conv}; +\node[blue_rect,above of = node-31, node distance = 2.5cm, draw, align=center] (node-34) { $1 \times 1$\\Conv}; + +\node[right of = node-32, yshift= -2cm,align=center,node distance = 4.5cm] (node-44) {Channel concatenation}; + +%Arrows +\draw[-Triangle, thickline](node-11)--(node-21); +\draw[-Triangle, thickline](node-11)--(node-22); +\draw[-Triangle, thickline](node-11)--(node-23); +\draw[-Triangle, thickline](node-11)edge[bend left=30](node-34); +\draw[-Triangle, thickline](node-21)--(node-31) node[below, pos=.5] {\scriptsize $96 \times 28 \times 28$}; +\draw[-Triangle, thickline](node-22)--(node-32) node[below, pos=.5] {\scriptsize $16 \times 28 \times 28$}; +\draw[-Triangle, thickline](node-23)--(node-33) node[below, pos=.5] {\scriptsize $192 \times 28\times28$} ; + +\draw[-Triangle, thickline](node-34)--(11.6,-0.2)node[above, pos=.5, sloped] {\scriptsize $64\times 28\times 28$} ; +\draw[-Triangle, thickline](node-31)--(11.1,-0.65) node[above, pos=.5, sloped] {\scriptsize $128 \times 28\times28$} ; +\draw[-Triangle, thickline](node-32)--(10.65, -1.1) node[above, pos=.5, sloped] {\scriptsize $32 \times 28\times28$}; +\draw[-Triangle, thickline](node-33)--(10.4, -1.9) node[above, pos=.5, sloped] {\scriptsize $32 \times 28\times28$}; + + +\cube{10}{-3}{-4}{1.2}{1}{-1}{border-green}{fill-grey}{64} +\cube{10}{-3}{-2.5}{1.2}{1}{-1.5}{fill-green}{fill-grey}{128} +\cube{10}{-3}{-2}{1.2}{1}{-.5}{border-light-green}{fill-grey}{32} +\cube{10}{-3}{-1.5}{1.2}{1}{-.5}{fill-light-green}{fill-grey}{32} + +\node at (11.15, -1.95) {\tiny $28 \times 28$}; +%\node at (10.25, -2) {\tiny $28$}; + +\node[below of = node-11, node distance=1cm, xshift= -0.7cm] {\scriptsize $192 \times 28 \times 28$}; +\node[above of = node-44, node distance=0.5cm] {\scriptsize $256 \times 28 \times 28$}; + +\end{scope} +\end{tikzpicture} +\end {document} \ No newline at end of file diff --git a/tikz/figure6-14-resnet.tex b/tikz/figure6-14-resnet.tex new file mode 100644 index 0000000..addf1d0 --- /dev/null +++ b/tikz/figure6-14-resnet.tex @@ -0,0 +1,51 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds, shapes} + +\tikzstyle{yellow_rect} = [yellowshape,text = black, minimum width=3cm, ultra thick, align=center] +\tikzstyle{blue_rect} = [blueshape, text = black, minimum width=3cm, ultra thick, align=center] +\tikzstyle{green_rect} = [greenshape, ultra thick, text = black, minimum width=3cm, align=center] + +\begin {document} + +\newcommand\flow[2]{ +\node[blue_rect] (node#1-1) at (#2, 0) {ReLU}; +\node[circle, blueshape, text = white, align=center, below of = node#1-1] (node#1-2) {+}; +\node[green_rect, below of = node#1-2] (node#1-3) {Convolution}; +\node[below of = node#1-2, node distance=2.2cm] (node#1-3-1) {}; +\node[below of = node#1-2, node distance=3.2cm] (node#1-3-2) {}; +\node[blue_rect, below of = node#1-3, node distance=3cm] (node#1-4) {ReLU}; +\node[green_rect, below of = node#1-4, node distance=0.54cm] (node#1-5) {Convolution}; +\node[below of = node#1-5, node distance=1.5cm] (node#1-6) {\Large $u = a^{[\ell]}$}; +\node[above of = node#1-1, node distance=1cm] (node#1-7) {\Large $a^{[\ell + \tilde{\ell}]}$}; +\node[left of = node#1-3-2, node distance=3cm] (node#1-7) {\Large $r(u)$}; + +\draw[-Triangle, uthickline] (node#1-1) -- ++(0, .7); +\draw[-Triangle, uthickline] (node#1-2) -- (node#1-1); +\draw[-Triangle, uthickline] (node#1-3) -- (node#1-2); +\draw[-Triangle, dashed, uthickline] (node#1-4) -- (node#1-3); +\draw[-Triangle, uthickline] (node#1-3-1) -- (node#1-3); +\draw[-Triangle, uthickline] (node#1-4) -- (node#1-3-2); +\draw[-Triangle, uthickline] (node#1-6) -- (node#1-5); + +\draw[decorate, decoration={calligraphic brace,amplitude=5pt}, pen colour={black!50}, ultra thick, rotate=0] (-1.7,-6.5) -- (-1.7,-2) node[above left =.25cm and .7cm]{}; +} + +\begin{tikzpicture}[node distance=1.2cm] +\sffamily +\flow{1}{0} +%\flow{2}{8} +%\node[green_rect, right of = node2-5, node distance=4cm] (node3-5) {1 x 1 Conv}; + +%\draw[-Triangle, uthickline] ([yshift=3mm]node2-8.north) -| (node3-5); +%\draw[-Triangle, uthickline] (node3-5) |- (node2-2); +\draw[-Triangle, uthickline] ([yshift=3mm]node1-6.north) -| ++(2.5cm, 0) |- (node1-2); + + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-2-vgg19.tex b/tikz/figure6-2-vgg19.tex new file mode 100644 index 0000000..3e17f41 --- /dev/null +++ b/tikz/figure6-2-vgg19.tex @@ -0,0 +1,134 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usepackage{geometry} +\usepackage{graphicx} + +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds,3d} + +\graphicspath{ {./images/} } + +\def\outputs{{0,1000,999,2,1}} + +\begin {document} +\begin{tikzpicture} + +\newcommand\cube[7] +{ +\filldraw[#7] (#1+#4,#2,#3) -- (#1+#4,#2+#5,#3) -- (#1,#2+#5,#3) -- (#1,#2,#3) -- cycle; +\filldraw[#7] (#1+#4,#2,#3) -- (#1+#4,#2,#3+#6) -- (#1+#4,#2+#5,#3+#6) -- (#1+#4,#2+#5,#3) -- cycle; +\filldraw[#7] (#1+#4,#2+#5,#3) -- (#1,#2+#5,#3) -- (#1,#2+#5,#3+#6) -- (#1+#4,#2+#5,#3+#6) -- cycle; +} + +\node[canvas is zy plane at x=0,draw,fill=white] (inputpic) at (-2,3,-3) {\includegraphics[scale=.14]{images/bird.jpeg}}; + +\cube{0}{0}{0}{.2}{6}{-6}{blueshape} +\cube{.5}{0}{0}{.2}{6}{-6}{blueshape} + +\cube{1.5}{1}{1}{.2}{5}{-5}{greenshape} +\cube{1.9}{1}{1}{.4}{5}{-5}{blueshape} +\cube{2.5}{1}{1}{.4}{5}{-5}{blueshape} + +\cube{3}{1.5}{.5}{.4}{4}{-4}{greenshape} +\cube{3.7}{1.5}{.5}{.6}{4}{-4}{blueshape} +\cube{4.6}{1.5}{.5}{.6}{4}{-4}{blueshape} +\cube{5.4}{1.5}{.5}{.6}{4}{-4}{blueshape} +\cube{6.2}{1.5}{.5}{.6}{4}{-4}{blueshape} + +\cube{7}{2.1}{.5}{.6}{3}{-3}{greenshape} +\cube{7.9}{2.1}{.5}{.8}{3}{-3}{blueshape} +\cube{9}{2.1}{.5}{.8}{3}{-3}{blueshape} +\cube{10}{2.1}{.5}{.8}{3}{-3}{blueshape} +\cube{11}{2.1}{.5}{.8}{3}{-3}{blueshape} + +\cube{12}{2.7}{.5}{.8}{2}{-2}{greenshape} +\cube{13}{2.7}{.5}{.8}{2}{-2}{blueshape} +\cube{14}{2.7}{.5}{.8}{2}{-2}{blueshape} +\cube{15}{2.7}{.5}{.8}{2}{-2}{blueshape} +\cube{16}{2.7}{.5}{.8}{2}{-2}{blueshape} +\cube{17}{3.3}{.5}{.8}{1}{-1.3}{greenshape} + +\node[style={yslant=0.9,xslant=0}] at (-3,-2,-6) { \Huge $x$ }; + +\node[] (first) at (-1.5,8,-3) {\Large $3 \times 224 \times 224$}; + +\draw[decorate, decoration={calligraphic brace,amplitude=5pt}, pen colour={black!50}, ultra thick] (2.2,8.5) -- (3,8.5) node[above right =.25cm and -1.5cm]{\Large $64 \times 224 \times 224$ }; + +\draw [-Triangle, thickline] (0.1,-2,-3) -- node[pos=-.4] { \Large $64 \times 112 \times 112$ } ++(0,1.3); + +\draw[decorate, decoration={calligraphic brace,amplitude=5pt}, pen colour={black!50}, ultra thick] (3.5,7.7) -- (4.4,7.7) node[above right =.25cm and -1cm]{\Large $128 \times 112 \times 112$ }; + +\draw [-Triangle, thickline] (1.9,-1,-3) -- node[pos=-.4] { \Large $128 \times 56 \times 56$ } ++(0,.9); + +\draw[decorate, decoration={calligraphic brace,amplitude=5pt}, pen colour={black!50}, ultra thick] (5,7) -- (8.2,7) node[above left =.25cm and 0cm]{\Large $256 \times 56 \times 56$}; + +\draw [-Triangle, thickline] (6,-1.2,-3) -- node[below left = .85 and -.85] { \Large $256 \times 28 \times 28$ } ++(-0,1.7); + +\draw [Triangle-, draw=red, line width=1mm] (8.1, 1.8) -- node[pos=1.15, text=red] { \Large Layer 12 } ++(-0,-3); + +\draw[decorate, decoration={calligraphic brace,amplitude=5pt}, pen colour={black!50}, ultra thick] (8.9,6.2) -- (12.8,6.2) node[above left =.25cm and .7cm]{\Large $512 \times 28 \times 28$}; + +\draw [-Triangle, thickline] (11,0,-3) -- node[pos=-.4] { \Large $512 \times 14 \times 14$ } ++(0,1.1); + +\draw[decorate, decoration={calligraphic brace,amplitude=5pt}, pen colour={black!50}, ultra thick] (13.5,5.4) -- (17.4,5.4) node[above left =.25cm and .5cm]{\Large $512 \times 14 \times 14$ }; + +\draw [-Triangle, thickline] (16,.1,-3) -- node[pos=-.2] { \Large $512 \times 7 \times 7$ } ++(0,1.6); + +\draw [-Triangle, uthickline] (18, 4) -- node[pos=1.6] {} ++(1.5,0); + +\foreach \i in {1,...,2} +{ + \foreach \j in {1,...,6} + { + \ifthenelse{\j > 3} + { + \pgfmathparse{int(\j)} \edef\pj{\pgfmathresult}; + } + { + \pgfmathparse{int(\j-.5)} \edef\pj{\pgfmathresult}; + } + \node[blueshape, circle, minimum size = .5cm] (column-\i\j) at (18.5+\i*1.2, \pj+1) {}; + } +} + +\foreach \j in {1,...,4} +{ + \ifthenelse{\j > 2} + { + \pgfmathparse{int(\j)} \edef\pj{\pgfmathresult}; + } + { + \pgfmathparse{int(\j-.5)} \edef\pj{\pgfmathresult}; + } + \node[blueshape, circle, minimum size = .5cm] (column-3\j) at (22, \pj+2) {}; +} + + + \foreach \i in {1,...,6}{ + \foreach \j in {1,...,6}{ + \draw[-Triangle, line] (column-1\i) -- (column-2\j); + \ifthenelse{\j < 5} + { + \draw[-Triangle, line] (column-2\i) -- (column-3\j); + \pgfmathparse{\outputs[\j]}\let\outs\pgfmathresult + \draw [-Triangle, line] (column-3\j) -- node[pos=1.7, text=black!50] {\Large $\hat{y}_{\outs}$} ++(1,0); + } + {} + } + } + +\draw[thickline, dashed] ([yshift=2mm]column-13.north) -- ([yshift=-2mm]column-14.south); + +\draw[thickline, dashed] ([yshift=2mm]column-23.north) -- ([yshift=-2mm]column-24.south); + +\draw[thickline, dashed] ([yshift=2mm]column-32.north) -- ([yshift=-2mm]column-33.south); + +\node[above of = column-16, node distance = .75cm] (first-c) {\Large 4096}; +\node[above of = column-26, node distance = .75cm] (first-c) {\Large 4096}; +\node[above of = column-34, node distance = .75cm] (first-c) {\Large 1000}; +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-3-a-convolution.tex b/tikz/figure6-3-a-convolution.tex new file mode 100644 index 0000000..2f9ea1c --- /dev/null +++ b/tikz/figure6-3-a-convolution.tex @@ -0,0 +1,65 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\begin {document} + +\begin{tikzpicture}[every node/.style={minimum size=1cm},on grid] + +\begin{scope} + +\newcommand\slantarray[5]{ + \foreach \i in {1,...,#3}{ + \foreach \j in {1,...,#4}{ + \node (node-#5\i\j) at (#1+\i-.5, #2-\j+.5) {$#5_{\j,\i}$}; + } + } + \draw[thickline] (#1,#2) grid[step=1] (#1+#3, #2-#4); +} + +\newcommand\fillbg[6]{ + \begin{scope}[on background layer] + \node[greyshape,thickline, minimum size=1cm,fill=#5, fill opacity=0.65] at (#1+.5+#3,#2-.5-#4){#6}; + \end{scope} +} + +\newcommand\lines[6]{ + \draw[#4, ultra thick, opacity=#6] (#1,#2) -- (#1+#3,#2); + \draw[#4, ultra thick, opacity=#6] (#1+#3,#2) -- (#1+#3,#2-#3); + \draw[#4, ultra thick, opacity=#6] (#1+#3,#2-#3) -- (#1,#2-#3); + \draw[#4, ultra thick, opacity=#6] (#1,#2-#3) -- (#1,#2); + \pgfmathparse{int(#3-1)} \edef\prev{\pgfmathresult}; + \foreach \i in {0,...,\prev}{ + \foreach \j in {0,...,\prev}{ + \fillbg{#1}{#2}{\i}{\j}{#5}{} + } + } +} + +\slantarray{5}{0}{7}{6}{x}; +\begin{scope}[yshift=.5cm] + \slantarray{0}{-2}{3}{3}{w}; +\end{scope} +\slantarray{14}{-1}{5}{4}{z}; + + +\lines{5}{0}{3}{border-green}{fill-light-green}{1} +\lines{6}{0}{3}{border-red}{fill-light-red}{.4} + +\lines{14}{-1}{1}{border-green}{fill-light-green}{1} +\lines{15}{-1}{1}{border-red}{fill-light-red}{.4} + +\node at (1.5,-5) { \Large $W$}; +\node at (8.5,-6.5) { \Large $ x$}; +\node at (16.5,-5.5) {\Large $z$}; + +\node at (4,-3) {\Large $\star$}; +\node at (13,-3) {\Large $ =$}; + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-3-b-element-of-convolution.tex b/tikz/figure6-3-b-element-of-convolution.tex new file mode 100644 index 0000000..64dd360 --- /dev/null +++ b/tikz/figure6-3-b-element-of-convolution.tex @@ -0,0 +1,75 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\begin {document} + +\begin{tikzpicture}[every node/.style={minimum size=1cm},on grid] + +\begin{scope} + +\newcommand\slantarray[7]{ + \foreach \i in {1,...,#3}{ + \foreach \j in {1,...,#4}{ + \IfEq{#7}{1}% + { + \pgfmathparse{int(#3-\i+1)} \edef\pi{\pgfmathresult}; + \pgfmathparse{int(#4-\j+1)} \edef\pj{\pgfmathresult}; + } + { + \pgfmathparse{int(\i)} \edef\pi{\pgfmathresult}; + \pgfmathparse{int(\j)} \edef\pj{\pgfmathresult}; + } + \node (node-#5\i\j) at (#1+\i-.5, #2-\j+.5) {$#6_{\pj,\pi}$}; + } + } + \draw [thickline](#1,#2) grid[step=1] (#1+#3, #2-#4); +} + +\newcommand\fillbg[6]{ + \begin{scope}[on background layer] + \node[rectangle,thickline, minimum size=1cm,fill=#5] at (#1+.5+#3,#2-.5-#4){#6}; + \end{scope} +} + +\newcommand\lines[5]{ + \draw[#4, ultra thick] (#1,#2) -- (#1+#3,#2); + \draw[#4, ultra thick] (#1+#3,#2) -- (#1+#3,#2-#3); + \draw[#4, ultra thick] (#1+#3,#2-#3) -- (#1,#2-#3); + \draw[#4, ultra thick] (#1,#2-#3) -- (#1,#2); + \pgfmathparse{int(#3-1)} \edef\prev{\pgfmathresult}; + \foreach \i in {0,...,\prev}{ + \foreach \j in {0,...,\prev}{ + \fillbg{#1}{#2}{\i}{\j}{#5}{} + } + } +} + +\slantarray{0}{0}{3}{3}{x}{x}{0}; +\slantarray{0}{4}{3}{3}{w}{w}{0}; +\slantarray{6}{4}{3}{3}{y}{w}{1}; + +\lines{0}{0}{3}{border-green}{fill-light-green} + +\node [draw,uthickline, circle, minimum size=1cm, right of = node-x22, node distance=6cm] (circle1) {\Large $\odot$}; + +\node [draw, uthickline, circle, minimum size=1cm, right of = circle1, node distance=4cm] (circle2) {\Large $\sum$}; + +\draw[-Triangle, thickline, draw=black!50] (node-x32)+(7mm,0) -- ([xshift=-2mm]circle1.west); + +\draw[-Triangle, thickline, draw=black!50] (circle1)+(7mm,0) -- ([xshift=-2mm]circle2.west); + +\draw[-Triangle, thickline, draw=black!50] (node-w32)+(7mm,0) -- ([xshift=-2mm]node-y12.west) node[pos=.5, above] {Flipping}; + +\draw[-Triangle, thickline, draw=black!50] (node-y23)+(0,-7mm) -- ([yshift=2mm]circle1.north); + +\draw[-Triangle, thickline, draw=black!50] (circle2)+(7mm,0) -- node[pos=1.3] {\Large $z_{1,1}$} ++(3cm,0); + + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-6-padding.tex b/tikz/figure6-6-padding.tex new file mode 100644 index 0000000..2959b70 --- /dev/null +++ b/tikz/figure6-6-padding.tex @@ -0,0 +1,58 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usepackage{moresize} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\begin {document} + +\begin{tikzpicture}[every node/.style={minimum size=1cm},on grid] + +\begin{scope}%[every node/.append style={yslant=0.3},yslant=0.3] + +\newcommand\slantarray[7]{ + \foreach \i in {1,...,#3}{ + \foreach \j in {1,...,#4}{ + \IfEq{#5}{0} + { + \ifthenelse{\j=#4 \OR \i=#3 \OR \j=1 \OR \i=1 } + { + \node (node-#7\i\j) at (#1+\i-.5, #2-\j+.5) {\large $#5$}; + } + { + } + } + { + \node (node-#7\i\j) at (#1+\i-.5, #2-\j+.5) {\large $#5_{\j,\i}$}; + } + + } + } + \draw[#6, ultra thick] (#1,#2) grid[step=1] (#1+#3, #2-#4) ; +} + + \begin{scope}[yshift=.5cm] + \slantarray{2}{2}{3}{3}{w}{border-grey}{1}; + \end{scope} + \slantarray{0}{-3}{7}{6}{x}{border-grey}{2}; + \slantarray{10}{-2}{9}{8}{0}{border-red}{3}; + \slantarray{11}{-3}{7}{6}{x}{border-grey}{4}; + \slantarray{21}{4}{7}{6}{z}{border-grey}{5}; + +\node at (3.5,-1.5) {\Huge $W$}; +\node at (3.5,-10) {\Huge $x$}; +\node at (15,-11) {\Huge $x$ with padding}; +\node at (24.5,-3) {\Huge $z$}; +\node [thickline, circle] at (14.5,1) (circle) {\Huge $\star$}; + +\draw[-Triangle, thickline, line width=.7mm] (node-273)+(7mm,-5mm) -- ([xshift=-2mm, yshift=-5mm]node-314.west) node[pos=.5, below] {\Large Padding}; +\draw[-Triangle, thickline, line width=.7mm] (node-132)+(7mm,0mm) -- ([xshift=-2mm]circle.west) {}; +\draw[Triangle-, thickline, line width=.7mm] (node-513)+(-7mm,-5mm) -- ([xshift=2mm]circle.east) {}; +\draw[-Triangle, thickline, thick, line width=.7mm] (node-351)+(0mm, 7mm) -- ([yshift=-2mm]circle.south) {}; + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-7-stride.tex b/tikz/figure6-7-stride.tex new file mode 100644 index 0000000..3b34ca0 --- /dev/null +++ b/tikz/figure6-7-stride.tex @@ -0,0 +1,96 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds, shapes} + +\pgfdeclarelayer{layer1} +\pgfdeclarelayer{layer2} +\pgfdeclarelayer{layer3} +\pgfdeclarelayer{layer4} +\pgfsetlayers{layer4,layer3,layer2,layer1} + +\begin {document} +\newcommand\slantarray[8]{ + \foreach \i in {0,...,#3}{ + \draw[#6, line width=#7] (#1,#2) grid (#1+#3+1, #2-#4-1); + \pgfmathparse{#1+((#3+1)/2)}\edef\ni{\pgfmathresult}; + \pgfmathparse{#2-#4-1.8}\edef\nj{\pgfmathresult}; + \node[#6] at(\ni,\nj){\huge $#8$}; + } +} + +\newcommand\lines[8]{ + \draw[#7, ultra thick] (#1,#2) -- (#3,#4); + \draw[#7, ultra thick] (#1+#5,#2) -- (#3+#6,#4); + \draw[#7, ultra thick] (#1,#2-#5) -- (#3,#4-#6); + \draw[#7, ultra thick] (#1+#5,#2-#5) -- (#3+#6,#4-#6); +} + +\newcommand\fillbg[6]{ + \begin{scope} + \node[rectangle,thickline, minimum size=1cm,fill=#5] at (#1+.5+#3,#2-.5-#4){#6}; + \end{scope} +} + +\newcommand\fillbglarge[7]{ + \begin{scope} + \node[rectangle,minimum size=#7cm,fill=#5] at (#1+.5+#3,#2-.5-#4){#6}; + \end{scope} +} + + +\begin{tikzpicture}[remember picture, every node/.style={minimum size=1cm},on grid] + +\begin{scope}[every node/.append style={yslant=0.3},yslant=0.3] + +\begin{pgfonlayer}{layer4} + \fillbglarge{3.5}{-4.5}{1}{0}{greylight}{}{10} + \slantarray{0}{0}{9}{9}{0}{fill-light-grey}{2}{\Huge $x$}; + \draw[decorate, decoration={calligraphic brace,amplitude=5pt, raise = .5cm}, pen colour={fill-grey}, ultra thick] (0,0) -- (4,0) node[above=.8cm, pos=.5]{\Huge $s_v = 4$}; + \draw[decorate, decoration={calligraphic brace,amplitude=5pt, raise = .5cm}, pen colour={fill-grey}, ultra thick] (0,-5) -- (0,0) node[left=.8cm, pos=.5]{\Huge $s_h = 5$}; +\end{pgfonlayer} + +\begin{pgfonlayer}{layer3} + \lines{4}{0}{17}{-5}{3}{3}{border-red}{fill-red}; + \fillbglarge{17}{-6}{1}{0}{fill-light-red}{}{3}; + \slantarray{4}{0}{2}{2}{1}{border-red}{3}{}; + \slantarray{17}{-5}{2}{2}{1}{border-red}{3}{$W$}; + \lines{17}{-5}{24}{-10}{3}{1}{border-red}{border-red} + + \lines{4}{-5}{17}{-10}{3}{3}{green2}{green1}; + \fillbglarge{17}{-11}{1}{0}{green0}{}{3} + \slantarray{4}{-5}{2}{2}{1}{green2}{3}{}; + \slantarray{17}{-10}{2}{2}{1}{green2}{3}{$W$}; + \lines{17}{-10}{24}{-11}{3}{1}{green2}{green2} +\end{pgfonlayer} + +\begin{pgfonlayer}{layer2} + \lines{0}{0}{13}{-5}{3}{3}{border-blue}{border-blue} + \fillbglarge{13}{-6}{1}{0}{fill-light-blue}{}{3} + \slantarray{0}{0}{2}{2}{0}{border-blue}{3}{}; + \slantarray{13}{-5}{2}{2}{1}{border-blue}{3}{$W$}; + \lines{13}{-5}{23}{-10}{3}{1}{border-blue}{border-blue} + + \lines{0}{-5}{13}{-10}{3}{3}{border-yellow}{border-yellow} + \fillbglarge{13}{-11}{1}{0}{fill-light-yellow}{}{3} + \slantarray{0}{-5}{2}{2}{1}{border-yellow}{3}{}; + \slantarray{13}{-10}{2}{2}{1}{border-yellow}{3}{$W$}; + \lines{13}{-10}{23}{-11}{3}{1}{border-yellow}{border-yellow} +\end{pgfonlayer} + +\begin{pgfonlayer}{layer1} + \slantarray{23}{-10}{1}{1}{1}{border-grey}{2}{\Huge $z$}; + \fillbg{23}{-11}{0}{0}{border-yellow}{} + \fillbg{23}{-10}{0}{0}{border-blue}{} + \fillbg{24}{-11}{0}{0}{green2}{} + \fillbg{24}{-10}{0}{0}{border-red}{} +\end{pgfonlayer} + + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-8-dilation.tex b/tikz/figure6-8-dilation.tex new file mode 100644 index 0000000..b01287a --- /dev/null +++ b/tikz/figure6-8-dilation.tex @@ -0,0 +1,65 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usepackage{moresize} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\begin {document} + +\begin{tikzpicture}[every node/.style={minimum size=1cm},on grid] + +\begin{scope} + +\newcommand\slantarray[7]{ + \draw[#6, ultra thick] (#1,#2) grid[step=1] (#1+#3, #2-#4) ; + \foreach \i in {1,...,#3}{ + \foreach \j in {1,...,#4}{ + \IfEq{#7}{2} + { + \ifthenelse{\j=2 \OR \i=2 \OR \j=4 \OR \i=4 } + { + \node (node-#7\i\j) at (#1+\i-.5, #2-\j+.5) {\large $\mathbf{0}$}; + \node[redshape, minimum size=1cm, opacity=0.5] at (#1+\i-.5,#2+-\j+.5){}; + } + { + \node (node-#7\i\j) at (#1+\i-.5, #2-\j+.5) {}; + } + } + { + \node (node-#7\i\j) at (#1+\i-.5, #2-\j+.5) {\large $#5_{\j,\i}$}; + } + + } + } + +} + + \begin{scope}[yshift=.5cm] + \slantarray{2}{2}{3}{3}{w}{fill-grey}{1}; + \slantarray{11}{3}{5}{5}{w}{fill-grey}{2}; + \end{scope} + \slantarray{0}{-3}{7}{6}{x}{fill-grey}{3}; + \slantarray{18}{-5}{3}{2}{z}{fill-grey}{4}; + + \foreach \i in {1,2,3}{ + \foreach \j in {1,2,3}{ + \node[] at (9.5+\i*2, 5-\j*2) {\large $w_{\j,\i}$}; + } +} +\node at (3.5,-1) {\LARGE $W$}; +\node at (3.5,-9.5) {\LARGE $x$}; +\node at (19.5,-7.5) {\LARGE $z$}; +\node [draw, circle, thickline, text=fill-grey] at (13.5,-6) (circle) {\Huge $\star$}; + +\draw[-Triangle, thickline, line width=.7mm] (node-132)+(7mm,-0mm) -- ([xshift=-2mm, yshift=0mm]node-213.west) node[pos=.5, below] {\Large Dilation}; +\draw[-Triangle, thickline, line width=.7mm] (node-373)+(7mm,-5mm) -- ([xshift=-2mm]circle.west) {}; +\draw[-Triangle, thickline, line width=.7mm] (node-235)+(0mm,-7mm) -- ([yshift=2mm]circle.north) {}; +\draw[Triangle-, thickline, thick, line width=.7mm] (node-411)+(-7mm, -5mm) -- ([xshift=2mm]circle.east) {}; + + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure6-9-input-channels.tex b/tikz/figure6-9-input-channels.tex new file mode 100644 index 0000000..7095526 --- /dev/null +++ b/tikz/figure6-9-input-channels.tex @@ -0,0 +1,68 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\begin {document} + +\begin{tikzpicture}%[fontsize=24pt] + +\begin{scope} +\newcommand\slantarray[8]{ + \draw[#6, line width=#7] (#1,#2) grid (#1+#3+1, #2-#4-1) rectangle (#1,#2); + \pgfmathparse{#1+((#3+1)/2)}\edef\ni{\pgfmathresult}; + \pgfmathparse{#2-#4-1.6}\edef\nj{\pgfmathresult}; + \node[] at(\ni,\nj-0.3){\Huge $#8$}; +} + +\newcommand\matrixset[9]{ + \draw[#5, line width=2] (#1,#2) grid (#1+#3+1, #2-#4-1) rectangle (#1,#2); + \draw[#6, line width=2] (#1-1,#2-1) grid (#1+#3, #2-#4-2) rectangle (#1-1,#2-1); + \draw[#7, line width=2] (#1-2,#2-2) grid (#1+#3-1, #2-#4-3) rectangle (#1-2,#2-2); + \draw[Triangle-Triangle, thickline] (#1-2, #2-#4-4) -- (#1+#3-1, #2-#4-4) node [midway,anchor=center, fill=white] {\Huge $#9_v$}; + \draw[Triangle-Triangle, thickline] (#1-3, #2-2) -- (#1-3, #2-#4-3) node [midway,anchor=center, fill=white] {\Huge $#9_h$}; + \draw[Triangle-Triangle, thickline] (#1+#3-.5, #2-#4-3.5) -- (#1+#3+1.5, #2-#4-1.5) node [midway,anchor=center, fill=white] {\Huge $#9_c$}; + + \node at (#1-2+.4 + #3/2, #2-#4-5.2) {\Huge #8}; + +} + +\matrixset{8}{0}{8}{8}{blueshape}{greenshape}{redshape}{$x$}{M^{[0]}}; +\matrixset{-1}{-3}{2}{2}{blueshape}{greenshape}{redshape}{$W$}{K}; +\draw[greylayer] (-5,2) rectangle ++(23,-16); + +\slantarray{29}{12}{8}{8}{0}{redshape}{2}{x_{(1)}}; +\slantarray{23}{9}{2}{2}{0}{redshape}{2}{W_{(1)}}; +\draw[greylayer] (22,13.5) rectangle ++(17,-12); + +\slantarray{29}{-1}{8}{8}{0}{greenshape}{2}{x_{(2)}}; +\slantarray{23}{-4}{2}{2}{0}{greenshape}{2}{W_{(2)}}; +\draw[greylayer] (22,.5) rectangle ++(17,-12); + +\slantarray{29}{-14}{8}{8}{0}{blueshape}{2}{x_{(3)}}; +\slantarray{23}{-17}{2}{2}{0}{blueshape}{2}{W_{(3)}}; +\draw[greylayer] (22,-12.5) rectangle ++(17,-12); +\draw[greylayer] (21,14.5) rectangle ++(19,-40); + +\slantarray{44}{-1}{6}{6}{0}{yellowshape}{2}{}; +\draw[greylayer] (43,0) rectangle ++(9,-9); + +\node at (3.5, -6) {\Huge $\star$}; +\node at (27.5,7.5) {\Huge $\star$}; +\node at (27.5,-5.5) {\Huge $\star$}; +\node at (27.5,-18.5) {\Huge $\star$}; + +\node at (19.5,-5.5) {\Huge =}; +\node at (41.5,-5.5) {\Huge =}; + +\node at (30,1) {\Huge +}; +\node at (30,-12) {\Huge +}; + +\node at (47.5,-10) {\Huge $W \star x$}; + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure7-1-a-look-ahead-prediction.tex b/tikz/figure7-1-a-look-ahead-prediction.tex new file mode 100644 index 0000000..fd3b981 --- /dev/null +++ b/tikz/figure7-1-a-look-ahead-prediction.tex @@ -0,0 +1,88 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{ifthen} + +\begin{document} +\begin{tikzpicture} + +\newcommand\rnnunit[6] +{ + \foreach \i in {1,...,#6} + { + \ifthenelse{\i=3 \OR \i=6} + { + \node[thick] (unit#4\i) at (#2+\i*3,#3) {\Huge {...}}; + } + { + \node[#5, rounded corners, minimum width=2cm, minimum height=1cm] (unit#4\i) at (#2+\i*3,#3) {Unit}; + } + } + \foreach \i in {2,...,#6} + { + \pgfmathparse{\i-1}\edef\ni{\pgfmathresult}; + \draw[-Triangle,uthickline] (unit#4\ni) -- (unit#4\i); + } + +} + +\newcommand\connect[3] +{ + \foreach \i in {#1,...,#2} + { + \pgfmathparse{\i+1}\edef\ni{\pgfmathresult}; + \draw[-Triangle, uthickline, bend left, looseness=2.5] (#3\i) to[out=90, in=-90] (#3\ni); + } +} + +\rnnunit{}{0}{0}{1}{blueshape}{7}; +\node[right of= unit17, node distance=2cm] (unit18) {\large }; + +\draw[-Triangle,uthickline,bend left, looseness=2.5] (unit14) to[out=90, in=-90] (unit15); +\draw[-Triangle,uthickline, bend left, looseness=2.5] (unit15) to[out=90, in=-90] (unit16); +\draw[-Triangle,uthickline, bend left, looseness=2.5] (unit16) to[out=90, in=-90] (unit17); + + +\node[redshape, rounded corners, minimum width=2cm, minimum height=1cm, above of = unit14, node distance=2cm ] (unit24) {\Large $\hat{x}^{\langle T+1 \rangle}$}; +\node[redshape, rounded corners, minimum width=2cm, minimum height=1cm, above of = unit15, node distance=2cm ] (unit25) {\Large $\hat{x}^{\langle T+2 \rangle}$}; +\node[ minimum width=2cm, minimum height=1cm, above of = unit16, node distance=2cm ] (unit26) {\Huge $...$}; +\node[redshape, rounded corners, minimum width=2cm, minimum height=1cm, above of = unit17, node distance=2cm ] (unit27) {\Large $\hat{x}^{\langle T+\tau \rangle}$}; +\node[redshape, rounded corners, minimum width=2cm, minimum height=1cm, right of = unit27, node distance=2.5cm ] (unit28) {\large Predictions}; +\node[lightgreyshape, rounded corners, minimum width=8cm, minimum height=1cm, left of = unit24, node distance=6cm ] (unit28) {\large Warmup Phase}; + +\node[yellowshape, rounded corners, minimum width=11cm, minimum height=1cm, above right = 3cm and 1.2cm of unit13] (unit01) {}; + +\node[above of = unit24, node distance = 1.8cm] {\Large $x^{\langle T+1\rangle}$}; +\node[above of = unit25, node distance = 1.8cm] {\Large $x^{\langle T+2\rangle}$}; +\node[above of = unit26, node distance = 1.8cm] {\Huge {...}}; +\node[above of = unit27, node distance = 1.8cm] {\Large $x^{\langle T+\tau\rangle}$}; + +\node[greenshape, rounded corners, minimum width=11cm, minimum height=1cm, below left = 3cm and 1cm of unit25] (unit41) {}; + + +\node[below of = unit11, node distance = 2cm] {\Large $x^{\langle 1 \rangle }$}; +\node[below of = unit12, node distance = 2cm] {\Large $x^{\langle 2 \rangle }$}; +\node[below of = unit13, node distance = 2cm] {\Huge {...}}; +\node[below of = unit14, node distance = 2cm] {\Large $x^{\langle T \rangle }$}; + +\draw [uthickline]([xshift = -2mm, yshift=-2mm]unit41.west) -- ([xshift=-2mm, yshift=-9mm]unit41.west) -- ([xshift=2mm, yshift=-9mm]unit41.east) -- ([xshift=2mm, yshift=-2mm]unit41.east); +\node[below of = unit41, node distance = 1.2cm] {\large Inputs Sequence}; + +\draw[uthickline] ([xshift = -2mm, yshift=2mm]unit01.west) -- ([xshift=-2mm, yshift=9mm]unit01.west) -- ([xshift=2mm, yshift=9mm]unit01.east) -- ([xshift=2mm, yshift=2mm]unit01.east); +\node[above of = unit01, node distance = 1.2cm] {\large Labels}; + +\draw[Triangle-, uthickline] (unit11) -- (unit11 |- unit41.north); +\draw[Triangle-, uthickline] (unit12) -- (unit12 |- unit41.north); +\draw[Triangle-, uthickline] (unit13) -- (unit13 |- unit41.north); +\draw[Triangle-, uthickline] (unit14) -- (unit14 |- unit41.north); +\draw[-Triangle, uthickline] (unit14) -- (unit24); +\draw[-Triangle, uthickline] (unit15) -- (unit25); +\draw[-Triangle, uthickline] (unit17) -- (unit27); + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-1-b-recurrent-sentiment.tex b/tikz/figure7-1-b-recurrent-sentiment.tex new file mode 100644 index 0000000..d67d0ed --- /dev/null +++ b/tikz/figure7-1-b-recurrent-sentiment.tex @@ -0,0 +1,46 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +\def\words{{ +{"I","like","reading", "this", "terribly", "instructive", "book"} +}} + +\foreach \i in {0,...,6} +{ + \pgfmathparse{int(\i-1)}\edef\j{\pgfmathresult}; + \pgfmathparse{\words[0][\i]} \edef\word{\pgfmathresult}; + + \node[blueshape, rounded corners, minimum width=1cm, minimum height=1cm] (unit\i) at (\i*3, 0) {Unit}; + + \node [greenshape, rounded corners, minimum width=1cm, minimum height=3cm, below of=unit\i, node distance=3cm] (rect\i) {}; + + \node[rotate=90, left of=unit\i, node distance=3cm] {Encoded Input}; + + \draw[-Triangle, uthickline] (rect\i) -- (unit\i); + + \node[below of=rect\i, node distance= 2cm] (word\i) {\Large \texttt{\word}}; + + \ifnum\i>0 + \draw[-Triangle, uthickline] (unit\j) -- (unit\i); + \fi + +} + +\node [minimum width=3cm, minimum height=1cm, above of=unit6, node distance=2cm, align=center] (rect) {\large Softmax}; + +\node[redshape, rounded corners, above of=rect, node distance=2cm, align=center] (text) {\large Sentiment}; + +\draw[-Triangle, uthickline] (unit6) -- (rect); +\draw[-Triangle, uthickline] (rect) -- (text); + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-1-c-basic-encoder-decoder.tex b/tikz/figure7-1-c-basic-encoder-decoder.tex new file mode 100644 index 0000000..58727f3 --- /dev/null +++ b/tikz/figure7-1-c-basic-encoder-decoder.tex @@ -0,0 +1,76 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{fontspec} + +\usepackage{arrayjob} +\def\words{{ +{"We","Enjoyed","Writing", "This", "Book", "", "nous","avons","aimé", "écrire", "ce", "livre"}, +{"", "", "", "", "", "nous","avons","aimé", "écrire", "ce", "livre", ""} +}} + +\begin{document} +\begin{tikzpicture} + +\pgfdeclarelayer{layer1} +\pgfdeclarelayer{layer2} +\pgfsetlayers{layer2,layer1} + +\begin{pgfonlayer}{layer1} +\foreach \i in {1,...,12} +{ + \pgfmathparse{int(\i-1)}\edef\j{\pgfmathresult}; + \pgfmathparse{\words[1][\j]} \edef\topword{\pgfmathresult}; + \pgfmathparse{\words[0][\j]} \edef\bottomword{\pgfmathresult}; + \node[blueshape, rounded corners, minimum width=1cm, minimum height=1cm] (unit\i) at (\j*2, 0) { Unit }; + \ifnum\i>1 + \draw[-Triangle, bthickline] (unit\j) -- (unit\i); + \fi + \node[above of=unit\i, node distance= 2cm] (top\i) { \texttt{ \topword }}; + \node[below of=unit\i, node distance= 2cm] (bottom\i) { \texttt{ \bottomword} }; + +} + +\foreach \i in {6,...,12} +{ + \ifnum\i<12 + \pgfmathparse{\i+1}\edef\ni{\pgfmathresult}; + \draw[-Triangle,uthickline, bend right, looseness=1] (top\i) to[out=90, in=-90] ([xshift=-1.2cm]bottom\ni); + \fi + \draw[-Triangle, uthickline] (unit\i) -- (top\i); +} + +\foreach \i in {1,...,6} +{ + \draw[-Triangle, uthickline] (bottom\i) -- (unit\i); +} +\end{pgfonlayer} + +\begin{pgfonlayer}{layer2} + +\node [greenshape, rounded corners, minimum width=9.5cm, minimum height=2.5cm, below of=unit3, node distance=0cm] (rect1) {}; + +\node [redshape, rounded corners, minimum width=13.5cm, minimum height=2.5cm, below of=unit9, node distance=0cm] (rect2) {}; + +\node [bluelayer, minimum width=10.2cm, minimum height=8cm, below of=unit3, node distance=.6cm] (rect3) {}; +\node [redlayer, minimum width=14.2cm, minimum height=8cm, below of=unit9, node distance=.4cm] (rect4) {}; + +\node [below left = -1cm and -2cm of rect3] {\large Encoder }; +\node [below right = -1cm and -2cm of rect4] {\large Decoder }; + +\node [below of=rect1, node distance=2.8cm] {\large Input} ; +\node [above of=rect2, node distance=3cm] {\large Output}; + +\draw[uthickline] ([xshift=2mm, yshift=2.2cm]rect2.west) -- ([xshift=2mm, yshift=2.5cm]rect2.west) -- ([xshift=-2mm, yshift=2.5cm]rect2.east) -- ([xshift=-2mm, yshift=2.2cm]rect2.east) ; + +\draw[uthickline] ([xshift=2mm, yshift=-2cm]rect1.west) -- ([xshift=2mm, yshift=-2.3cm]rect1.west) -- ([xshift=-2mm, yshift=-2.3cm]rect1.east) -- ([xshift=-2mm, yshift=-2cm]rect1.east) ; + +\end{pgfonlayer} + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-1-d-image-to-text.tex b/tikz/figure7-1-d-image-to-text.tex new file mode 100644 index 0000000..0985741 --- /dev/null +++ b/tikz/figure7-1-d-image-to-text.tex @@ -0,0 +1,47 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{graphicx} %package to manage images +\graphicspath{ {./images/} } + +\usepackage{arrayjob} +\def\words{{ +{"Three","good","friends", "having", "fun"} +}} + +\begin{document} +\begin{tikzpicture} + +\foreach \i in {1,...,5} +{ + \pgfmathparse{int(\i-1)}\edef\j{\pgfmathresult}; + \pgfmathparse{\words[0][\j]} \edef\word{\pgfmathresult}; + \node[blueshape, rounded corners, minimum width=.5cm, minimum height=2cm] (unit\i) at (\j*2, 0) { }; + \node[rotate=90, below of=unit\i, node distance=0cm] {Unit}; + \node[above of=unit\i, node distance= 2cm] (word\i) {\large \texttt{\word}}; + \draw[-Triangle,uthickline] (unit\i) -- (word\i); + + \ifnum\i>1 + \draw[-Triangle,uthickline] (unit\j) -- (unit\i); + \draw[-Triangle,uthickline, bend right, looseness=1.5] (word\j) to[out=90, in=-90] (unit\i.south); + \fi +} + +\node[lightgreenshape, trapezium, align=center, trapezium angle=80, minimum width = 2cm, shape border rotate=270, left of = unit1, node distance = 3cm ] (t1) {\Large CNN }; + +\node[scale = .07, left of = t1, node distance = 80cm] (inputpic) {\includegraphics {images/threepersons.jpeg}}; +\node[below of=unit1, node distance= 2cm] (word) {\large \texttt{}}; + +\draw[-Triangle,uthickline] (inputpic) -- (t1.west); +\draw[-Triangle,uthickline] (t1.east) -- (unit1); +\draw[-Triangle,uthickline] (word) -- (unit1); + + + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-10-encoder-decoder-attention.tex b/tikz/figure7-10-encoder-decoder-attention.tex new file mode 100644 index 0000000..a3f5683 --- /dev/null +++ b/tikz/figure7-10-encoder-decoder-attention.tex @@ -0,0 +1,79 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{ifthen} +\usepackage{medl_colors} +\usepackage{arrayjob} +\usepackage{amsmath} + +\begin{document} +\begin{tikzpicture} + +\node[rounded corners, minimum width=10cm, minimum height=1cm] at (6, 2.5) (rect1) {$u^{\langle t \rangle} = \textrm{Attention} [z_q^{\langle t\rangle} = s^{\langle t-1\rangle}, z_k = (v^{\langle 1 \rangle},\ldots ,v^{ \langle + T_{\text{in}}\rangle}), v = (v^{\langle 1 \rangle},\ldots,v^{ \langle T_{\text{in}} \rangle})]$}; + +\foreach \i in {1,...,5} +{ + \pgfmathparse{\i-1}\edef\j{\pgfmathresult}; + \ifthenelse{\i = 3} + { + \node[] (unit1\i) at (\i*2, 0) {\large ... }; + \node[] (unit2\i) at (\i*2, -1) {\large ... }; + } + { + \node[lightblueshape, rounded corners, minimum width=1.5cm, minimum height=2cm] at (\i*2, -0.5) (rectbox\i) {}; + \node[blueshape, rounded corners, minimum width=1cm, minimum height=.5cm] (unit1\i) at (\i*2, 0) { Unit}; + \node[blueshape, rounded corners, minimum width=1cm, minimum height=.5cm] (unit2\i) at (\i*2, -1) { Unit}; + } + + \ifnum\i>1 + \draw[Triangle-, thickline] (unit1\j) -- (unit1\i); + \draw[-Triangle, thickline] (unit2\j) -- (unit2\i); + \fi +} + +\foreach \i in {1,...,6} +{ + \pgfmathparse{\i-1}\edef\j{\pgfmathresult}; + \ifthenelse{\i=2 \OR \i=5 } + { + \node[] at (-1+\i*2, 5) (trectbox\i) {\large ... }; + } + { + \node[redshape, rounded corners, minimum width=1.2cm, minimum height=2cm] at (-1+\i*2, 5) (trectbox\i) {}; + } +} + +\node [left of=rectbox1, node distance=4cm] { Encoder }; +\node [left of=trectbox1, node distance=3cm] { Decoder }; + +\draw[-Triangle, thickline, looseness=.5] (trectbox3.south) to[out=-90, in=90] ([xshift=-2cm]rect1.north); +\draw[Triangle-, thickline, looseness=.5] (trectbox4.south) to[out=-90, in=90] ([xshift=2mm, yshift=5mm]rect1.west); + +\draw[-Triangle, thickline] (rectbox1.north) -- (rect1.south -| rectbox1) node[pos=.5, right] {$v^{ \langle 1 \rangle}$}; +\draw[Triangle-, thickline] (rectbox1.south) -- ++(0, -1) node[pos=1.3] {$x^{\langle 1 \rangle}$}; +\draw[-Triangle, thickline] (rectbox2.north) -- (rect1.south -| rectbox2) node[pos=.5, right] {$v^{ \langle 2 \rangle}$}; +\draw[Triangle-, thickline] (rectbox2.south) -- ++(0, -1) node[pos=1.3] {$x^{\langle 2 \rangle}$}; + +\draw[-Triangle, thickline] (rectbox4.north) -- (rect1.south -| rectbox4) node[pos=.5, right] {$v^{ \langle T_{\text{in}}-1 \rangle}$}; +\draw[Triangle-, thickline] (rectbox4.south) -- ++(0, -1) node[pos=1.3] {$x^{\langle T_{\text{in}}-1 \rangle}$}; + +\draw[-Triangle, thickline] (rectbox5.north) -- (rect1.south -| rectbox5) node[pos=.5, right] {$v^{ \langle T_{\text{in}} \rangle}$}; +\draw[Triangle-, thickline] (rectbox5.south) -- ++(0, -1) node[pos=1.3] {$x^{\langle T_{\text{in}} \rangle}$}; + +\draw[-Triangle, thickline] (trectbox1.north) -- ++(0, 1) node[pos=1.2] {$ \texttt{} $}; +\draw[-Triangle, thickline] (trectbox3.north) -- ++(0, 1) node[pos=1.2] {$\hat{y}^{ \langle t-1 \rangle}$}; +\draw[-Triangle, thickline] (trectbox4.north) -- ++(0, 1) node[pos=1.2] {$\hat{y}^{ \langle t \rangle}$}; +\draw[-Triangle, thickline] (trectbox6.north) -- ++(0, 1) node[pos=1.2] {$\texttt{} $}; + +\node[] at (trectbox1) {$s^{ \langle 1 \rangle}$}; +\node[] at (trectbox3) {$s^{ \langle t-1 \rangle}$}; +\node[] at (trectbox4) {$s^{ \langle t \rangle}$}; +\node[] at (trectbox6) {$s^{ \langle T_{\text{out}} \rangle}$}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-11-attention-matrix.tex b/tikz/figure7-11-attention-matrix.tex new file mode 100644 index 0000000..002fe2a --- /dev/null +++ b/tikz/figure7-11-attention-matrix.tex @@ -0,0 +1,74 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usepackage{etoolbox} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds, shapes} +\usepackage{arrayjob} + +\begin {document} + +\def\nums{{ + {"0.93", "0.02", "0.01", "0.02", "0.02"}, + {"0.44", "0.46", "0.04", "0.05", "0.01"}, + {"0.23", "0.26", "0.23", "0.25", "0.03"}, + {"0.01", "0.04", "0.45", "0.47", "0.03"}, + {"0.01", "0.02", "0.39", "0.55", "0.03"}, + {"0.02", "0.01", "0.67", "0.28", "0.02"}, + {"0.01", "0.01", "0.01", "0.01", "0.96"} +}} + +\def\colors{{ + {"border-blue", "border-blue!40", "border-blue!40", "border-blue!40", "border-blue!40"}, + {"border-blue!80", "border-blue!80", "border-blue!40", "border-blue!40", "border-blue!40"}, + {"border-blue!60", "border-blue!60", "border-blue!60", "border-blue!50", "border-blue!40"}, + {"border-blue!40", "border-blue!40", "border-blue!80", "border-blue!80", "border-blue!40"}, + {"border-blue!40", "border-blue!40", "border-blue!80", "border-blue!90", "border-blue!40"}, + {"border-blue!40", "border-blue!40", "border-blue!75", "border-blue!80", "border-blue!40"}, + {"border-blue!40", "border-blue!40", "border-blue!40", "border-blue!40", "border-blue"} +}} + +\def\words{{ + {"We","love","deep", "learning", ""}, + {"nous","aimons","l'", "apprentissage", "en", "profondeur", ""} +}} + +\begin{tikzpicture} + +\begin{scope} + +\foreach \i in {0,...,4} +{ + \foreach \j in {0,...,6} + { + \pgfmathparse{\nums[\j][\i]} \edef\num{\pgfmathresult}; + \pgfmathparse{\colors[\j][\i]} \edef\color{\pgfmathresult}; + \node[rectangle, thickline, minimum size=1cm, fill=\color] at (\i+.5 ,-\j+6.5) (grid\i\j) { \texttt{\num}}; + \ifnum\i=4 + { + \pgfmathparse{\words[1][\j]} \edef\word{\pgfmathresult}; + \pgfmathparse{int(\j+1)}\edef\k{\pgfmathresult}; + + \node[left of= grid0\j, node distance=2cm] (word\j) { \texttt{\scriptsize \word}}; + \node[right of= grid4\j, node distance=2cm] { \texttt {\scriptsize t=\k}}; + } + \fi + + } + \pgfmathparse{\words[0][\i]} \edef\word{\pgfmathresult}; + \pgfmathparse{int(\i+1)}\edef\j{\pgfmathresult}; + \node[above of= grid\i0, node distance=1.3cm] { \texttt {\scriptsize \word}}; + \node[above of= grid\i0, node distance=.8cm] { \texttt {\scriptsize$\tau=$\j}}; +} + +\node[left of= grid03, node distance=4.5cm, font=\boldmath] { \texttt { $[\alpha_{\tau}^{\langle t \rangle }]=$}}; +\draw[decorate, decoration={calligraphic brace,mirror, raise=3cm, amplitude=10pt}, uthickline, draw=black!50] (grid00.north) -- (grid06.south); +\draw[uthickline] ([xshift=-1cm]grid00.north) -- ([xshift=-1cm]grid06.south); +\draw[uthickline] ([xshift=1cm]grid40.north) -- ([xshift=1cm]grid46.south); + +\end{scope} +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure7-12-self-attention.tex b/tikz/figure7-12-self-attention.tex new file mode 100644 index 0000000..7a3bc44 --- /dev/null +++ b/tikz/figure7-12-self-attention.tex @@ -0,0 +1,60 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{ifthen} +\usepackage{medl_colors} +\usepackage{arrayjob} + +\def\words{{ + {"\alpha_{1}^{\langle t\rangle}", "\alpha_{2}^{\langle t\rangle}", "", "\alpha_{\tau}^{\langle t\rangle}", "", "\alpha_{t}^{\langle t\rangle}", "", "", ""}, + {"x^{\langle 1\rangle}", "x^{\langle2\rangle}", "", "x^{\langle\tau \rangle}", "", "x^{\langle t \rangle}", "", "", ""} +}} + +\begin{document} +\begin{tikzpicture} + + +\node [thickline,draw,circle, minimum size=0.6cm] at (1,0) (tcircle1) { $+$ }; +\draw [-Triangle, thickline, draw] (tcircle1) -- node[pos=1.3] {$ u ^{\langle t \rangle}$} ++(0,2); + +\foreach \j in {0,...,5} +{ + \pgfmathparse{\words[0][\j]} \edef\topword{\pgfmathresult}; + \pgfmathparse{\words[1][\j]} \edef\bottomword{\pgfmathresult}; + + \node[] at (-4+\j,-3) (t\j) {\tiny $\topword$ }; + \node[] at (-4+\j,-5) (b\j) {\tiny $\bottomword$ }; + + \ifx\topword\empty + \node [] at (-4+\j,-4) (circle\j) {. . .}; + \else + \node [circle] at (-4+\j,-4) (circle\j) { $\times$ }; + \draw [Triangle-, thickline, draw] (tcircle1) -- (t\j); + \fi +} + +\draw [Triangle-, thickline, draw] (tcircle1) -- (t3); +\draw [Triangle-,red] (tcircle1) -- (2, -2.7); +\draw [Triangle-,red] (tcircle1) -- (4, -2.7); +\path (b3) edge [-Triangle,thickline,out=180,in=180,draw=blue] node [midway, left, blue] {\tiny $W_v$} (circle3); + +% \node[pink0] at (-1,-3) {\tiny $\alpha^{\langle \tau\rangle}$ }; +% \node[pink0] at (-1,-5) {\tiny $X^f{}$ }; +% \node[fred, thick] at (1,-5) {\tiny $X^{}$ }; + +\path (b3) edge [-Triangle,thickline,out=0,in=-10,draw=blue, looseness=.7] node [pos=.3, left, blue] {\tiny $W_k$} (t3); +\path ([yshift=-5mm]b5) edge [-Triangle,thickline,out=180,in=10,draw=blue] node [pos=.3, right,blue] {\tiny $W_q$} (t3); + +\node[] at (.4,-2) {. . .}; +\node[] at (-1,-2) {. . .}; +\node[align=center,red] at (2.4,-2) {\tiny non-\\ \tiny casual}; + +\node[left of = t1, align=center, node distance = 3cm] {\small Attention\\ \small Weights:}; +\node[left of = b1, align=center, node distance = 3cm] {\small Input:}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-13-Multi-head-self-attention.tex b/tikz/figure7-13-Multi-head-self-attention.tex new file mode 100644 index 0000000..fa7f95e --- /dev/null +++ b/tikz/figure7-13-Multi-head-self-attention.tex @@ -0,0 +1,48 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +\node[bluelayer, minimum height=1cm, below left = 3cm] (unit01) {\parindent=1cm $x^{\langle 1\rangle }$ \indent$x^{\langle 2\rangle }$ \indent $\cdots$ \indent \textcolor{red}{$x^{\langle t\rangle }$} \indent $\cdots$ \indent \indent $x^{\langle T\rangle }$}; + +\node[bluelayer, minimum height=1cm, above of=unit01,node distance= 7cm] (unit02) {\parindent=1cm $u^{\langle 1\rangle }$ \indent$u^{\langle 2\rangle }$ \indent $\cdots$ \indent \textcolor{red}{$u^{\langle t\rangle }$} \indent $\cdots$ \indent \indent $u^{\langle T\rangle }$}; + +\node[ rounded corners, minimum width=4.2cm, minimum height=1cm, above left= 1cm and .5cm of unit01] (head11) {$W_{q}^{1}~~ W_{k}^{1}~~ W_{v}^{1} $}; + +\node[uthickline, rounded corners, minimum width=5.3cm, minimum height=1cm, above of = head11] (head1) {Head 1}; + +\node[ rounded corners, minimum width=4.2cm, minimum height=1cm, above right= 1cm and .5cm of unit01] (head22) {$W_{q}^{H} ~~ W_{k}^{H} ~~W_{v}^{H} $}; + +\node[uthickline, rounded corners, minimum width=5.5cm, minimum height=1cm, above of = head22] (head2) {Head H}; + + +\node[greenlayer, minimum width=4.2cm, minimum height=1cm, above of = head1, node distance = 1.2cm] (tunit01) {\parindent=.3cm $u^{1, \langle 1\rangle }$ \indent $\cdots$ \indent \textcolor{red}{$u^{1,\langle t\rangle }$} \indent $\cdots$ \indent $u^{1,\langle T\rangle }$}; +\node[greenlayer, minimum width=4.2cm, minimum height=1cm, above of = head2, node distance = 1.2cm] (tunit02) {\parindent=.3cm $u^{H, \langle 1\rangle }$ \indent $\cdots$ \indent \textcolor{red}{$u^{H, \langle t\rangle }$} \indent $\cdots$ \indent $u^{H, \langle T\rangle }$}; + +\draw[-Triangle,thickline, looseness=.4] ([xshift=-.5cm]unit01.north) to[out=90, in=-90] (head11.south)++(0, 0.2) node[](line1){}; +\draw[-Triangle,thickline, looseness=.4] ([xshift=1cm]unit01.north) to[out=90, in=-90] (head22.south)++(0, 0.2) node[](line2){}; + +%\draw[-Triangle,thickline, looseness=.7] ([xshift=.5cm]unit01.north) to[out=90, in=-90] ++(2,1); +%\draw[-Triangle,thickline, looseness=.7] (unit01.north) to[out=90, in=-90] ++(-2,1); + +\draw[-Triangle,thickline, looseness=.5] (tunit01.north) to[out=90, in=-90] (unit02.south) node[](line3){}; +\draw[-Triangle,thickline, looseness=.5] ([xshift=0cm]tunit02.north) to[out=90, in=-90] ([xshift=.5cm]unit02.south) node[](line4){}; + +%\node[above left = -.2cm and -5.5cm of line1] {$W_{q}^{1}~~ W_{k}^{1}~~ W_{v}^{1} $}; +%\node[above right = -.2cm and -5cm of line2] {$W_{q}^{H} ~~ W_{k}^{H} ~~W_{v}^{H} $}; +\node[above left = -1cm and -5cm of line3] {$W_{c}^H $}; +\node[above right = -1cm and -5cm of line4] {$W_{c}^1 $}; + +%\node[border-grey, above of = unit01, node distance = 3.5cm] {\Huge - - - - - - - }; +\node[border-grey, above of = unit01, node distance = 3.5cm] {\Huge . . . . . . . . }; + + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-15-a-transformer-block.tex b/tikz/figure7-15-a-transformer-block.tex new file mode 100644 index 0000000..73ea0b4 --- /dev/null +++ b/tikz/figure7-15-a-transformer-block.tex @@ -0,0 +1,44 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +\node[bluelayer, minimum width=3cm, minimum height=1cm] (unit11) {\parindent=.1cm $a_{\textrm{out}}^{\langle 1\rangle }$ \indent - - - \indent $a_{\textrm{out}}^{\langle T\rangle }$}; + +\node[lightgreyshape, circle, minimum size=.8cm, below of = unit11, node distance = 2.25cm, align=center] (unit12) {+}; + +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=1.5cm, below of = unit12 ] (unit13) {\parindent=.1cm $u_{[3]}^{\langle 1\rangle }$ \indent - - - \indent $u_{[3]}^{\langle T\rangle }$}; + +\node[uthickline, rounded corners, minimum width=3cm, minimum height=1cm, below of = unit13, node distance = 1.2cm, align=center] (unit14) {Feed Forward\\Network}; + +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=2cm, below of = unit14 ] (unit15) {\parindent=.1cm $u_{[2]}^{\langle 1\rangle }$ \indent - - - \indent $u_{[2]}^{\langle T\rangle }$}; + +\node[lightgreyshape, circle, minimum size=.8cm, below of = unit15, node distance = 2.25cm, align=center] (unit16) {+}; + +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=1.5cm, below of = unit16 ] (unit17) {\parindent=.1cm $u_{[1]}^{\langle 1\rangle }$ \indent - - - \indent $u_{[1]}^{\langle T\rangle }$}; + +\node[uthickline, rounded corners, minimum width=3cm, minimum height=1cm, below of = unit17, node distance = 1.2cm, align=center] (unit18) {Multi-Head\\Self Attention}; + +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=2cm, below of = unit18 ] (unit19) +{$a_{\textrm{in}}^{\langle 1\rangle }$ \indent - - - \indent $a_{\textrm{in}}^{\langle T\rangle }$}; + +\draw[-Triangle, thickline] (unit19) -- (unit18); +\draw[-Triangle, thickline] (unit17) -- (unit16); +\draw[-Triangle, thickline] (unit16) -- (unit15) node[pos=.4, anchor=center, fill=white] {Layer Norm}; +\draw[-Triangle, thickline] (unit13) -- (unit12); +\draw[-Triangle, thickline] (unit13) -- (unit12); +\draw[-Triangle, thickline] (unit15) -- (unit14); +\draw[-Triangle, thickline] (unit12) -- (unit11) node[pos=.4, anchor=center, fill=white] {Layer Norm}; + +\draw[-Triangle, thickline] ([yshift=5mm]unit19.north) -| ++(2cm, 0) |- (unit16.east); +\draw[-Triangle, thickline] ([yshift=-5mm]unit14.south) -| ++(2cm, 0) |- (unit12.east); + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-15-b-transformer-decoder-block.tex b/tikz/figure7-15-b-transformer-decoder-block.tex new file mode 100644 index 0000000..a85482a --- /dev/null +++ b/tikz/figure7-15-b-transformer-decoder-block.tex @@ -0,0 +1,48 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +\node[bluelayer, minimum width=3cm, minimum height=1cm] (unit11) {\parindent=.1cm $a_{\textrm{out}}^{\langle 1\rangle }$ \indent - - - - \indent $a_{\textrm{out}}^{\langle T\rangle }$}; +\node[lightgreyshape,circle, minimum size=.8cm, node distance = 2.25cm, align=center, below of = unit11] (unit12) {$+$}; +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=1.5cm, below of = unit12 ] (unit13) {\parindent=1cm $u_{[5]}^{\langle 1\rangle }$ \indent $u_{[5]}^{\langle T\rangle }$}; +\node[uthickline, rounded corners, minimum width=3cm, minimum height=1cm, node distance = 1.2cm, align=center, below of = unit13] (unit14) {Feed Forward\\Network}; +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=2cm, below of = unit14 ] (unit15) {\parindent=.1cm $u_{[4]}^{\langle 1\rangle }$ \indent - - - - \indent $u_{[4]}^{\langle T\rangle }$}; +\node[lightgreyshape,circle, minimum size=.8cm, node distance = 2.25cm, align=center, below of = unit15] (unit16) {$+$}; +\node[bluelayer, minimum width=2.25cm, minimum height=1cm, node distance=1.5cm, below of = unit16 ] (unit17) {\parindent=.1cm $u_{[3]}^{\langle 1\rangle }$ \indent - - - - \indent $u_{[3]}^{\langle T\rangle }$}; +\node[uthickline, rounded corners, minimum width=3cm, minimum height=1cm, node distance = 1.2cm, align=center, below of = unit17] (unit18) {Multi-Head\\Cross Attention}; + +\node[left of = unit18, node distance=3cm] (zznode) {{\Large $z^\star$}}; + + +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=2cm, below of = unit18 ] (unit19) {\parindent=.1cm $u_{[2]}^{\langle 1\rangle }$ \indent - - - - \indent $u_{[2]}^{\langle T\rangle }$}; +\node[lightgreyshape,circle, minimum size=.8cm, node distance = 2.25cm, align=center, below of = unit19] (unit20) {$+$}; +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=1.5cm, below of = unit20 ] (unit21) {\parindent=1cm $u_{[1]}^{\langle1\rangle }$ \indent $u_{[1]}^{\langle T\rangle }$}; +\node[uthickline, rounded corners, minimum width=3cm, minimum height=1cm, node distance = 1.2cm, align=center, below of = unit21] (unit22) {Multi-Head\\Self Attention}; +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=2cm, below of = unit22 ] (unit23) {\parindent=.1cm $a_{\textrm{in}}^{\langle 1\rangle }$ \indent - - - - \indent $a_{\textrm{in}}^{\langle T\rangle }$}; + +\draw[Triangle-, thickline] (unit11) -- (unit12) node[pos=.5, anchor=center, fill=white] {Layer Norm}; +\draw[Triangle-, thickline] (unit12) -- (unit13); +\draw[Triangle-, thickline] (unit14) -- (unit15); +\draw[Triangle-, thickline] (unit15) -- (unit16) node[pos=.5, anchor=center, fill=white] {Layer Norm}; +\draw[Triangle-, thickline] (unit16) -- (unit17); +\draw[Triangle-, thickline] (unit18) -- (unit19); +\draw[Triangle-, thickline] (unit19) -- (unit20) node[pos=.5, anchor=center, fill=white] {Layer Norm}; +\draw[Triangle-, thickline] (unit20) -- (unit21); +\draw[Triangle-, thickline] (unit22) -- (unit23); + +\draw[-Triangle, thickline] (zznode) -- (unit18); + +\draw[-Triangle, thickline] ([yshift=5mm]unit23.north) -| ++(2cm, 0) |- (unit20.east); +\draw[-Triangle, thickline] ([yshift=5mm]unit19.north) -| ++(2cm, 0) |- (unit16.east); +\draw[-Triangle, thickline] ([yshift=5mm]unit15.north) -| ++(2cm, 0) |- (unit12.east); + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-16-transformer-encoder-decoder.tex b/tikz/figure7-16-transformer-encoder-decoder.tex new file mode 100644 index 0000000..9c23bbb --- /dev/null +++ b/tikz/figure7-16-transformer-encoder-decoder.tex @@ -0,0 +1,56 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +\node[bluelayer, minimum width=3cm, minimum height=1cm] (unit11) {\parindent=1cm $a_{\textrm{out}}^{\langle 1\rangle }$ \indent $a_{\textrm{out}}^{\langle T\rangle }$}; +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=5cm, right of = unit11] (unit21) {\parindent=1cm $\hat y_{\textrm{out}}^{\langle 1\rangle }$ \indent $\hat y_{\textrm{out}}^{\langle T\rangle }$}; + +\node[draw, uthickline, rounded corners, minimum width=3cm, minimum height=1cm, below of = unit11, node distance = 2cm, align=center] (unit12) {Transformer\\Block}; +\node[draw, uthickline, rounded corners, minimum width=3cm, minimum height=1cm, below of = unit21, node distance = 2cm, align=center] (unit22) {Transformer\\Decoder Block}; + +\node[minimum width=3cm, minimum height=1cm, below of = unit12, node distance = 2cm, align=center] (unit13) { .\\.\\.}; +\node[minimum width=3cm, minimum height=1cm, below of = unit22, node distance = 2cm, align=center] (unit23) { .\\.\\.}; + +\node[draw, uthickline, rounded corners, minimum width=3cm, minimum height=1cm, below of = unit13, node distance = 2cm, align=center] (unit14) {Transformer\\Block}; +\node[draw, uthickline, rounded corners, minimum width=3cm, minimum height=1cm, below of = unit23, node distance = 2cm, align=center] (unit24) {Transformer\\Decoder Block}; + +\node[draw, uthickline, rounded corners, minimum width=3cm, minimum height=1cm, below of = unit14, node distance = 2cm, align=center] (unit15) {Transformer\\Block}; +\node[draw, uthickline, rounded corners, minimum width=3cm, minimum height=1cm, below of = unit24, node distance = 2cm, align=center] (unit25) {Transformer\\Decoder Block}; + +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=2cm, below of = unit15 ] (unit16) {\parindent=1cm $\tilde x_{\textrm{in}}^{\langle 1\rangle }$ \indent $\tilde x_{\textrm{in}}^{\langle T\rangle }$}; +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=2cm, below of = unit25] (unit26) {\parindent=1cm $\tilde y_{\textrm{out}}^{\langle 1\rangle }$ \indent $\tilde y_{\textrm{out}}^{\langle T\rangle }$}; + +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=2cm, below of = unit16 ] (unit17) {\parindent=1cm $x_{\textrm{in}}^{\langle 1\rangle }$ \indent $x_{\textrm{in}}^{\langle T\rangle }$}; +\node[bluelayer, minimum width=3cm, minimum height=1cm, node distance=2cm, below of = unit26] (unit27) {\parindent=1cm $y_{\textrm{out}}^{\langle 1\rangle }$ \indent $y_{\textrm{out}}^{\langle T\rangle }$}; + +\foreach \i in {2,...,7} +{ + \pgfmathparse{int(\i-1)}\edef\j{\pgfmathresult}; + \draw[-Triangle, thickline, thick] (unit1\i) -- (unit1\j); + \draw[-Triangle, thickline, thick] (unit2\i) -- (unit2\j); +} + +\node[ above right = .25cm and -1.5cm of unit17, align=center] {\footnotesize Positional Embedding}; +\node[ above right = .25cm and -1.5cm of unit27, align=center] {\footnotesize Positional Embedding}; +\node[below of = unit17, node distance=1cm] {Encoder}; +\node[below of = unit27, node distance=1cm] {Decoder}; + +\node[ above right = .25cm and -1.5cm of unit12, align=center] (mark1) {\tiny {\Large $z^{\star}$}}; + +\draw[Triangle-, thickline, thick] (unit27.east) -| ++(2cm, 0) |- (unit21.east); +\draw[-Triangle, thickline, thick] (mark1) -| ++(2cm, 0) |- (unit22.west); +\draw[-Triangle, thickline, thick] (mark1) -| ++(2cm, 0) |- (unit24.west); +\draw[-Triangle, thickline, thick] (mark1) -| ++(2cm, 0) |- (unit25.west); + + + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-17-transformer-encoder-decoder-unrolling.tex b/tikz/figure7-17-transformer-encoder-decoder-unrolling.tex new file mode 100644 index 0000000..16d4736 --- /dev/null +++ b/tikz/figure7-17-transformer-encoder-decoder-unrolling.tex @@ -0,0 +1,50 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{fontspec} + + +\begin{document} +\begin{tikzpicture} + +\newcommand\lhs[1] +{ + \node[left of = unit#1, node distance=2cm] (side#1) {\Large $z^{\star}$}; + \draw[-Triangle, thickline] (side#1) -- ([yshift=1.3cm]unit#1.west); + \draw[-Triangle, thickline] (side#1) -- ([yshift=.9cm]unit#1.west); + \draw[-Triangle, thickline] (side#1) -- ([yshift=-1cm]unit#1.west); + \node[left of = unit#1, node distance=1.3cm, align=center, border-grey, thick] (side#1) {.\\.\\.}; +} + + +\node[greenshape,rounded corners,minimum width=2cm, minimum height=4cm, align=center] (unit1) { Transformer\\Encoder }; +\node[below of = unit1, node distance=3cm] (bottom1) {$\texttt{We love deep learning }$}; +\node[above of = unit1, node distance=3cm] (top1) {\Large $z^{\star}$}; +\draw[-Triangle, thickline] (bottom1.north) -- (unit1.south); +\draw[-Triangle, thickline] (unit1.north) -- (top1.south); +\draw[-Triangle, thickline] (top1.east) -- ++(1.5, -0.5); + +\node[redshape,rounded corners, minimum width=2cm, minimum height=4cm, align=center, node distance=5cm, right of = unit1] (unit2) { Transformer\\Decoder }; +\node[below of = unit2, node distance=3cm] (bottom2) {$\texttt{}$}; +\node[above of = unit2, node distance=3cm] (top2) {$\texttt{ nous}$}; +\draw[-Triangle, thickline] (bottom2.north) -- (unit2.south); +\draw[-Triangle, thickline] (unit2.north) -- (top2.south); + +\node[redshape,rounded corners, minimum width=2cm, minimum height=4cm, align=center, node distance=5cm, right of = unit2] (unit3) { Transformer\\Decoder }; +\node[below of = unit3, node distance=3cm] (bottom3) {$\texttt{ nous}$}; +\node[above of = unit3, node distance=3cm] (top3) {$\texttt{ nous aimons}$}; +\draw[-Triangle, thickline] (bottom3.north) -- (unit3.south); +\draw[-Triangle, thickline] (unit3.north) -- (top3.south); +\draw[-Triangle, thickline, bend right, looseness=1] (top2.east) to[out=90, in=-90] ([xshift=-1.2cm]bottom3); +\draw[-Triangle, thickline, bend right, looseness=1] (top3.east) to[out=90, in=-90] ([xshift=5cm]bottom3); + +\lhs{2}; +\lhs{3}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-2-a-one-to-many.tex b/tikz/figure7-2-a-one-to-many.tex new file mode 100644 index 0000000..5399016 --- /dev/null +++ b/tikz/figure7-2-a-one-to-many.tex @@ -0,0 +1,48 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{graphicx} %package to manage images +\graphicspath{ {./images/} } + +\usepackage{arrayjob} + +\begin{document} +\begin{tikzpicture} + +\newcommand\rnnunit[6] +{ + \foreach \i in {1,...,#6} + { + \pgfmathparse{\i-1}\edef\j{\pgfmathresult}; + + \node[blueshape, rounded corners, minimum width=.5cm, minimum height=2cm] (unit#4\i) at (#2+\i*1.5,#3) { }; + \node[rotate=90, below of=unit#4\i, node distance=0cm] {Unit}; + + \node[redshape, rounded corners, minimum width=.5cm, minimum height=2cm, above of=unit#4\i, node distance=3cm] (top#4\i) { }; + \draw[-Triangle, uthickline] (unit#4\i) -- (top#4\i); + + \ifnum\i=1 + { + \node[greenshape, rounded corners, minimum width=.5cm, minimum height=2cm, below of=unit#4\i, node distance=3cm] (bottom#4\i) { }; + \draw[Triangle-, uthickline] (unit#4\i) -- (bottom#4\i); + } + \fi + + \ifnum\i>1 + \draw[-Triangle, uthickline] (unit#4\j) -- (unit#4\i); + \fi + } +} + + +\rnnunit{}{0}{0}{0}{}{3}; +\node[above of=unit02, node distance=4.5cm] {}; +%One to many}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-2-b-many-to-one.tex b/tikz/figure7-2-b-many-to-one.tex new file mode 100644 index 0000000..f879870 --- /dev/null +++ b/tikz/figure7-2-b-many-to-one.tex @@ -0,0 +1,59 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{graphicx} %package to manage images +\graphicspath{ {./images/} } + +\usepackage{arrayjob} + +\def\spec +{{ + {0, 0, 1}, + {1, 1, 1} +}} + +\begin{document} +\begin{tikzpicture} + +\newcommand\rnnunit[6] +{ + \foreach \i in {1,...,#6} + { + \pgfmathparse{\i-1}\edef\j{\pgfmathresult}; + \pgfmathparse{int(\spec[0][\j])} \edef\top{\pgfmathresult}; + \pgfmathparse{int(\spec[1][\j])} \edef\bottom{\pgfmathresult}; + + \node[blueshape, rounded corners, minimum width=.5cm, minimum height=2cm] (unit#4\i) at (#2+\i*1.5,#3) { }; + \node[rotate=90, below of=unit#4\i, node distance=0cm] {Unit}; + + \ifnum\top=1 + { + \node[redshape, rounded corners, minimum width=.5cm, minimum height=2cm, above of=unit#4\i, node distance=3cm] (top#4\i) { }; + \draw[-Triangle, uthickline] (unit#4\i) -- (top#4\i); + } + \fi + + \ifnum\bottom=1 + { + \node[greenshape, rounded corners, minimum width=.5cm, minimum height=2cm, below of=unit#4\i, node distance=3cm] (bottom#4\i) { }; + \draw[Triangle-, uthickline] (unit#4\i) -- (bottom#4\i); + } + \fi + + \ifnum\i>1 + \draw[-Triangle, uthickline] (unit#4\j) -- (unit#4\i); + \fi + } +} + +\rnnunit{}{6}{0}{1}{}{3}; +\node[above of=unit12, node distance=4.5cm] {}; +%Many to one}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-2-c-many-to-many-1.tex b/tikz/figure7-2-c-many-to-many-1.tex new file mode 100644 index 0000000..61b6fba --- /dev/null +++ b/tikz/figure7-2-c-many-to-many-1.tex @@ -0,0 +1,59 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{graphicx} %package to manage images +\graphicspath{ {./images/} } + +\usepackage{arrayjob} + +\def\spec +{{ + {0, 0, 1, 1, 1}, + {1, 1, 0, 0, 0} +}} + +\begin{document} +\begin{tikzpicture} + +\newcommand\rnnunit[6] +{ + \foreach \i in {1,...,#6} + { + \pgfmathparse{\i-1}\edef\j{\pgfmathresult}; + \pgfmathparse{int(\spec[0][\j])} \edef\top{\pgfmathresult}; + \pgfmathparse{int(\spec[1][\j])} \edef\bottom{\pgfmathresult}; + + \node[blueshape, rounded corners, minimum width=.5cm, minimum height=2cm] (unit#4\i) at (#2+\i*1.5,#3) { }; + \node[rotate=90, below of=unit#4\i, node distance=0cm] {Unit}; + + \ifnum\top=1 + { + \node[redshape, rounded corners, minimum width=.5cm, minimum height=2cm, above of=unit#4\i, node distance=3cm] (top#4\i) { }; + \draw[-Triangle, uthickline] (unit#4\i) -- (top#4\i); + } + \fi + + \ifnum\bottom=1 + { + \node[greenshape, rounded corners, minimum width=.5cm, minimum height=2cm, below of=unit#4\i, node distance=3cm] (bottom#4\i) { }; + \draw[Triangle-, uthickline] (unit#4\i) -- (bottom#4\i); + } + \fi + + \ifnum\i>1 + \draw[-Triangle, uthickline] (unit#4\j) -- (unit#4\i); + \fi + } +} + +\rnnunit{}{12}{0}{2}{}{5}; +\node[above of=unit23, node distance=4.5cm] {}; +%Many to many}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-2-d-many-to-many-2.tex b/tikz/figure7-2-d-many-to-many-2.tex new file mode 100644 index 0000000..f5eb8b7 --- /dev/null +++ b/tikz/figure7-2-d-many-to-many-2.tex @@ -0,0 +1,43 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{graphicx} %package to manage images +\graphicspath{ {./images/} } + +\usepackage{arrayjob} + +\begin{document} +\begin{tikzpicture} + +\newcommand\rnnunit[6] +{ + \foreach \i in {1,...,#6} + { + \pgfmathparse{\i-1}\edef\j{\pgfmathresult}; + + \node[blueshape, rounded corners, minimum width=.5cm, minimum height=2cm] (unit#4\i) at (#2+\i*1.5,#3) { }; + \node[rotate=90, below of=unit#4\i, node distance=0cm] {Unit}; + + \node[redshape, rounded corners, minimum width=.5cm, minimum height=2cm, above of=unit#4\i, node distance=3cm] (top#4\i) { }; + \draw[-Triangle,uthickline] (unit#4\i) -- (top#4\i); + + \node[greenshape, rounded corners, minimum width=.5cm, minimum height=2cm, below of=unit#4\i, node distance=3cm] (bottom#4\i) { }; + \draw[Triangle-,uthickline] (unit#4\i) -- (bottom#4\i); + + \ifnum\i>1 + \draw[-Triangle,uthickline] (unit#4\j) -- (unit#4\i); + \fi + } +} + +\rnnunit{}{21}{0}{3}{}{3}; +\node[above of=unit32, node distance=4.5cm] {}; +%Many to many}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-3-unrolling-rnn.tex b/tikz/figure7-3-unrolling-rnn.tex new file mode 100644 index 0000000..d1fb0f0 --- /dev/null +++ b/tikz/figure7-3-unrolling-rnn.tex @@ -0,0 +1,59 @@ +\documentclass[border=0.2cm]{standalone} + +% More defined colors +\usepackage[dvipsnames]{xcolor} +\usepackage{tikz} +\usepackage{xstring} +\usepackage{pgfmath,pgffor} +\usepackage{arrayjob} +\usepackage{medl_colors} + +\usetikzlibrary{arrows.meta,shapes.arrows, shapes.misc} +\usetikzlibrary{positioning} +\usetikzlibrary{cd, fit, calc} +\usepackage{textcomp} + +\begin{document} +\begin{tikzpicture} + +\newcommand{\numlayerA}{3} +\newcommand{\nodedis}{8} + +\newarray\indicesarray +\readarray{indicesarray}{-1&&+1} + + +\node [blueshape, rounded corners, minimum width=2cm, minimum height=1cm] (controller1) at (0, 0) {\Large $ h ^{\langle{} t \rangle{} } $ }; +\node [redshape, rounded corners, minimum width=1.5cm, minimum height = 2cm, above of=controller1, node distance=2.5cm ] (circlea1) {\Large $ \hat{y} ^{\langle{} t \rangle{} } $ }; +\node [greenshape, rounded corners, minimum width=1.5cm, minimum height = 2cm, below of=controller1, node distance=2.5cm ] (circleb1) {\Large $ x ^{\langle{} t \rangle{} } $ }; + +\draw [Triangle-, uthickline] (circlea1.south) -- (controller1.north) node[midway,right] {}; +\draw [-Triangle, uthickline] (circleb1.north) -- (controller1.south) node[midway,right] {}; +\draw[-Triangle, uthickline] ($(controller1.north west)+(0.5,0)$) -- ++ (0,0) arc[start angle=20, end angle=331, x radius=1.2cm, y radius =1.2cm] node[midway, right] (feedbackcircle) {}; + +\node[uthickline, double arrow, minimum height=10mm, minimum width=.8mm, single arrow head extend=1mm, anchor=west, right of=controller1, node distance=2.5cm] (arrowh) {}; + +\node[right of=arrowh, node distance=1.5cm] (dot1) {- -}; +\draw [-Triangle, uthickline] (dot1.east)+(.1cm,1pt) -- node[below] (arrow1) {} ++(.6,1pt); +%\node[below of=circleb1, node distance=1cm] (textrecgraph) {Recursive graph}; + +%\node [ rounded corners, draw, inner sep = 3mm, fit={(feedbackcircle) (controller1) (circlea1) (textrecgraph)} ] {}; + +\foreach \i in {1,...,\numlayerA} +{ + \node [blueshape, rounded corners,minimum width=2cm, minimum height=1cm] (controller\i) at (3 + \i*3, 0) {\Large $ h ^{\langle{} t\indicesarray(\i) \rangle{} } $}; + \node [redshape, rounded corners, minimum width=1.5cm, minimum height = 2cm, above of=controller\i, node distance=2.5cm ] (circlea\i) {\Large $ \hat{y} ^{\langle{} t\indicesarray(\i) \rangle{} } $ }; + \node [greenshape, rounded corners, minimum width=1.5cm, minimum height = 2cm, below of=controller\i, node distance=2.5cm ] (circleb\i) {\Large $ x ^{\langle{} t\indicesarray(\i) \rangle{} } $ }; + \draw [Triangle-, uthickline] (circlea\i.south) -- (controller\i.north) node[midway,right] {}; + \draw [-Triangle, uthickline] (circleb\i.north) -- (controller\i.south) node[midway,right] {}; + \draw [-Triangle, uthickline] (controller\i.east)+(.1cm,1pt) -- node[below] (arrow\i) {} ++(.8,1pt); +} + +%\node[below of=circleb2, node distance=1cm] (textunfoldgraph) {Unfolded graph}; + +\node[right of=controller3, node distance=2.3cm](dot2) {- -}; +\%node [rounded corners, draw, inner sep = 3mm, fit={(dot1) (dot2) (circlea2) (textunfoldgraph)}] {}; + + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-4-rnn-unit.tex b/tikz/figure7-4-rnn-unit.tex new file mode 100644 index 0000000..4662ab0 --- /dev/null +++ b/tikz/figure7-4-rnn-unit.tex @@ -0,0 +1,61 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\begin {document} +\begin{tikzpicture}[node distance=2cm] + +\node[lightblueshape,rounded corners,inner xsep = 3mm, inner ysep=1cm, minimum width=10cm,minimum height=8cm] (largerec) at(-.5,0){}; + +\matrix[row sep=1cm,column sep=1cm] { + \node [] (node-11) {\large $W_{hh}$ }; & + \node [] (node-12) {\large $b_{y}$ }; & + \node [ minimum size=0cm] (node-13) { }; & + \node [draw, uthickline, circle, minimum size=.6cm] (node-14) {\large $\times$ }; & + \node [] (node-15) {\large $W_{yh}$}; & + \\ + \node [draw, uthickline, circle, minimum size=.6cm] (node-21) {\large $\times$ }; & + \node [] (node-22) {}; & + \node [draw, uthickline, circle, minimum size=.6cm] (node-23) {\large $+$ }; & + \node [circle, minimum size=.6cm, xshift=1.5cm] (node-24) { }; & + \node [] (node-25) {\large $S_h(\cdot)$ }; & + \\ + \node [] (node-31) {}; & + \node [] (node-32) {\large $W_{hx}$ }; & + \node [draw, uthickline, circle, minimum size=.6cm] (node-33) {\large $\times$ }; & + \node [draw, uthickline, circle, minimum size=.6cm, yshift=1.5cm] (node-34) {\large $+$ }; & + \node [] (node-35) {\large $b_{h}$ }; & + \\ + }; + +\node [above of = node-13, node distance = .8cm] (node-03) {\large $S_{y}(\cdot)$}; + +\node [redshape, rounded corners, minimum width=1.3cm, minimum height=2cm, above of = node-13, node distance = 3.5cm](rect1) {\large $ \hat{y} ^{\langle{} t \rangle{} } $}; +\node [greenshape, rounded corners, minimum width=1.3cm, minimum height=2cm, below of = node-33, node distance = 3.5cm](rect2) {\large $ x ^{\langle{} t \rangle{} } $}; +\node [blueshape, rounded corners, minimum width=1.3cm, minimum height=2cm, left of = node-21, node distance = 2.5cm](rect3) {\large $ h ^{\langle{} t-1 \rangle{} } $}; +\node [blueshape, rounded corners,minimum width=1.3cm, minimum height=2cm, right of = node-25, node distance = 2.4cm](rect4) {\large $ h ^{\langle{} t \rangle{} } $}; + +\draw[-Triangle, uthickline] (node-12) |- (node-23); +\draw[-Triangle, uthickline] (node-11) -- (node-21); +\draw[-Triangle, uthickline] (node-21) |- (node-34); +\draw[-Triangle, uthickline] (node-32) -- (node-33); +\draw[-Triangle, uthickline] (node-23) -- (node-03); +\draw[-Triangle, uthickline] (node-14.west) |- ++(-5mm, 0) |- (node-23); +\draw[-Triangle, uthickline] (node-33) -| (node-34); +\draw[-Triangle, uthickline] (node-35) |- (node-34); +\draw[-Triangle, uthickline] (node-34) |- (node-25); +\draw[-Triangle, uthickline] (node-24) -- (node-25); +\draw[-Triangle, uthickline] (node-25.north) |- ++(0, 5mm) -| (node-14); +\draw[-Triangle, uthickline] (node-15) -- (node-14); +\draw[-Triangle, uthickline] (node-13) -- (node-03); +\draw[-Triangle, uthickline] (node-03) -- (rect1); +\draw[-Triangle, uthickline] (rect2) -- (node-33); +\draw[-Triangle, uthickline] (rect3) -- (node-21); +\draw[-Triangle, uthickline] (node-25) -- (rect4); + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure7-5-rnn-simple-example.tex b/tikz/figure7-5-rnn-simple-example.tex new file mode 100644 index 0000000..4bf6d4d --- /dev/null +++ b/tikz/figure7-5-rnn-simple-example.tex @@ -0,0 +1,111 @@ +\documentclass[tikz, border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{graphicx} %package to manage images +\graphicspath{ {./images/} } +\usepackage{ifthen} + +\usepackage{arrayjob} + +\begin{document} +\begin{tikzpicture} + +\pgfdeclarelayer{background} +\pgfsetlayers{background, main} + +\def\numsA{{ + {"0.2", "0.05", "0.05", "0.1", "0.4", "0.1", "0.05", "0.05"}, + {"0.01", "0.55", "0.09", "0.02", "0.08", "0.1", "0.1", "0.05"}, + {"0.05", "0.15", "0.05", "0.1", "0.04", "0.35", "0.2", "0.06"}, + {"0.3", "0.37", "0.03", "0.05", "0.02", "0.03", "0.09", "0.11"}, + {"0.02", "0.52", "0.03", "0.12", "0.03", "0.03", "0.21", "0.04"} +}}; + +\def\numsB{{ + {"0", "0", "0", "0", "0", "0", "0", "1"}, + {"0", "0", "0", "0", "1", "0", "0", "0"}, + {"0", "1", "0", "0", "0", "0", "0", "0"}, + {"0", "0", "0", "0", "0", "1", "0", "0"}, + {"1", "0", "0", "0", "0", "0", "0", "0"} +}}; + +\def\spec{{ + {"the", "mathematical", "engineering", "of", "deep"}, + {"mathematical", "engineering", "of", "engineering", "learning"}, + {"mathematical", "engineering", "of", "deep", "learning"}, + {"deep", "engineering", "learning", "machine", "mathematical", "of", "statistics", "the"}, + {"4", "1", "5", "1", "2", "3"} +}}; + +\node[greylayer, thick, minimum width=11.2cm, minimum height=.5cm] at (7.4,5.7) (rect1) {}; +\node[redlayer, thick, minimum width=11.2cm, minimum height=.5cm] at (7.4,4.7) (rect2) {}; +\node[greenlayer, thick, minimum width=11.2cm, minimum height=.5cm] at (7.4,-4.7) (rect3) {}; + +\foreach \i in {1,...,5} +{ + \pgfmathparse{\i-1}\edef\j{\pgfmathresult}; + + \node[blueshape, rounded corners, minimum width=1cm, minimum height=.5cm] (unit\i) at (\i*2.5, 0) { \tiny $h^{\langle \i \rangle}$}; + + \node[redshape, rounded corners, minimum width=.5cm, minimum height=2.6cm, above of=unit\i, node distance=2.5cm] (top\i) { }; + + \draw[-Triangle, thickline] (unit\i) -- (top\i) node[pos=.43, fill=white] {\tiny $W_{yh}$}; + + \node[greenshape, rounded corners, minimum width=.5cm, minimum height=2.6cm, below of=unit\i, node distance=2.5cm] (bottom\i) { }; + \draw[Triangle-, thickline] (unit\i) -- (bottom\i) node[pos=.57, fill=white] {\tiny $W_{hx}$}; + + \ifnum\i>1 + \draw[-Triangle, thickline] (unit\j) -- (unit\i) node[pos=.45, fill=white] {\tiny $W_{hh}$};; + \fi + + \pgfmathparse{\spec[0][\j]} \edef\bword{\pgfmathresult}; + \pgfmathparse{\spec[1][\j]} \edef\tword{\pgfmathresult}; + \pgfmathparse{\spec[2][\j]} \edef\ttword{\pgfmathresult}; + \pgfmathparse{int(\spec[4][\j])} \edef\cindex{\pgfmathresult}; + + \node [draw=border-light-red, circle, minimum size=4mm, fill=fill-light-red] at (\i*2.5, 3.6-\cindex*.3) {}; + + \node[below of=bottom\i, node distance=2.2cm] (bword\i) { \texttt {\tiny \bword}}; + \ifthenelse{\i = 4} + { + \node[above of=top\i, node distance=2.2cm, red] (tword\i) { \texttt {\tiny \tword}}; + \node[above of=top\i, node distance=3.2cm, red] (ttword\i) { \texttt {\tiny \ttword}}; + \draw[-, red, thick] ($(top\i.north)+(0,1.1)$) -- (top\i |- rect1.south); + } + { + \node[above of=top\i, node distance=2.2cm] (tword\i) { \texttt {\tiny \tword}}; + \node[above of=top\i, node distance=3.2cm] (ttword\i) { \texttt {\tiny \ttword}}; + \draw[-, border-light-grey, thick] ($(top\i.north)+(0,1.1)$) -- (top\i |- rect1.south); + } + + \draw[-Triangle, thickline] ($(bword\i.north)+(0,.1)$) -- (bottom\i); + \draw[-Triangle, thickline] (top\i) -- (top\i |- rect2.south); + + \foreach \k in {0,...,7} + { + \pgfmathparse{\numsA[\j][\k]} \edef\tnum{\pgfmathresult}; + \pgfmathparse{\numsB[\j][\k]} \edef\ttnum{\pgfmathresult}; + + \node[] at (\i*2.5, 3.6-\k*.3) (ttext\i\k) { \texttt {\tiny \tnum}}; + \node[] at (\i*2.5, -1.4-\k*.3) (btext\i\k) { \texttt {\tiny \ttnum}}; + } +} + +\foreach \k in {0,...,7} +{ + \pgfmathparse{\spec[3][\k]} \edef\ttword{\pgfmathresult}; + \node[align=left, text width=2.2cm] at (1.5, 3.6-\k*.3) (ttext0\k) { \texttt {\tiny \ttword:}}; +} + +\node[rounded corners, minimum width=1cm, minimum height=.5cm, left of = btext13, node distance=2cm] (encoded) { \footnotesize One-hot encoded:}; +\node[left of = bword1, node distance = 1.25cm,font=\footnotesize] {Input:}; +\node[left of = tword1, node distance = 1.55cm,font=\footnotesize] {Prediction: }; +\node[left of = ttword1, node distance = 1.3cm,font=\footnotesize] {Target:}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-6-back-prop-through-time.tex b/tikz/figure7-6-back-prop-through-time.tex new file mode 100644 index 0000000..d75208e --- /dev/null +++ b/tikz/figure7-6-back-prop-through-time.tex @@ -0,0 +1,71 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +%Nodes +\matrix[row sep=2.2cm,column sep=2cm] (m1) { + & + \node [align=center] (node21) {\large $h^{\langle 1\rangle}$}; & + \node [align=center] (node22) {\large $h^{\langle 2\rangle}$}; & + \node [align=center] (node23) {\large $h^{\langle T-1 \rangle}$}; & + \node [align=center] (node24) {\large $h^{\langle T \rangle}$}; & + \\ + & + \node [align=center, xshift=-.5cm] (node31) {\large $\zeta^{\langle 1 \rangle}$}; & + \node [align=center, xshift=-.5cm] (node32) {\large $\zeta^{\langle 2 \rangle}$}; & + \node [align=center, xshift=-.5cm] (node33) {\large $\zeta^{ \langle T-1 \rangle }$}; & + \node [align=center, xshift=-.5cm] (node34) {\large $\zeta^{\langle T \rangle}$}; & + \\ + }; + +\node[] at (0, 5) (t1) {\large $W$}; +\draw[-Triangle, thickline] (t1) -- (node21); +\draw[-Triangle, thickline] (t1) -- (node22); +\draw[-Triangle, thickline] (t1) -- (node23); +\draw[-Triangle, thickline] (t1) -- (node24); + +\node[] at (0, -5) (t2) {\large $g_W$}; +\draw[Triangle-, thickline] (t2) -- (node31); +\draw[Triangle-, thickline] (t2) -- (node32); +\draw[Triangle-, thickline] (t2) -- (node33); +\draw[Triangle-, thickline] (t2) -- (node34); + +\draw[Triangle-, thickline] (node21) -- ++(0, -.7) node[pos=1.7] {\large $x^{\langle 1 \rangle}$}; +\draw[Triangle-, thickline] (node22) -- ++(0, -.7) node[pos=1.7] {\large $x^{\langle 2\rangle}$}; +\draw[Triangle-, thickline] (node23) -- ++(0, -.7) node[pos=1.7] {\large $x^{\langle T-1\rangle}$}; +\draw[Triangle-, thickline] (node24) -- ++(0, -.7) node[pos=1.7] {\large $x^{\langle T\rangle}$}; + +\draw [dashed] ([xshift=.5cm]node22.east) -- ([xshift=-.5cm]node23.west) node[] {}; +\draw [dashed] ([xshift=.5cm]node32.east) -- ([xshift=-.5cm]node33.west) node[] {}; + +\draw [-Triangle, thickline] ([xshift=1.1cm]node21.west) -- ([xshift=-1.1cm]node22.east); +\draw [-Triangle, thickline] ([xshift=1.4cm]node23.west) -- ([xshift=-1.4cm]node24.east); + +\draw [-Triangle, thickline] ([xshift=-.5cm]node32.west) -- ([xshift=.5cm]node31.east); +\draw [-Triangle, thickline] ([xshift=-.5cm]node34.west) -- ([xshift=.5cm]node33.east); + +\node[below of = t2, node distance=.8cm, align=center] {\large Gradient}; +\node[above of = t1, node distance=.8cm, align=center] {\large Shared Parameter}; + +\node[below right = 0mm and 1mm of node22, align=center] (textforward) {\large Forward}; +\node[above right = 0mm and 5mm of node32, align=center] {\large Backward}; + +\node[rounded corners, bthickline, below right = 9mm and 1cm of node24] (nodec) {\large Loss : $C$}; + +\node[above left = 1.5cm and -2.5cm of nodec.west, align=center] (nodey) { $y^{\langle 1\rangle},\ldots,y^{\langle T\rangle}$\\ $\hat{y}^{\langle 1 \rangle},\ldots,\hat{y}^{\langle T \rangle}$}; +\draw [-Triangle, thickline] ([yshift=-2mm]nodey.south) -- ([yshift=2mm, xshift=5mm]nodec.north); + +\path (node24.east)edge [-Triangle, thickline, out=0,in=90] node [midway, anchor=center] {} (nodec.north); + +\path (nodec.south)edge [-Triangle, thickline, out=270,in=0] node [midway, anchor=center] {} (node34.east); + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-7-a-bidirectional-rnn.tex b/tikz/figure7-7-a-bidirectional-rnn.tex new file mode 100644 index 0000000..6ed97e9 --- /dev/null +++ b/tikz/figure7-7-a-bidirectional-rnn.tex @@ -0,0 +1,51 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{ifthen} +\usepackage{medl_colors} +\usepackage{arrayjob} + +\usepackage{graphicx} %package to manage images +\graphicspath{ {./images/} } + +\begin{document} +\begin{tikzpicture} + +\node[draw, dashed, border-grey, rounded corners, minimum width=9.5cm, minimum height=1cm] at (6,0) (rect1) {}; +\node[draw, dashed, border-grey, rounded corners, minimum width=9.5cm, minimum height=1cm] at (7,-1.5) (rect2) {}; + +\foreach \i in {1,...,5} +{ + \pgfmathparse{\i-1}\edef\j{\pgfmathresult}; + \ifthenelse{\i = 4} + { + \node[] (unit1\i) at (\i*2, 0) { - - - }; + \node[] (unit2\i) at (1+\i*2, -1.5) { - - - }; + \node[below of=unit1\i, node distance=4cm] (bottom1\i) { - - - }; + \node[above of=unit2\i, node distance=4cm] (bottom2\i) { - - - }; + } + { + \node[blueshape, rounded corners, minimum width=1cm, minimum height=.5cm] (unit1\i) at (\i*2, 0) {\footnotesize Unit}; + \node[blueshape, rounded corners, minimum width=1cm, minimum height=.5cm] (unit2\i) at (1+\i*2, -1.5) { \footnotesize Unit}; + \node[greenshape, rounded corners, minimum width=.5cm, minimum height=2cm, below of=unit1\i, node distance=4cm] (bottom1\i) { }; + \node[redshape, rounded corners, minimum width=.5cm, minimum height=2cm, above of=unit2\i, node distance=4cm] (bottom2\i) { }; + + \draw[Triangle-,thickline] (unit1\i) -- (bottom1\i.north); + \draw[-Triangle,thickline] (unit1\i) -- ([xshift=-2mm]bottom2\i.south); + + \draw[-Triangle,thickline] (unit2\i) -- (bottom2\i.south); + \draw[Triangle-,thickline] (unit2\i) -- (bottom1\i.north); + } + + \ifnum\i>1 + \draw[-Triangle,thickline] (unit1\j) -- (unit1\i); + \draw[Triangle-,thickline] (unit2\j) -- (unit2\i); + \fi +} + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-7-b-stacked-rnn.tex b/tikz/figure7-7-b-stacked-rnn.tex new file mode 100644 index 0000000..fed88f0 --- /dev/null +++ b/tikz/figure7-7-b-stacked-rnn.tex @@ -0,0 +1,57 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{ifthen} +\usepackage{medl_colors} +\usepackage{arrayjob} + +\begin{document} +\begin{tikzpicture} + +\node[draw, dashed, border-grey, rounded corners, minimum width=9.5cm, minimum height=1cm] at (6,0) (rect1) {}; +\node[draw, dashed, border-grey, rounded corners, minimum width=9.5cm, minimum height=1cm] at (6,-3) (rect2) {}; +\node[draw, dashed, border-grey, rounded corners, minimum width=9.5cm, minimum height=1cm] at (6,-4.5) (rect2) {}; + +\foreach \i in {1,...,5} +{ + \pgfmathparse{\i-1}\edef\j{\pgfmathresult}; + + \ifthenelse{\i = 4} + { + \node[] (unit1\i) at (\i*2, 0) {\Large ... }; + \node[] (unit2\i) at (\i*2, -1.5) {\Large }; + \node[] (unit3\i) at (\i*2, -3) {\Large ... }; + \node[] (unit4\i) at (\i*2, -4.5) {\Large ... }; + \node[below of=unit4\i, node distance=2cm] (bottom1\i) { \Large ... }; + \node[above of=unit1\i, node distance=2cm] (bottom2\i) { \Large ... }; + } + { + \node[blueshape, rounded corners, minimum width=1cm, minimum height=.5cm] (unit1\i) at (\i*2, 0) { \footnotesize Unit}; + \node[] (unit2\i) at (\i*2, -1.3) { \Large \vdots}; + \node[blueshape, rounded corners, minimum width=1cm, minimum height=.5cm] (unit3\i) at (\i*2, -3) { \footnotesize Unit}; + \node[blueshape, rounded corners, minimum width=1cm, minimum height=.5cm] (unit4\i) at (\i*2, -4.5) { \footnotesize Unit}; + + \node[greenshape, rounded corners, minimum width=.5cm, minimum height=2cm, below of=unit4\i, node distance=2cm] (bottom1\i) { }; + \node[redshape, rounded corners, minimum width=.5cm, minimum height=2cm, above of=unit1\i, node distance=2cm] (bottom2\i) { }; + + \draw[-Triangle, thickline] (unit1\i) -- (bottom2\i); + \draw[-Triangle, thickline] (unit2\i)++(0, 0.25) -- (unit1\i); + \draw[-Triangle, thickline] (unit3\i) -- (unit2\i); + \draw[-Triangle, thickline] (unit4\i) -- (unit3\i); + \draw[-Triangle, thickline] (bottom1\i) -- (unit4\i); + } + + \ifnum\i>1 + \draw[-Triangle, thickline] (unit1\j) -- (unit1\i); + \draw[-Triangle, thickline] (unit3\j) -- (unit3\i); + \draw[-Triangle, thickline] (unit4\j) -- (unit4\i); + \fi + +} + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-8-a-lstm.tex b/tikz/figure7-8-a-lstm.tex new file mode 100644 index 0000000..83a4a1a --- /dev/null +++ b/tikz/figure7-8-a-lstm.tex @@ -0,0 +1,87 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\usetikzlibrary{decorations.markings} + + +\tikzset{middlearrow/.style={ + decoration={markings, + mark= at position .5 with {\arrow{Triangle}} + }, + postaction={decorate} + } +} + +\begin{document} + +\begin{tikzpicture}[node distance=2cm] + +\node[lightblueshape, rounded corners, inner xsep = 3mm, inner ysep=1cm, minimum width=8.5cm,minimum height=6cm] (largerec) at(-.5,0){}; + +\matrix[row sep=0.8cm,column sep=0.8cm] { + \node [draw, uthickline, circle, minimum size=.6cm] (circle1) { . }; & + & + \node[draw, uthickline, circle, minimum size=.6cm] (circle2) { + }; & + \node[label={\large $ c ^{\langle{} t \rangle{} } $}] (hid) { }; & + \node (hid) { }; & + \\ + & + & + \node [draw, uthickline, circle, minimum size=.6cm] (circle3) { . }; & + & + \node [draw, uthickline, circle, minimum size=.6cm] (circle4) { . }; & + \\ + \node (rect) [draw, rounded corners, yellowshape, minimum width=.6cm,minimum height=1.2cm] (rect1) { {$ g_f ^{\langle{} t \rangle{} } $ }}; & + \node (rect) [draw, rounded corners, yellowshape, minimum width=.6cm,minimum height=1.2cm] (rect2) { {$ g_i ^{\langle{} t \rangle{} } $ }}; & + \node (rect) [draw, rounded corners, lightgreyshape, minimum width=.6cm,minimum height=1.2cm] (rect3) { {$ \tilde c ^{\langle{} t \rangle{} } $ }}; & + \node (rect) [draw, rounded corners, yellowshape, minimum width=.6cm,minimum height=1.2cm] (rect4) { {$ g_o ^{\langle{} t \rangle{} } $ }}; & + & + \\ + \node (hid1) { }; & + \node (hid2) { }; & + \node (hid3) { }; & + \node (hid4) { }; & + \node (hid5) { }; & + & + \\ + }; + +\node [greenshape, rounded corners, minimum width=1.3cm, minimum height=2cm] at ($(rect1.east)+(-.5,-4)$)(rect5) {\large $ x ^{\langle{} t \rangle{} } $}; + +\node [blueshape,rounded corners, minimum width=1.3cm, minimum height=2cm, node distance=3cm, left of=circle1] (rect6) {\large $ c ^{\langle{} t-1 \rangle{} } $}; + +\node [blueshape,rounded corners, minimum width=1.3cm, minimum height=2cm, node distance=3cm, left of=hid1] (rect7) {\large $ h ^{\langle{} t-1 \rangle{} } $}; + +\node [blueshape, rounded corners, minimum width=1.3cm, minimum height=2cm, node distance=6.5cm, right of=circle2] (rect8) {\large $ c ^{\langle{} t \rangle{} } $}; + +\node [blueshape,rounded corners, minimum width=1.3cm, minimum height=2cm, above right = 7cm and .1cm of hid5] (rect9) {\large $ h ^{\langle{} t \rangle{} } $}; + +\node [blueshape,rounded corners, minimum width=1.3cm, minimum height=2cm, node distance=3.5cm, right of=hid5] (rect10) {\large $ h ^{\langle{} t \rangle{} } $}; + +\draw[-Triangle, thickline] (rect1.north) -- (circle1.south) {}; +\draw[-Triangle, thickline] (circle3.north) -- (circle2.south) {}; +\draw [thickline](circle1.east) -- (circle2.west) {}; +\draw [thickline](rect3.north) -- (circle3.south) {}; +\draw[-Triangle, thickline] (rect2) |- (circle3); +\draw[-Triangle, thickline] (rect4) |- (circle4); + +\draw (hid.center) -- (circle4) node[midway,anchor=center,fill=fill-light-blue] {$S_{\text{Tanh}}(\cdot)$}; +\draw (rect4) -- (hid4.center) node[midway,anchor=center,fill=fill-light-blue] {$S_{\text{Sig}}(\cdot)$}; +\draw (rect3) -- (hid3.center) node[midway,anchor=center,fill=fill-light-blue] {$S_{\text{Tanh}}(\cdot)$}; +\draw (rect2) -- (hid2.center) node[midway,anchor=center,fill=fill-light-blue] {$S_{\text{Sig}}(\cdot)$}; +\draw (rect1) -- (hid1.center) node[midway,anchor=center,fill=fill-light-blue] {$S_{\text{Sig}}(\cdot)$}; +\draw [thickline](circle4) -- (hid5.center) node[] {}; +\draw[-Triangle, thickline] (hid1.center) -- (rect10) {}; +\draw[Triangle-,thickline] (hid1.west) -- ++(0,-1.5){}; +\draw [middlearrow,thickline] (rect7) -- (hid1.center) node[ above, pos=.3] {}; +\draw [-Triangle, thickline] (circle2) -- (rect8); +\draw [middlearrow,thickline] (rect6) -- (circle1); +\draw [Triangle-,thickline] (rect9) -- (rect9 |- hid5); + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure7-8-b-gru.tex b/tikz/figure7-8-b-gru.tex new file mode 100644 index 0000000..8fcb1cd --- /dev/null +++ b/tikz/figure7-8-b-gru.tex @@ -0,0 +1,84 @@ +\documentclass[tikz, border=50pt]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usepackage{amsmath,xstring} +\usepackage{ifthen} +\usetikzlibrary{shapes.multipart, shapes.geometric, arrows.meta, decorations.pathreplacing, calligraphy} +\usetikzlibrary{matrix, calc, positioning,fit, backgrounds} +\usetikzlibrary{decorations.markings} + +\begin{document} + +\tikzset{middlearrow/.style={ + decoration={markings, + mark= at position .1 with {\arrow{Triangle}} + }, + postaction={decorate} + } +} + +\begin{tikzpicture}[node distance=2cm] + +\node[lightblueshape,rounded corners,inner xsep = 3mm, inner ysep=1cm, minimum width=8.5cm,minimum height=7cm] (largerec) at(-.5,0){}; + +\matrix[row sep=0.8cm,column sep=0.8cm] { + \node (hid) { }; & + & + \node [draw, uthickline,circle, minimum size=.6cm] (circle1) { . }; & + \node [draw, uthickline, circle, minimum size=.6cm, xshift=2cm] (circle2) {\small $+$ }; & + \\ + \node [draw, uthickline, circle, minimum size=.6cm] (circle3) { . }; & + & + \node [draw, uthickline,circle, minimum size=.6cm] (circle4) {\tiny $1 - $ }; & + \node [draw, uthickline, circle, minimum size=.6cm, xshift=2cm, yshift=-1cm] (circle5) { . }; & + \\ + & + \node (rect) [yellowshape, rounded corners, minimum width=.6cm,minimum height=1.2cm] (rect1) { {$ g_r ^{\langle{} t \rangle{} } $ }}; & + \node (rect) [yellowshape, rounded corners, minimum width=.6cm,minimum height=1.2cm] (rect2) { {$ g_u ^{\langle{} t \rangle{} } $ }}; & + \node (rect) [lightgreyshape, rounded corners, minimum width=.6cm,minimum height=1.2cm, xshift=2cm] (rect3) { {$ \tilde h^{\langle{}t\rangle{}}$ }}; & + \\ + \node (hid1) { }; & + \node (hid2) { }; & + \node (hid3) { }; & + \node [yshift=-.5cm] (hid4) { }; & + \\ + }; + +\node [greenshape,rounded corners, minimum width=1.3cm, minimum height=2cm] at ($(rect1.east)+(-2.5,-4.5)$)(rect5) {\large $ x^{\langle{} t \rangle{} } $}; + +\node [blueshape, rounded corners, minimum width=1.3cm, minimum height=2cm, left of = circle1, node distance = 6cm] (rect6) {\large $ h ^{\langle{} t-1 \rangle{} } $}; + +\node [blueshape, rounded corners, minimum width=1.3cm, minimum height=2cm, right of = circle2, node distance = 4cm] (rect7) {\large $ h ^{\langle{} t \rangle{} } $}; + +\node [blueshape, rounded corners, minimum width=1.3cm, minimum height=2cm, above right = 1cm and 1cm of circle2] (rect8) {\large $ h ^{\langle{} t \rangle{} } $}; + +%Connecting first row and second row + +\draw[middlearrow,thickline](rect6) -- (circle1); +\draw [thickline](circle1) -- (circle2); +\draw[Triangle-,thickline] (rect8) -- (rect8 |- circle2); +\draw[-Triangle,thickline] (circle2) -- (rect7); +\draw[-Triangle,thickline] (hid) -- (circle3); +\draw[-Triangle,thickline] (circle4.north) -- (circle1.south); +\draw[-Triangle,thickline] (circle5.north) -- (circle2.south); +\draw[Triangle-,thickline] (circle5) -- (rect2 |- circle5); + +%Connecting second row and third row +\draw [thickline](circle3) -- (hid1); +\draw[-Triangle,thickline] (rect1) |- (circle3); +\draw [thickline](circle4) -- (rect2); +\draw [thickline](rect3.north) -- (circle5.south); + +%Connecting third row and third row +\draw [thickline](rect1) -- (hid2.center) node[midway,anchor=center,fill=fill-light-blue] {$S_{\text{Sig}}(\cdot)$}; +\draw [thickline](rect2) -- (hid3.center) node[midway,anchor=center, fill=fill-light-blue] {$S_{\text{Sig}}(\cdot)$}; +\draw [thickline](rect3) -- ([xshift=2cm]hid4.center) node[midway,anchor=center, fill=fill-light-blue] {$S_{\text{Tanh}}(\cdot)$}; +\draw [thickline](hid3) -- (rect5 |- hid3); +\draw [thickline](rect5 |- hid4) -- ++(7,0); + +\draw [thickline](hid1) -- (hid1 |- hid4); +\draw[middlearrow,thickline] (rect5) -- (rect5 |- hid); + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure7-9-a-encoder-decoder-basic.tex b/tikz/figure7-9-a-encoder-decoder-basic.tex new file mode 100644 index 0000000..deb9369 --- /dev/null +++ b/tikz/figure7-9-a-encoder-decoder-basic.tex @@ -0,0 +1,79 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{fontspec} + +\usepackage{arrayjob} +\def\words{{ + {"We","enjoyed","writing", "this", "book"}, + {"Nous","avons","aimé", "écrire", "ce", "livre", ""}, + {"", "Nous","avons","aimé", "écrire", "ce", "livre"} +}} + +\pgfdeclarelayer{background} +\pgfsetlayers{background, main} + +\newcommand\rnnunit[7] +{ + \foreach \i in {1,...,#4} + { + \pgfmathparse{int(\i-1)}\edef\j{\pgfmathresult}; + \pgfmathparse{\words[#5][\j]} \edef\topword{\pgfmathresult}; + \pgfmathparse{\words[#6][\j]} \edef\bottomword{\pgfmathresult}; + + \node[blueshape, rounded corners, minimum width=1cm, minimum height=1cm] (unit\i#1) at (#2+\j*2, #3) { Unit }; + \node[below of=unit\i#1, node distance= 2cm] (bottom\i-#1) {\texttt{ \bottomword} }; + \draw[-Triangle, uthickline] (bottom\i-#1) -- (unit\i#1); + + \ifnum#7>1 + \node[above of=unit\i#1, node distance= 2cm] (top\i-#1) { \texttt{ \topword }}; + \draw[Triangle-, uthickline] (top\i-#1) -- (unit\i#1); + \ifnum\i>1 + \draw[-Triangle, uthickline, bend right, looseness=1] (top\j-#1.east) to[out=90, in=-90] ([xshift=-6mm]bottom\i-#1); + \fi + \fi + + \ifnum\i>1 + \draw[-Triangle, uthickline] (unit\j#1) -- (unit\i#1); + \fi + } +} + +\newcommand\fullthing[3] +{ + \rnnunit{a#1}{0}{#2}{5}{0}{0}{1}; + \node[draw, thick, rounded corners, minimum width=.7cm, minimum height=3cm, right of=unit5a#1, node distance=2cm] (block#1) {}; + \node[rotate=90, below of=block#1, node distance=0cm] (code) {Context Vector}; + \node[below of=code, node distance=2cm]{\LARGE #3}; + \rnnunit{b#1}{12}{#2}{7}{1}{2}{2}; + \draw[-Triangle, uthickline] (unit5a#1) -- (block#1); + \draw[-Triangle, uthickline] (block#1) -- (unit1b#1); + \begin{pgfonlayer}{background} + \node [greenshape, rounded corners, minimum width=9.5cm, minimum height=2.5cm, below of=unit3a#1, node distance=0cm] (rect1#1) {}; + \node [redshape, rounded corners, minimum width=13.5cm, minimum height=2.5cm, below of=unit4b#1, node distance=0cm] (rect2#1) {}; + \node [bluelayer, minimum width=10.2cm, minimum height=8cm, below of=unit3a#1, node distance=.4cm] (rect3#1) {}; + \node [redlayer, minimum width=14cm, minimum height=8cm, below of=unit4b#1, node distance=.4cm] (rect4#1) {}; + \end{pgfonlayer} + + \node [below left = -1cm and -2.5cm of rect3#1] {\LARGE Encoder }; + \node [below right = -1cm and -2.5cm of rect4#1] {\LARGE Decoder }; + + \node [below of=rect1#1, node distance=2.8cm] {\Large Input} ; + \node [above of=rect2#1, node distance=3cm] {\Large Output}; + + \draw[uthickline] ([xshift=2mm, yshift=2.2cm]rect2#1.west) -- ([xshift=2mm, yshift=2.5cm]rect2#1.west) -- ([xshift=-2mm, yshift=2.5cm]rect2#1.east) -- ([xshift=-2mm, yshift=2.2cm]rect2#1.east) ; + \draw[uthickline] ([xshift=2mm, yshift=-2cm]rect1#1.west) -- ([xshift=2mm, yshift=-2.3cm]rect1#1.west) -- ([xshift=-2mm, yshift=-2.3cm]rect1#1.east) -- ([xshift=-2mm, yshift=-2cm]rect1#1.east) ; +} + +\begin{document} +\begin{tikzpicture} + +\fullthing{2}{10}{$z^\star$}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure7-9-b-encoder-decoer-enriched.tex b/tikz/figure7-9-b-encoder-decoer-enriched.tex new file mode 100644 index 0000000..2010927 --- /dev/null +++ b/tikz/figure7-9-b-encoder-decoer-enriched.tex @@ -0,0 +1,86 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings} +\usepackage{medl_colors} +\usepackage{fontspec} + +\usepackage{arrayjob} +\def\words{{ + {"We","enjoyed","writing", "this", "book"}, + {"Nous","avons","aimé", "écrire", "ce", "livre", ""}, + {"", "Nous","avons","aimé", "écrire", "ce", "livre"} +}} + +\pgfdeclarelayer{background} +\pgfsetlayers{background, main} + +\newcommand\rnnunit[7] +{ + \foreach \i in {1,...,#4} + { + \pgfmathparse{int(\i-1)}\edef\j{\pgfmathresult}; + \pgfmathparse{\words[#5][\j]} \edef\topword{\pgfmathresult}; + \pgfmathparse{\words[#6][\j]} \edef\bottomword{\pgfmathresult}; + + \node[blueshape, rounded corners, minimum width=1cm, minimum height=1cm] (unit\i#1) at (#2+\j*2, #3) { Unit }; + \node[below of=unit\i#1, node distance= 2cm] (bottom\i-#1) {\texttt{ \bottomword} }; + \draw[-Triangle, thickline] (bottom\i-#1) -- (unit\i#1); + + \ifnum#7>1 + \node[above of=unit\i#1, node distance= 2cm] (top\i-#1) { \texttt{ \topword }}; + \draw[Triangle-, thickline] (top\i-#1) -- (unit\i#1); + \ifnum\i>1 + \draw[-Triangle,thickline, bend right, looseness=1] (top\j-#1.east) to[out=90, in=-90] ([xshift=-6mm]bottom\i-#1); + \fi + \fi + + \ifnum\i>1 + \draw[-Triangle, thickline] (unit\j#1) -- (unit\i#1); + \fi + } +} + +\newcommand\fullthing[3] +{ + \rnnunit{a#1}{0}{#2}{5}{0}{0}{1}; + \node[draw, thick, rounded corners, minimum width=.7cm, minimum height=3cm, right of=unit5a#1, node distance=2cm] (block#1) {}; + \node[rotate=90, below of=block#1, node distance=0cm] (code) {Context Vector}; + \node[below of=code, node distance=2cm]{\LARGE #3}; + \rnnunit{b#1}{12}{#2}{7}{1}{2}{2}; + \draw[-Triangle, uthickline] (unit5a#1) -- (block#1); + \draw[-Triangle, uthickline] (block#1) -- (unit1b#1) node[pos=.2, above]{}; + \begin{pgfonlayer}{background} + \node [greenshape, rounded corners, minimum width=9.5cm, minimum height=2.5cm, below of=unit3a#1, node distance=0cm] (rect1#1) {}; + \node [redshape, rounded corners, minimum width=13.5cm, minimum height=2.5cm, below of=unit4b#1, node distance=0cm] (rect2#1) {}; + \node [bluelayer, minimum width=10.2cm, minimum height=8cm, below of=unit3a#1, node distance=.4cm] (rect3#1) {}; + \node [redlayer, minimum width=14.5cm, minimum height=8cm, below of=unit4b#1, node distance=.4cm] (rect4#1) {}; + + \end{pgfonlayer} + + \node [below left = -1cm and -2.5cm of rect3#1] {\LARGE Encoder }; + \node [below right = -1cm and -2.5cm of rect4#1] {\LARGE Decoder }; + + \node [below of=rect1#1, node distance=2.8cm] {\Large Input} ; + \node [above of=rect2#1, node distance=3cm] { \Large Output}; + + \draw[uthickline] ([xshift=2mm, yshift=2.2cm]rect2#1.west) -- ([xshift=2mm, yshift=2.5cm]rect2#1.west) -- ([xshift=-2mm, yshift=2.5cm]rect2#1.east) -- ([xshift=-2mm, yshift=2.2cm]rect2#1.east) ; + \draw[uthickline] ([xshift=2mm, yshift=-2cm]rect1#1.west) -- ([xshift=2mm, yshift=-2.3cm]rect1#1.west) -- ([xshift=-2mm, yshift=-2.3cm]rect1#1.east) -- ([xshift=-2mm, yshift=-2cm]rect1#1.east) ; +} + +\begin{document} +\begin{tikzpicture} + +\fullthing{1}{0}{$z^\star$}; + +\foreach \i in {1,...,7} +{ + \draw[-Triangle, draw=border-grey] ([xshift=5mm]block1.east) -- ([xshift=-6mm]top\i-b1); + \draw[-Triangle, draw=border-grey] ([xshift=5mm]block1.east) -- ([xshift=-6mm]bottom\i-b1); +} + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure8-1-general-generative-diff-gan.tex b/tikz/figure8-1-general-generative-diff-gan.tex new file mode 100644 index 0000000..8e1b099 --- /dev/null +++ b/tikz/figure8-1-general-generative-diff-gan.tex @@ -0,0 +1,55 @@ +\documentclass[border=1cm]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} + +\usetikzlibrary{shapes.geometric, shapes.misc, matrix} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning, shadows} +\graphicspath{ {./images/} } + +\begin{document} +\begin{tikzpicture} + \pgfmathsetseed{3} + +{\large \matrix (m) [matrix of math nodes, nodes in empty cells, left delimiter=[, right delimiter={]}, row sep=0.3cm, column sep=0.3cm, minimum width=0.4cm, minimum height=0.4cm, scale=0.7] at (3.5, 0) { + -2.084\\ + 0.412\\ + -0.84\\ + 0.232\\ + -0.424\\ + 0.173\\ + 0.259\\ + 0.985\\ + -1.808\\ + 0.112 \\ + }; +} + \node[below of= m, node distance=2.4cm, align=center, yshift=-3cm] {\Huge $z$}; + + \node[scale=.58] (picd) at (15,-10.5) {\includegraphics{images/collage.png}}; + + \node[below right of= picd, node distance=2.4cm, align=center, yshift=-4.2cm, xshift=4.2cm] {\Huge $\mathcal{D}$}; + + \node[scale=.5, draw, uthickline](picz) at (3.5, -21) {\includegraphics{images/noisy_image_10.jpg}}; + \node[below of= picz, node distance=2.4cm, align=center] {\Huge $z$}; + + \node[blueshape, rounded corners, minimum width=10cm, minimum height=2cm, align=center] (rect1) at (15,0) {\Large GAN Generator \\\,\\ \Large has learned to \textbf{sample} from $p(x | z)$}; + \node[draw, right of= rect1, node distance=11cm, align=center, scale=0.27] (picx1) {\includegraphics {images/18.png}}; + \node[below of= picx1, node distance=2.4cm, align=center] {\Huge $x$}; + + \node[blueshape, rounded corners, minimum width=10cm, minimum height=2cm, align=center] (rect2) at (15,-21) {\Large Diffusion Decoder \\\,\\ \Large has \textbf{learned} $p(x | z)$}; + \node[draw, right of= rect2, node distance=11cm, align=center, scale=0.2] (picx2) {\includegraphics {images/thalli1}}; + + \node[below of= picx2, node distance=2.4cm, align=center] {\Huge $x$}; + + \draw[-Triangle, uthickline] ([xshift=3mm]rect1.east) -- (picx1){}; + \draw[Triangle-, uthickline] ([xshift=-3mm]rect1.west) -- ++(-4, 0){}; + \draw[Triangle-, uthickline] ([yshift=-3mm]rect1.south) -- (picd.north){}; + \draw[-Triangle, uthickline] ([xshift=3mm]rect2.east) -- (picx2){}; + \draw[Triangle-, uthickline] ([xshift=-3mm]rect2.west) -- ++(-4, 0){}; + \draw[Triangle-, uthickline] ([yshift=3mm]rect2.north) -- (picd.south){}; + + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure8-10-a-social-networks-data.tex b/tikz/figure8-10-a-social-networks-data.tex new file mode 100644 index 0000000..0b78435 --- /dev/null +++ b/tikz/figure8-10-a-social-networks-data.tex @@ -0,0 +1,30 @@ +\documentclass[border=0.2cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +\node at (0,0)[lightblueshape,circle,minimum size=15mm, align=center,font=\small] (node1) {Emily}; +\node [lightblueshape,circle,minimum size=15mm, align=center,font=\small,right of=node1, yshift=0.75cm,node distance = 4cm] (node2) {Kayley}; +\node [lightblueshape,circle,minimum size=15mm, align=center,font=\small,above of=node1, xshift=0.75cm,node distance = 3cm] (node3) {Yarden}; +\node [lightblueshape,circle,minimum size=15mm, align=center,font=\small,below of=node1, xshift=2cm,node distance = 2cm] (node4) {Adaya}; + +\draw [dashed,thickline](node1) -- (-2,-1); +\draw [dashed,thickline](node1) -- (-1,2); +\draw [thickline](node3) -- (node2) -- (node4) -- (node3) -- (node1); +\draw [dashed,thickline](node2) -- (5,2); +\draw [dashed,thickline](node2) -- (5,0.25); +\draw [dashed,thickline](node3) -- (2,4); +\draw [dashed,thickline](node3) -- (-1,4); +\draw [dashed,thickline](node4) -- (3,-3); +\draw [dashed,thickline](node4) -- (1,-2); +\draw [dashed,thickline](node4) -- (2,-3); +\draw [dashed, thickline](node2)--(node1)node[midway,above]{\textbf{?}}--(node4)node[midway,above]{\textbf{?}}; + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure8-10-b-knowledge-graphs-data.tex b/tikz/figure8-10-b-knowledge-graphs-data.tex new file mode 100644 index 0000000..1ab5496 --- /dev/null +++ b/tikz/figure8-10-b-knowledge-graphs-data.tex @@ -0,0 +1,20 @@ +\documentclass[border=10pt]{standalone} +\usepackage{tikz} +\usepackage{medl_colors} +\usetikzlibrary{graphdrawing,graphdrawing.trees,graphs, graphs.standard, backgrounds, calc, arrows.meta, quotes, bending} +\usegdlibrary{layered} + +\begin{document} + \begin{tikzpicture} + \path (0, -2) graph [tree layout,nodes={lightblueshape, circle, minimum size=1.5cm}, level sep=1cm, sibling sep=1cm, edges={>={Triangle[round,sep,bend]}, thickline}] + { + Sheep ->["is"] Animal; + Sheep ->["eat"] Herb; + Herb ->["is"] Plant; + Plant ->["is"] Being; + Frog ->["is"] Animal; + Animal ->["is"] Being; + }; + + \end{tikzpicture} +\end{document} diff --git a/tikz/figure8-10-c-molecules.tex b/tikz/figure8-10-c-molecules.tex new file mode 100644 index 0000000..929ee26 --- /dev/null +++ b/tikz/figure8-10-c-molecules.tex @@ -0,0 +1,31 @@ +\documentclass[border=1cm]{standalone} +\usepackage{tikz} +\usepackage{chemfig} +\usepackage{medl_colors} + +\begin{document} +\setchemfig{atom sep=2em,bond style={line width=1pt, black!20}} +% \chemfig{ +% *6( +% C(=O)- +% {\color{border-blue}N}(-C(-[4]{\color{fill-grey}H})(-[6]{\color{fill-grey}H})(-[8]{\color{fill-grey}H}))- +% C(*5(-{\color{border-blue}N}=C-{\color{border-blue}N}(-C(-[8]{\color{fill-grey}H})(-[1]{\color{fill-grey}H})(-[2]{\color{fill-grey}H}))-))= +% C- +% C(=O)- +% {\color{border-blue}N}(-C(-[5]{\color{fill-grey}H})(-[4]{\color{fill-grey}H})(-[3]{\color{fill-grey}H}))- +% )} + +\begin{tikzpicture} +\node at (0,0){\chemfig{ +*6( + C(=O)- + {\color{border-blue}N}(-C(-[4]{\color{fill-grey}H})(-[6]{\color{fill-grey}H})(-[8]{\color{fill-grey}H}))- + C(*5(-{\color{border-blue}N}=C-{\color{border-blue}N}(-C(-[8]{\color{fill-grey}H})(-[1]{\color{fill-grey}H})(-[2]{\color{fill-grey}H}))))= + C- + C(=O)- + {\color{border-blue}N}(-C(-[5]{\color{fill-grey}H})(-[4]{\color{fill-grey}H})(-[3]{\color{fill-grey}H})) +)}}; +\draw [line width = 1pt, black!20](-0.76,0.25) -- (-0.76,-0.07); +\draw [line width = 1pt, black!20](0.65,0.5) -- (0.95,0.6); +\end{tikzpicture} +\end{document} diff --git a/tikz/figure8-11-a-undirected-graphs.tex b/tikz/figure8-11-a-undirected-graphs.tex new file mode 100644 index 0000000..85de412 --- /dev/null +++ b/tikz/figure8-11-a-undirected-graphs.tex @@ -0,0 +1,45 @@ +\documentclass[border=10pt]{standalone} +\usepackage{tikz} +\usepackage{medl_colors} +\usetikzlibrary{graphdrawing,graphdrawing.trees,graphs, graphs.standard, backgrounds, calc, arrows.meta, matrix} +\usegdlibrary{layered} + +\begin{document} + \begin{tikzpicture} + \path (0, -2) graph [tree layout, nodes={blueshape, circle, minimum size=1cm,empty nodes}, level sep=6mm, sibling sep=15mm, edges={thickline}] + { + 1[label = center:$v_1$]; + 2[label = center:$v_2$]; + 3[label = center:$v_3$]; + 4[label = center:$v_4$]; + 5[label = center:$v_5$]; + 6[label = center:$v_6$]; + 7[label = center:$v_7$]; + 8[label = center:$v_8$]; + 1 -- { + 3 -- {2 -- {5 -- {6, 7}}, 4, 6 -- {8}} + }; + }; + + % Matrix to the right + {\Large \matrix (m) [matrix of math nodes, nodes in empty cells, left delimiter=[, right delimiter={]}, row sep=0.3cm, column sep=0.3cm, minimum width=0.4cm, minimum height=0.4cm, scale=0.7] at (10, -5.5) { + 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 1 & 0 & 1 & 0 & 0 & 0 \\ + 1 & 1 & 0 & 1 & 0 & 1 & 0 & 0 \\ + 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 1 & 0 & 0 & 0 & 1 & 1 & 0 \\ + 0 & 0 & 1 & 0 & 1 & 0 & 0 & 1 \\ + 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ + }; + } + + % Labels for the matrix + \foreach \i in {1,...,8} + \node[anchor=east, xshift=-0.5cm] at (m-\i-1.west) {\i}; + \foreach \j in {1,...,8} + \node[anchor=north, yshift=0.7cm] at (m-1-\j.north) {\j}; + + \end{tikzpicture} +\end{document} + \ No newline at end of file diff --git a/tikz/figure8-11-b-directed-graphs.tex b/tikz/figure8-11-b-directed-graphs.tex new file mode 100644 index 0000000..286a599 --- /dev/null +++ b/tikz/figure8-11-b-directed-graphs.tex @@ -0,0 +1,43 @@ +\documentclass[border=10pt]{standalone} +\usepackage{tikz} +\usepackage{medl_colors} +\usetikzlibrary{graphdrawing,graphdrawing.trees,graphs, graphs.standard, backgrounds, calc, arrows.meta, bending, matrix} +\usegdlibrary{layered} + +\begin{document} + \begin{tikzpicture} + \path (0, -1.6) graph [layered layout, nodes={blueshape, circle, minimum size=1cm, thick,empty nodes}, level sep=6mm, sibling sep=15mm, edges={>={Triangle[round,sep,bend]}, thickline}] + { + 1[label = center:$v_1$]; + 2[label = center:$v_2$]; + 3[label = center:$v_3$]; + 4[label = center:$v_4$]; + 5[label = center:$v_5$]; + 6[label = center:$v_6$]; + 7[label = center:$v_7$]; + 8[label = center:$v_8$]; + 1 -> 3 -> 2 -> 5; + 3 ->[bend left] 4 ->[bend left] 3; + 5 ->[bend left] 7 ->[bend left] 5; + 5 ->[bend left] 6 ->[bend left] 8 ->[bend left] 6 ->[bend right] 3; + + }; + {\Large + \matrix (m) [matrix of math nodes, nodes in empty cells, left delimiter=[,right delimiter={]}, row sep=0.3cm, column sep=0.3cm, minimum width=0.4cm, minimum height=0.4cm, scale=0.7] at (10, -6.0) { + 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ + 0 & 1 & 0 & 1 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0 \\ + 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 \\ + 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ + 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ + }; + } + % Labels for the matrix + \foreach \i in {1,...,8} + \node[anchor=east, xshift=-0.5cm] at (m-\i-1.west) {\i}; + \foreach \j in {1,...,8} + \node[anchor=north, yshift=0.7cm] at (m-1-\j.north) {\j}; + \end{tikzpicture} +\end{document} diff --git a/tikz/figure8-12-a-big-graph-for-transductive-learning.tex b/tikz/figure8-12-a-big-graph-for-transductive-learning.tex new file mode 100644 index 0000000..472b1f7 --- /dev/null +++ b/tikz/figure8-12-a-big-graph-for-transductive-learning.tex @@ -0,0 +1,45 @@ +\documentclass[border=0.2cm]{standalone} + +\usepackage{tikz} +\usepackage{medl_colors} +\usetikzlibrary{graphs,graphdrawing} +\usegdlibrary{force} + + +\begin{document} +\begin{tikzpicture} + % To add labeling and check, change the code in this way + % \graph[spring layout, nodes={circle, draw, inner sep=2pt} + \begin{scope}[shift={(-1,5)}] + \graph[spring layout, nodes={circle, draw=fill-grey, inner sep=1.5pt, empty nodes}, edges={line}] + { + a[blueshape,circle,thick] -- b -- c -- d -- e [blueshape,circle,thick] -- f -- a [blueshape,circle,thick]-- g -- h; + g -- i; + e [blueshape,circle,thick] -- a4; + e [blueshape,circle,thick] -- b4; + b -- 1 -- 2 -- 3 -- b2; + 2 -- a2 [redshape,circle,thick] -- b2 -- c2 -- d2 -- e2 [yellowshape,circle,thick] -- f2 --a2 [redshape,circle,thick]; + 2 -- a3 -- b3 [greenshape,circle,thick] -- c3 -- d3 -- e3 -- f3 --a3; + b -- f2; + }; + \end{scope} + +\begin{scope}[shift={(-3,3)}] + \graph[spring layout, nodes={circle, draw=fill-grey, inner sep=1.5pt, empty nodes}, edges={line}] + { + 1a [greenshape,circle,thick] -- 1b -- 1c -- 1d -- 1e -- 1f -- 1a [greenshape,circle,thick] -- 1g -- 1h; + g2 [greenshape,circle,thick] -- i2 --a4; + e -- a4 -- 13; + e -- b4 -- 1b; + 1a [greenshape,circle,thick] -- 13; + b -- 1 -- 2 -- 13 -- b2; + 2 -- a2 [redshape,circle,thick] -- b2 -- 2c2 -- d2 -- e2 [yellowshape,circle,thick] -- f2 --a2 [redshape,circle,thick]; + 2 -- a3 -- b3 [greenshape,circle,thick] -- c3 -- d3 -- e3 -- f3 --a3; + b -- f2; + }; + \draw [line](13) -- (c2); + + \end{scope} + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure8-12-b-several-small-graphs-for-inductive-learning.tex b/tikz/figure8-12-b-several-small-graphs-for-inductive-learning.tex new file mode 100644 index 0000000..e69de29 diff --git a/tikz/figure8-14-a-message-passing-input-graph.tex b/tikz/figure8-14-a-message-passing-input-graph.tex new file mode 100644 index 0000000..040fd8f --- /dev/null +++ b/tikz/figure8-14-a-message-passing-input-graph.tex @@ -0,0 +1,29 @@ +\documentclass[border=0.2cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usepackage{medl_colors} + +\begin{document} +\begin{tikzpicture} + +\node [redshape,circle,minimum size=5mm] (node11) {$v_3$}; +\node [lightgreenshape,circle,above of=node11,node distance=3cm,xshift=1.5cm] (node12) {$v_1$}; +\node [greenshape,circle,right of=node11,node distance=1cm,yshift=0.8cm, xshift=1.5cm] (node13) {$v_2$}; +\node [yellowshape, circle, below of=node11,node distance=1cm,xshift=2cm] (node14) {$v_4$}; +\node [lightblueshape,circle,right of=node14,node distance=2cm,xshift=-0.2cm] (node15) {$v_5$}; +\node [lightgreyshape,circle,right of=node13,node distance=2cm, yshift=1cm] (node16) {$v_6$}; +\node [below of=node11,node distance=1cm](node17){Target Node}; + +\draw [thickline](node11) -- (node12) {}; +\draw [thickline](node11) -- (node13) {}; +\draw [thickline](node11) -- (node14) {}; +\draw [thickline](node12) -- (node13) {}; +\draw [thickline](node13) -- (node16) {}; +\draw [thickline](node15) -- (node14) {}; +%\draw[-Triangle] (node17) -- (node11) {}; + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure8-2-vae-encoder-decoder.tex b/tikz/figure8-2-vae-encoder-decoder.tex new file mode 100644 index 0000000..d07ca79 --- /dev/null +++ b/tikz/figure8-2-vae-encoder-decoder.tex @@ -0,0 +1,43 @@ +\documentclass[border=0.2cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usepackage{medl_colors} +\usepackage{amsmath} + +\newcommand\fillbg[9]{ + \node [#6, thick, rectangle,minimum height=#3cm, minimum width=#4cm](#7) at (#1,#2){}; + \node[anchor=#8,font=\small] at ([xshift=#9mm, yshift=-1mm]#7.#8) {{#7}}; +} + +\begin{document} +\begin{tikzpicture} + +\fillbg{4.5}{0.5}{3.6}{9.5}{0.2}{redlayer}{Training}{north west}{2}; +\fillbg{7}{0.8}{4}{7}{0.2}{bluelayer}{Production}{north east}{-2}; + +\node[align=center](start){{\large $x$}}; +\node[greenshape,trapezium, align=center, trapezium angle=80,minimum height=1.5cm,shape border rotate=270,right of = start, node distance = 1.5cm] (encoder) {{\large $q_\phi(z\, |\, x)$}}; +\node[right of =encoder,node distance=3cm](samplevar_dist){{\large $\,\, z^*$}}; +\node[redshape,trapezium,trapezium angle=80,minimum height=1.5cm,shape border rotate=90,right of = samplevar_dist, node distance = 3cm] (decoder) {{\large $p_\theta (x\, |\, z^*)$}}; +\node[right of =decoder,node distance=2.5cm](prediction){{\large $\,\, x^*$}}; + +\draw [-Triangle, thickline] (start) -- (encoder) {}; +\draw [-Triangle, thickline] (encoder) -- ($(samplevar_dist)+(-0.2,0)$) {}; +\draw [-Triangle, thickline] (samplevar_dist) -- (decoder) {}; +\draw [-Triangle, thickline] (decoder) -- ($(prediction)+(-0.2, 0)$) {}; + +\node[below of=start,node distance=2 cm, align=center,font=\small](text1){Data\\sample}; +\node[below of=encoder,node distance=0.9 cm, align=center](text2){Encoder}; +\node[below of=samplevar_dist,node distance=2 cm, align=center](text3){Latent \\variable}; +\node[below of=decoder,node distance=0.9 cm, align=center,font=\small](text4){Decoder}; +\node[below of=prediction,node distance=2 cm, align=center,font=\small](text5){Generated \\ data sample}; + +\draw [-, thickline, dashed] (text1) -- (start) {}; +\draw [-, thickline, dashed] (text3) -- (samplevar_dist) {}; +\draw [-, thickline, dashed] (text5) -- (prediction) {}; + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/figure8-4-markovian-vae-latent-steps.tex b/tikz/figure8-4-markovian-vae-latent-steps.tex new file mode 100644 index 0000000..ab36f7b --- /dev/null +++ b/tikz/figure8-4-markovian-vae-latent-steps.tex @@ -0,0 +1,70 @@ +\documentclass[border=0.2cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usetikzlibrary{decorations.markings, decorations.pathreplacing} +\usepackage{medl_colors} +\usepackage{ifthen} + +\graphicspath{ {./images/} } + +\newcommand{\fetchitem}[2]{ + \foreach \x [count=\k] in #1 { + \ifnum\k=#2 + \x + \fi + } +} +\newcommand{\recursiveRectangleZero}[6]{ + \node (rect) at (#1,#2) [draw,#4,rounded corners,minimum width=0.9cm,minimum height=3cm] (#61) {$\fetchitem{{#5}}{3}$}; + \foreach \i in {2,...,#3} { + \node (rect)[draw,#4,rounded corners,minimum width=0.9cm,minimum height=3cm,right of=#61,node distance={(\i-1)*3.1cm}] (#6\i) {$z_{\fetchitem{{#5}}{\i}}$}; + \pgfmathtruncatemacro{\prevIndex}{\i - 1}; + \draw [Triangle-, thickline] ($(#6\i.west)+(0,1)$) -- ($(#6\prevIndex.east)+(0,1)$) node[above,pos=0.5,font=\small]{$q_{\phi_{\fetchitem{{#5}}{\prevIndex}}}(z_{\fetchitem{{#5}}{\i}} | \fetchitem{{#5}}{3})$}; + \draw [Triangle-, thickline] ($(#6\prevIndex.east)+(0,-1)$) -- ($(#6\i.west)+(0,-1)$)node[below,pos=0.5,font=\small]{$p_{\theta_{\fetchitem{{#5}}{\i}}}(\fetchitem{{#5}}{3} | z_{\fetchitem{{#5}}{\i}})$}; + } +} +\newcommand{\recursiveRectangle}[6]{ + \node (rect) at (#1,#2) [draw,#4,rounded corners,minimum width=0.9cm,minimum height=3cm] (#61) {$z_{\fetchitem{{#5}}{1}}$}; + \foreach \i in {2,...,#3} { + \node (rect)[draw,#4,rounded corners,minimum width=0.9cm,minimum height=3cm,right of=#61,node distance={(\i-1)*3.1cm}] (#6\i) {$z_{\fetchitem{{#5}}{\i}}$}; + \pgfmathtruncatemacro{\prevIndex}{\i - 1}; + \draw [Triangle-, thickline] ($(#6\i.west)+(0,1)$) -- ($(#6\prevIndex.east)+(0,1)$) node[above,pos=0.5,font=\small]{$q_{\phi_{\fetchitem{{#5}}{\prevIndex}}}(z_{\fetchitem{{#5}}{\i}} | z_{\fetchitem{{#5}}{\prevIndex}})$}; + \draw [Triangle-, thickline] ($(#6\prevIndex.east)+(0,-1)$) -- ($(#6\i.west)+(0,-1)$)node[below,pos=0.5,font=\small]{$p_{\theta_{\fetchitem{{#5}}{\i}}}(z_{\fetchitem{{#5}}{\prevIndex}}| z_{\fetchitem{{#5}}{\i}})$}; + } +} + +\newcommand{\customArrow}[5]{ + \ifthenelse{\equal{#5}{right}}{% + \draw[dashed, uthickline] (#1,#2) -- (#3-1,#4); + \draw[-Triangle, thickline] (#3-0.9,#4) -- (#3,#4) {}; + }{ + \draw[dashed, uthickline] (#1,#2) -- (#3+1,#4); + \draw[-Triangle, thickline] (#3+0.9,#4) -- (#3,#4) {}; + } +} + +\begin{document} +\begin{tikzpicture} + +\recursiveRectangleZero{0}{0}{2}{blueshape}{0, 1, x}{id1}; +\recursiveRectangle {7.7}{0}{3}{blueshape}{{t-1},{t},{t+1}}{id2}(ring2); +\recursiveRectangle {18.5}{0}{2}{blueshape}{{\scriptscriptstyle T-1},{\scriptscriptstyle T}}{id3}; + +\customArrow{3.55}{1}{7.2}{1}{right}; +\customArrow{7.2}{-1}{3.55}{-1}{left}; +\customArrow{14.35}{1}{18.0}{1}{right}; +\customArrow{18.0}{-1}{14.35}{-1}{left}; + +\node[below right = 2cm and -1cm of id11, scale = .4] (pica) {\includegraphics {images/noisy_image_00.jpg}}; +\node[below left = 2cm and -1.9cm of id22, scale = .4] (picb) {\includegraphics {images/noisy_image_03.jpg}}; +\node[below right = 2cm and 0.3cm of id31, scale = .4] (picc) {\includegraphics {images/noisy_image_10.jpg}}; + +\draw [-Triangle, bthickline] ($(picb.north)+(-2.5,6)$) -- ($(picb.north)+ +(2.5,6)$) node[above, midway](de3){\large {Encoder}}; +\draw [Triangle-, bthickline] ($(picb.south)+(-2.5, 4)$) -- ($(picb.south)+ (2.5, 4)$) node[below, midway](de3){\large {Decoder}}; + +\end{tikzpicture} +\end{document} diff --git a/tikz/figure8-6-GAN-architecture.tex b/tikz/figure8-6-GAN-architecture.tex new file mode 100644 index 0000000..ea48f7d --- /dev/null +++ b/tikz/figure8-6-GAN-architecture.tex @@ -0,0 +1,37 @@ +\documentclass[border=0.2cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usepackage{medl_colors} +\usepackage{amsmath} + +\newcommand\fillbg[7]{ + \node [#6,rectangle,minimum height=#3cm,minimum width=#4cm](#7) at (#1,#2){}; + \node[anchor=north east,font=\Large] at ([xshift=-3mm, yshift=-3mm]#7.north east) {{#7}}; +} + +\begin{document} +\begin{tikzpicture} + +\fillbg{-4.5}{3}{5}{13}{0.2}{redlayer}{Production}; +\fillbg{-1}{1.5}{8.5}{21}{0.1}{bluelayer}{Training}; + +\node[greenshape,cylinder,minimum width=2cm,minimum height = 2cm, shape border rotate = 90, font=\Large,aspect=0.3] (node_z) at (0,2.5) {{\Huge $x^*$}}; +\node[yellowshape, cylinder, minimum width=2cm,minimum height = 2cm, shape border rotate = 90, below of=node_z, node distance=4cm, font=\Large,aspect=0.2] (node_x) []{{\LARGE $x \in {\cal D}$}}; +\node (rect) [blueshape,minimum width=3cm,minimum height=2cm, left of=node_z, node distance=5cm, font=\Large] (node_ftheta){{\huge $f_{\theta}^{\text{G}}(\cdot)$}}; +\node[blueshape,rectangle, trapezium angle=80, minimum height=1cm,minimum width=5cm,rotate=270, font=\Large] (node_fphi) at (4,0.5) {\rotatebox{90}{{\huge $f_{\phi}^{\text{D}}(\cdot)$}}}; +\node [align=center, right of=node_fphi, node distance=4cm, font=\Large] (predlabel) {\texttt{Fake}/\texttt{Real}}; + +\node[lightgreyshape,cylinder, minimum width=2cm,minimum height = 2cm, shape border rotate = 90, font=\Large,aspect=0.3] (node_D) at (-9,2.5) {{\Huge $z^*$}}; + +\draw [-Triangle, ultra thick] (node_fphi.north) -- (predlabel.west) node[midway,right] {}; +\draw [-Triangle, ultra thick] (node_z.east) -- (node_fphi.south|-node_z.east) node[midway,right] {}; +\draw [-Triangle, ultra thick] (node_x.east) -- (node_fphi.south|-node_x.east) node[midway,right] {}; +\draw [-Triangle, ultra thick] (node_ftheta.east) -- (node_z.west) node[midway,right] {}; +\draw [-Triangle, ultra thick] (node_D.east) -- (node_ftheta.west) {}; + +\end{tikzpicture} + +\end{document} \ No newline at end of file diff --git a/tikz/figure8-7-GAN-Generator-Distributions-Signal.tex b/tikz/figure8-7-GAN-Generator-Distributions-Signal.tex new file mode 100644 index 0000000..4ef6b6d --- /dev/null +++ b/tikz/figure8-7-GAN-Generator-Distributions-Signal.tex @@ -0,0 +1,64 @@ +\documentclass[border=1cm]{standalone} +\usepackage{pgfplots} +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric, shapes.misc} +%\pgfplotsset{compat=1.18} +\pgfmathdeclarefunction{gauss}{3}{% + \pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}% +} + +\begin{document} + +\begin{tikzpicture} + +\begin{axis}[ + axis line style = ultra thick, + clip=false, + samples=1000, + ymin=0, xmin=0, xmax=40, ymax=1, + hide y axis, + domain=-5:40, + xtick=\empty, + axis lines*=left, + enlargelimits=false, + width=20cm, + height=5cm] + +\addplot[black, ultra thick,restrict x to domain=5:15] {gauss(x, 10, .7)} + coordinate [pos=1] (g10) + coordinate [pos=0.5] (g11) + coordinate [pos=0.6] (g12); + +\addplot[black, ultra thick,restrict x to domain=25:35] {gauss(x, 30, .7)} + coordinate [pos=1] (g20) + coordinate [pos=0.5] (g21) + coordinate [pos=.6] (g22) + coordinate [pos=.7] (g23); + +\node at ([xshift=1cm]g12) {\large $p_{{\cal D}}(\cdot)$}; +\node at ([xshift=1cm]g22) {\large $p_{G}(\cdot)$}; + +\draw[black, thick] ([xshift=-120, yshift=11]g11) -- ([xshift=120, yshift=11]g11); +\draw[black, thick] ([xshift=120, yshift=11]g11) to[out=-5, in=180] (230,0); + +% Add "XX" label next to the red curve +\node at ([xshift=160, yshift=0]g11) {\large $f_{\phi^{(t)}}^D(\cdot)$}; + +\fill[fill=black] ([xshift=-100]g10) circle (3pt); +\fill[fill=black] ([xshift=-80]g10) circle (3pt); +\fill[fill=black] ([xshift=-70]g10) circle (3pt); +\fill[fill=black] ([xshift=-65]g10) circle (3pt); +\fill[fill=black] ([xshift=-50]g10) circle (3pt); + +\fill[fill=black] ([xshift=-100]g20) circle (3pt); +\fill[fill=black] ([xshift=-85]g20) circle (3pt); +\fill[fill=black] ([xshift=-80]g20) circle (3pt); +\fill[fill=black] ([xshift=-70]g20) circle (3pt); +\fill[fill=black] ([xshift=-65]g20) circle (3pt); +\fill[fill=black] ([xshift=-60]g20) circle (3pt); + +\end{axis} + +\end{tikzpicture} + +\end{document} diff --git a/tikz/figure8-8-DIFFERENT-LATEX-COMPILER-wgan-joint-distribution.tex b/tikz/figure8-8-DIFFERENT-LATEX-COMPILER-wgan-joint-distribution.tex new file mode 100644 index 0000000..be3e1b8 --- /dev/null +++ b/tikz/figure8-8-DIFFERENT-LATEX-COMPILER-wgan-joint-distribution.tex @@ -0,0 +1,75 @@ +\documentclass[border=1cm]{standalone} +\usepackage{pgfplots} +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric, shapes.misc, calc} +\usepackage{medl_colors} +\usetikzlibrary{intersections, patterns} +\pgfplotsset{compat=1.18} + + + +\begin{document} + +\pgfmathdeclarefunction{gauss}{3}{% + \pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}% +} + +\begin{tikzpicture} +\begin{axis}[ + name=axis, + axis line style={very thick}, + clip=false, + samples=1000, + ymin=0, xmin=0, xmax=40, ymax=1, + axis lines*=left, + xtick=\empty, ytick=\empty, + enlargelimits=false, + axis on top, + no markers, + every axis y label/.style={at=(current axis.above origin),anchor=south}, + every axis x label/.style={at=(current axis.right of origin),anchor=west}, + width=10cm, + height=10cm, + xlabel={$p_{{\cal D}}$}, + ylabel={$p_G$}, +] + +\addplot[border-red,thick, rotate=180, xshift=-100] {gauss(x, 0, 1.2)} coordinate [pos=0.5] (g1); +\addplot[border-green,thick, rotate=180, xshift=-200] {gauss(x, 0, 1.2)} coordinate [pos=0.5] (g2); +\addplot[border-red,thick, rotate=90, xshift=170, yshift=-30] {gauss(x, 0, 1.2)} coordinate [pos=0.5] (g3); +\addplot[border-green,thick, rotate=90, xshift=172, yshift=-30] {gauss(x, 0, 1.2)} coordinate [pos=0.5] (g4); + +\end{axis} + +\path[draw, thick, name path=splitline] (axis.south west) -- ($(axis.north east)+(-2, -2)$); + +\path[name path=r1line] (g1 |- g3) -- (g1); +\path[name path=r2line] (g1 |- g3) -- ++(100,0); +\path[name intersections={of=splitline and r1line, by=ra}]; +\path[name intersections={of=splitline and r2line, by=rb}]; + +\path[name path=g1line] (g2 |- g3) -- (g2); +\path[name path=g2line] (g2 |- g3) -- ++(100,0); +\path[name intersections={of=splitline and g1line, by=ga}]; +\path[name intersections={of=splitline and g2line, by=gb}]; + +\def\radius{1} +\pgfmathsetseed{4} +% % Draw the circle + \draw[border-red, thick, draw=none] (g1 |- g3) circle (\radius); + \foreach \i in {1,...,1000} { + \pgfmathsetmacro{\angle}{random(0,360)} + \pgfmathsetmacro{\r}{min(1.5\radius, -0.3*ln(random())*\radius)} + \draw[fill=border-red, draw=none] ($(g1 |- g3)+(\angle:\r)$) circle (1pt); + } + \foreach \i in {1,...,1000} { + \pgfmathsetmacro{\angle}{random(0,360)} + \pgfmathsetmacro{\r}{min(1.5\radius, -0.3*ln(random())*\radius)} + \draw[fill=border-green, draw=none] ($(g2 |- g3)+(\angle:\r)$) circle (1pt); + } + +\draw[-,thick] (g2 |- g3) -- (ga) node[pos=.7, left, border-green] {$W(p_{{\cal D}}, p_G)$}; +\draw[-,thick] (g1 |- g3) -- (ra) node[pos=.6, right, border-red] {$W(p_{{\cal D}}, p_G)$}; +\end{tikzpicture} + +\end{document} diff --git a/tikz/figure8-9-RL-agent-envior.tex b/tikz/figure8-9-RL-agent-envior.tex new file mode 100644 index 0000000..d0c823e --- /dev/null +++ b/tikz/figure8-9-RL-agent-envior.tex @@ -0,0 +1,30 @@ +\documentclass[border=0.2cm]{standalone} + +\usepackage{tikz} +\usetikzlibrary{shapes.geometric, shapes.misc} +\usetikzlibrary{cd, fit, calc} +\usetikzlibrary{positioning} +\usepackage{medl_colors} +\begin{document} +\begin{tikzpicture} + +\node[blueshape,trapezium, align=center, trapezium angle=80, minimum width=1cm, align=center, shape border rotate=270, node distance = 1.5cm] (node1) {\small Agent}; + +%\node (rect)[blueshape,rounded corners, minimum width=2cm,minimum height=1cm, align=center] (node1) {\small Agent}; + +\node (rect)[yellowshape,rounded corners,minimum width=1cm,minimum height=2cm, align=center,below of=node1,node distance = 3cm] (node2) {\small Environment}; +\node [below of=node1, xshift=3cm,node distance=1.5cm,minimum height=1cm](node3){}; +\node [right of=node3,align=center,node distance=0.75cm,text=red](textnode1){\small Action}; +\node [below of=node1, xshift=-3cm,node distance=1.5cm](node4){}; +\node [right of=node4,align=center, text=green3](textnode2){\small Reward}; +\node [left of=node4,align=center,node distance=1.4cm,text=green3](textnode3){\small Observation}; + +\draw [bthickline](node1.east) -| (node3.center){}; +\draw [-Triangle,bthickline](node3.center) |- (node2.east){}; +\draw [bthickline]($(node2.west)+(0,0.25)$) -| ($(node4.center)+(0.25,0)$){}; +\draw [bthickline]($(node2.west)+(0,-0.25)$) -| ($(node4.center)+(-0.25,0)$){}; +\draw [-Triangle,bthickline]($(node4.center)+(0.25,0)$) |- ($(node1.west)+(0,-0.2)$){}; +\draw [-Triangle,bthickline]($(node4.center)+(-0.25,0)$) |- ($(node1.west)+(0,0.2)$){}; + +\end{tikzpicture} +\end{document} \ No newline at end of file diff --git a/tikz/medl_colors.sty b/tikz/medl_colors.sty new file mode 100644 index 0000000..2da3aab --- /dev/null +++ b/tikz/medl_colors.sty @@ -0,0 +1,89 @@ +\RequirePackage{xcolor} +\usetikzlibrary{arrows.meta} + +\definecolor{green0}{RGB}{206, 222, 178} +\definecolor{green1}{RGB}{133, 194, 81} +\definecolor{green2}{RGB}{79, 175, 50} +\definecolor{green3}{RGB}{64, 136, 38} + +\definecolor{blue0}{RGB}{168, 212, 228} +\definecolor{blue1}{RGB}{49, 143, 187} +\definecolor{blue2}{rgb}{0.34, 0.63, 0.81} + +\definecolor{yellow1}{RGB}{251, 189, 9} +\definecolor{yellow2}{RGB}{252, 238, 216} + +\definecolor{pink0}{RGB}{214, 0, 239} +\definecolor{pink1}{RGB}{253, 243, 245} + +\definecolor{orange1}{RGB}{236, 91, 84} + +\definecolor{pinklight}{HTML}{ffb6c1} +\definecolor{redlight}{HTML}{FFCCCB} +\definecolor{greylight}{HTML}{d3d3d3} + +\definecolor{newgreen1}{HTML}{00cc00} +\definecolor{newgreen2}{HTML}{00b200} +\definecolor{newgreen3}{HTML}{009900} +\definecolor{newgreen4}{HTML}{007f00} + +\definecolor{fblue}{RGB}{82, 158, 181} +\definecolor{fgreen}{RGB}{154, 187, 109} +\definecolor{fred}{RGB}{203, 47, 73} +\definecolor{fyellow}{RGB}{245, 187, 86} +\definecolor{border-teal}{RGB}{0,128,128} +\definecolor{fill-teal}{RGB}{95,158,160} + +% Start + +\definecolor{border-red}{RGB}{198, 97, 111} +\definecolor{fill-red}{RGB}{211, 135, 147} +\definecolor{border-light-red}{RGB}{247, 206, 204} +\definecolor{fill-light-red}{RGB}{248, 216, 214} + +\definecolor{border-blue}{RGB}{102, 157, 179} +\definecolor{fill-blue}{RGB}{130, 175, 194} +\definecolor{border-light-blue}{RGB}{177, 211, 226} +\definecolor{fill-light-blue}{RGB}{192, 220, 231} + +\definecolor{border-green}{RGB}{160, 186, 118} +\definecolor{fill-green}{RGB}{179, 200, 144} +\definecolor{border-light-green}{RGB}{209, 222, 182} +\definecolor{fill-light-green}{RGB}{218, 229, 196} + +\definecolor{border-yellow}{RGB}{236, 190, 105} +\definecolor{fill-yellow}{RGB}{240, 203, 132} +\definecolor{border-light-yellow}{RGB}{250, 239, 219} +\definecolor{fill-light-yellow}{RGB}{251, 241, 226} + +\definecolor{border-grey}{RGB}{76, 76, 76} +\definecolor{fill-grey}{RGB}{128, 128, 128} +\definecolor{border-light-grey}{RGB}{178, 178, 178} +\definecolor{fill-light-grey}{RGB}{198, 198, 198} + +\tikzstyle{uthickline} = [draw=fill-grey, ultra thick] +\tikzstyle{thickline} = [draw=fill-grey, thick] +\tikzstyle{line} = [draw=fill-grey] + +\tikzstyle{ubthickline} = [draw=border-grey, ultra thick] +\tikzstyle{bthickline} = [draw=border-grey, thick] +\tikzstyle{bline} = [draw=border-grey] + +\tikzstyle{redshape} = [rectangle, draw=border-red, fill=fill-red, text = black, ultra thick, align=center] +\tikzstyle{blueshape} = [rectangle, draw=border-blue, fill=fill-blue, text = black, ultra thick, align=center] +\tikzstyle{greenshape} = [rectangle, draw=border-green, fill=fill-green, text = black, ultra thick, align=center] +\tikzstyle{yellowshape} = [rectangle, draw=border-yellow, fill=fill-yellow, text = black, ultra thick, align=center] +\tikzstyle{greyshape} = [rectangle, draw=border-grey, fill=fill-grey, text = black, ultra thick, align=center] + +\tikzstyle{tealshape} = [rectangle, draw=border-teal, fill=fill-teal, text = black, ultra thick, align=center] + +\tikzstyle{lightredshape} = [rectangle, draw=border-light-red, fill=fill-light-red, text = black, ultra thick, align=center] +\tikzstyle{lightblueshape} = [rectangle, draw=border-light-blue, fill=fill-light-blue, text = black, ultra thick, align=center] +\tikzstyle{lightgreenshape} = [rectangle, draw=border-light-green, fill=fill-light-green, text = black, ultra thick, align=center] +\tikzstyle{lightyellowshape} = [rectangle, draw=border-light-yellow, fill=fill-light-yellow, text = black, ultra thick, align=center] +\tikzstyle{lightgreyshape} = [rectangle, draw=border-light-grey, fill=fill-light-grey, text = black, ultra thick, align=center] + +\tikzstyle{redlayer} = [dashed,ultra thick, draw=border-red, rounded corners] +\tikzstyle{bluelayer} = [dashed,ultra thick, draw=border-blue, rounded corners] +\tikzstyle{greenlayer} = [dashed,ultra thick, draw=border-green, rounded corners] +\tikzstyle{greylayer} = [dashed,ultra thick, draw=fill-grey, rounded corners] \ No newline at end of file