1. Mutable & Immutable In python, built-in types are classified as mutable and immutable.
immutable: tuple, string, number, bool
mutable: list, dict, set
example city_list = ['New York', 'London', 'Tokyo'] city_list.append('Paris') print(city_list) # ['New York', 'London', 'Tokyo', 'Paris'] tuple_a = (1, 2) tuple_a[0] = 3 # error, since tuple_a is immutable, we can't modify it tuple_b = ([], 0) tuple_b[0].append(1) # success, because the address of the first element didn't change print(tuple_b) # ([1], 0) Conlusion Mutable objects are often used in the situations where we want to do updates.
1. Basic Concepts Redis is a NoSql database. Its characteristics are non-structured, non-relational, no SQL grammar. Other NoSQL includes MongoDB, elaticsearch. Besides, Redis only has base transaction.
Redis stores key-value, runs in single thread with low latency. Data persistence is supported in case of blackout.
2. Install See Redis. For mac os, we can just run
brew install redis 3. Basic Commands brew services start redis # start redis redis-cli -h 127.
1. Install See minikube.
1. First Example Suppose that we are going to build a blog application. The following codes will create the index page.
# urls.py urlpatterns = [ path('', views.index, name='index'), ] # views.py def index(request): latest = Post.objects.order_by("-modified_time") return render(request, "index.html", {"post_list": latest}) If we use View class, the codes will be easier to read.
# urls.py urlpatterns = [ path('', views.IndexView.as_view(), name='index'), ] # views.py from django.views.generic import ListView class IndexView(ListView): queryset = Post.
1. dot a = torch.tensor(1, 2, 3) b = torch.tensor(1, -1, 1) torch.dot(a, b) # 2 # x1y1 + x2y2 + x3y3 ... 2. mul This is the element-wise multiplication (broadcast). Or we can use ‘*’.
a = torch.tensor(1, 2, 3) b = torch.tensor(1, -1, 1) torch.mul(a, b) # (1, -2, 3) a * b # (1, -2, 3) 3. mm & bmm This is the matrix-multiplication. Also, ‘bmm’ is used for batch data.
1. Introduction 1.1 KL for two Gaussian distribution $$ KL(p,q) = \log\frac{\sigma_1}{\sigma_2} + \frac{\sigma_1^2+(\mu_1-\mu_2)^2}{2\sigma_2^2} - \frac{1}{2} $$
1.2 Reparameterization If we want to sample from $N(\mu_1,\sigma_1)$, we can first sample $z$ from $N(0,1)$ and calculate $\sigma*z+\mu$ which will help us to get partial gradients.
1.3 Single layer of VAE The variational lower bound, or the evidence lower bound(ELBO), can be derived as follows.
$$ \begin{aligned} p(x) &= \int_z p_\theta(x|z)p(z) \\ &= \int_z q_\phi(z|x)\frac{p_\theta(x|z)p(z)}{q_\phi(z|x)} \\ \log p(x) &= \log E_{z\sim q_\phi{z|x}}[\frac{p_\theta(x|z)p(z)}{q_\phi(z|x)}] \\ &\ge E_{z\sim q_\phi{z|x}}[\log \frac{p_\theta(x|z)p(z)}{q_\phi(z|x)}] \end{aligned} $$
1. Flow-Based Generatvie Model Give a datapoint $x$ and latent varible $z\sim p_{\theta}(z)$. The function $g_{\theta}(..)$ is invertible such that
$$ \begin{aligned} x&=g_{\theta}(z) \\ z&=f_{\theta}(x) =g_{\theta}^{-1}(x) \end{aligned} $$
The probability density function of the model can be written as:
$$ \begin{aligned} \log p_{\theta}(x) &= \log p_{\theta}(z) + \log | det(dz/dx) | \\ &= \log p_{\theta}(z) + \sum_{i=1}^{K}\log | det(dh_i/dh_{i-1}) | \end{aligned} $$
To simplify the calculation, we can choose transformations with Jacobian $dh_{i}/dh_{i-1}$ is a triangular matrix,