tensor_methods

Tensor Methods for DS and SC
git clone git://popovic.xyz/tensor_methods.git
Log | Files | Refs

main.tex (9491B)


      1 \documentclass[a4paper]{article}
      2 
      3 
      4 \usepackage[T1]{fontenc}
      5 \usepackage[utf8]{inputenc}
      6 \usepackage{mathptmx}
      7 
      8 %\usepackage{ngerman}	% Sprachanpassung Deutsch
      9 
     10 \usepackage{graphicx}
     11 \usepackage{geometry}
     12 \geometry{a4paper, top=15mm}
     13 
     14 \usepackage{subcaption}
     15 \usepackage[shortlabels]{enumitem}
     16 \usepackage{amssymb}
     17 \usepackage{amsthm}
     18 \usepackage{mathtools}
     19 \usepackage{braket}
     20 \usepackage{bbm}
     21 \usepackage{graphicx}
     22 \usepackage{float}
     23 \usepackage{yhmath}
     24 \usepackage{tikz}
     25 \usepackage{algorithm}
     26 \usepackage{algpseudocode}
     27 \usetikzlibrary{patterns,decorations.pathmorphing,positioning}
     28 \usetikzlibrary{calc,decorations.markings}
     29 
     30 \newcommand{\eps}{\varepsilon}
     31 
     32 \usepackage[backend=biber, sorting=none]{biblatex}
     33 \addbibresource{uni.bib}
     34 
     35 \usepackage[framemethod=TikZ]{mdframed}
     36 
     37 \tikzstyle{titlered} =
     38     [draw=black, thick, fill=white,%
     39         text=black, rectangle,
     40         right, minimum height=.7cm]
     41 
     42 
     43 \usepackage[colorlinks=true,naturalnames=true,plainpages=false,pdfpagelabels=true]{hyperref}
     44 \usepackage[parfill]{parskip}
     45 \usepackage{lipsum}
     46 
     47 
     48 \usepackage{tcolorbox}
     49 \tcbuselibrary{skins,breakable}
     50 
     51 \pagestyle{myheadings}
     52 
     53 \markright{Popović\hfill Tensor Methods \hfill}
     54 
     55 
     56 \title{University of Vienna\\ Faculty of Mathematics\\
     57 \vspace{1cm}TENSOR METHODS FOR DATA SCIENCE AND SCIENTIFIC COMPUTING
     58 }
     59 \author{Milutin Popovic}
     60 
     61 \begin{document}
     62 \maketitle
     63 \tableofcontents
     64 \section{Assignment 5}
     65 \subsection{Truncated TT-MPS}
     66 Given an MPS-TT factorization $U_1, \dots ,U_d$ of $A \in
     67 \mathbb{R}^{n_1\times \cdots \times n_d}$, with ranks $p_1, \dots, p_{d-1}\
     68 \in \mathbb{N}$, we will produce a MPS-TT approximation of ranks not
     69 exceeding $r_1, \dots, r_{d-1}$ with factors $V_1, \dots, V_d$ of
     70 quasioptimal accuracy in the Forbenius norm.
     71 
     72 
     73 \begin{algorithm}[H]
     74   \caption{rank truncation MPS-TT}\label{alg: hosvd}
     75 \begin{algorithmic}
     76     \State $\tilde{U_1} \gets U_1$
     77     \For{$k = 1, \dots, d-1$}
     78         \State $\tilde{U}_k \gets \text{reshape}\left(\tilde{U}_k, (p_{k-1} \cdot n_k, r_k\right)$
     79 
     80         \State $\bar{U}_k \gets \hat{P}_k \hat{\Sigma}_k \hat{W}^*_k$
     81         \Comment{rank- $r_k$ T-SVD of $\tilde{U}_k$}
     82 
     83         \State $\hat{Q}_k \gets \text{reshape}\left(\hat{P}_k, (p_{k-1}, n_k,
     84         r_k) \right)$
     85 
     86         \State $\hat{Z}_k \gets \text{reshape}\left(\hat{\Sigma}_k \hat{W}^*_k,
     87             (r_{k}, 1, p_k) \right)$
     88 
     89         \State $(\tilde{U}_{k+1})_{\beta_k,i_{k+1},\alpha_{k+1}} \gets
     90         \sum_{\alpha_k = 1}^{r_k} (\hat{Z}_k)_{\beta_k, 1, \alpha_k}
     91             (U_{k+1})_{\alpha_k, i_{k+1}, \alpha_{k+1}}$
     92         \State $\text{save}(\hat{Q_k})$
     93     \EndFor
     94     \State $\text{save}\left(\tilde{U}_d\right)$
     95 \end{algorithmic}
     96 \end{algorithm}
     97 \subsection{TT-MPS arithmetic}
     98 \subsubsection{Addition}
     99 Consider two tensors $U$ and $V$ of size $n_1 \times \cdots \times n_d \ \in
    100 \mathbb{N}$ for $d \in \mathbb{N}$, with TT-MPS factorization $U_k$ with rank
    101 $p_k$ and $V_k$ with rank $q_k$ respectively (for $k \in \{1, \dots ,d-1\}$).
    102 Then TT-MPS factorization of $W = U + V$ can be calculated without
    103 evaluating $U$ or $V$, just by using $U_1, \dots, U_{d}$ and $V_1, \dots,
    104 V_d$ by the following
    105 \begin{align}
    106     W &= U_1 \bowtie \cdots \bowtie U_d + V_1 \bowtie \cdots \bowtie V_d
    107     =\nonumber\\
    108       &= \begin{bmatrix}U_1 & V_1\end{bmatrix} \bowtie
    109       \begin{bmatrix} U_2 \bowtie \cdots \bowtie U_d  \\  V_2 \bowtie \cdots
    110       \bowtie V_d  \end{bmatrix} =\nonumber\\
    111       &= \cdots =\nonumber\\
    112       &=\begin{bmatrix}U_1 & V_1\end{bmatrix} \bowtie \begin{bmatrix} U_2 &
    113     0\\ 0& V_2 \end{bmatrix} \bowtie \cdots \bowtie \begin{bmatrix} U_{d-1} &
    114     0\\ 0& V_{d-1} \end{bmatrix} \bowtie \begin{bmatrix} U_d \\ V_d
    115 \end{bmatrix} =\nonumber\\
    116         &= W_1 \bowtie \cdots \bowtie W_d,
    117 \end{align}
    118 where $W$ has a decomposition of ranks $(p_1 + q_1), \dots, (p_{d-1}
    119 q_{d-1})$. The construction of these matrices and vectors can be done by
    120 initializing the $W_k$ and then slicing for $U_k$ and $V_k$ in the second
    121 dimension, meaning $n_k$. Thereby for the $k$-th ($2\leq k \leq d-2$) step we would have
    122 \begin{align}
    123     (W_k)_{:, i_k, :} = \begin{bmatrix} (U_k)_{:, i_k, :} & 0 \\
    124                                         0 & (V_k)_{:, i_k, :}
    125                         \end{bmatrix} \;\;\;\; \forall i_k \in \{1, \dots,
    126                         n_k\}.
    127 \end{align}
    128 For the first step we have $p_0 = q_0 = 1$ and thereby
    129 \begin{align}
    130     (W_1)_{:, i_1, :} = \begin{bmatrix} (U_1)_{1, i_1,:} & (V_1)_{1, i_1, :}
    131     \end{bmatrix} \;\;\;\;\; \forall i_1 \in \{1, \dots, n_1 \}.
    132 \end{align}
    133 And for the $k=d$-th step we have $p_d = q_d = 1$ and thereby
    134 \begin{align}
    135     (W_d)_{:, i_d, :} = \begin{bmatrix} (U_d)_{:, i_d,1} \\ (V_d)_{:, i_d, 1}
    136     \end{bmatrix} \;\;\;\;\; \forall i_d \in \{1, \dots, n_d \}.
    137 \end{align}
    138 This concludes the construction of the algorithm for addition
    139 \subsubsection{Hadamard Product}
    140 Now consider again two tensors $U$ and $V$ of size $n_1 \times \cdots \times n_d \ \in
    141 \mathbb{N}$ for $d \in \mathbb{N}$, with TT-MPS factorization $U_k$ with rank
    142 $p_k$ and $V_k$ with rank $q_k$ respectively (for $k \in \{1, \dots ,d-1\}$).
    143 Then TT-MPS factorization of $W = U \otimes V$ can be calculated without
    144 evaluating $U$ or $V$, just by using $U_1, \dots, U_{d}$ and $V_1, \dots,
    145 V_d$ by the following
    146 \begin{align}
    147     W_{i_1, \dots, i_d} &= \sum_{\alpha_1 = 1}^{q_1} \cdots \sum_{\alpha_{d-1}
    148     = 1}^{q_{d-1}} \prod_{k=1}^d U_k(\alpha_{k-1}, i_k, \alpha_k) \cdot
    149     \sum_{\beta_1 = 1}^{q_1} \cdots \sum_{\beta_{d-1}
    150         = 1}^{q_{d-1}} \prod_{k=1}^d V_k(\beta_{k-1}, i_k, \beta_k)
    151         =\nonumber\\
    152         =&
    153     \sum_{\gamma_1 = 1}^{r_1} \cdots \sum_{\gamma_{d-1}
    154         = 1}^{r_{d-1}} \prod_{k=1}^d W_k(\gamma_{k-1}, i_k, \gamma_k).
    155 \end{align}
    156 Thereby the factors $W_k$ can be calculated with the factor wise product
    157 \begin{align}
    158     W_k(\alpha_{k-1}\beta{k-1}, i_k, \alpha_k\beta_k) = U_k(\alpha_{k-1},
    159     i_k, \alpha_k) \cdot V_k(\beta_{k-1}, i_k, \beta_k),
    160 \end{align}
    161 for all $\alpha_{k} \in \{1, \dots, p_{k}\}$ and $\beta_k \in \{1, \dots,
    162 q_k\}$ and $p_0 = p_d = q_0 = q_d = 1$. Where the TT-MPS calculated by the
    163 algorithm is of ranks $(p_1q_1), \dots, (p_{d-1} q_{d-1})$.
    164 
    165 The computer reads in slices and Kronecker products
    166 \begin{align}
    167     (W_k)_{:, i_k, :} = (U_k)_{:, i_k, :} \otimes (V_k)_{:, i_k, :}
    168     \;\;\;\;\;\; \forall i_k \in \{1, \dots, n_k\}.
    169 \end{align}
    170 \subsubsection{Matrix Vector product}
    171 Now consider $A\in \mathbb{R}^{n_1\cdots n_d \times m_1 \cdots m_d}$ and
    172 $u \in \mathbb{R}^{m_1 \cdots m_d}$. The TT-MPS factorization of $A$ is $A_k
    173 \in \mathbb{R}^{p_{k-1} \times n_k \times m_k \times q_k}$ and the TT-MPS
    174 factorization of $U$ is $U_k \in \mathbb{R}^{q_{k-1} \times m_k \times q_k}$.
    175 The TT-MPS factors $W_k$ of $w = A\cdots u$ can be explicitly calculated with
    176 \begin{align}
    177     W_{i_1,\dots, i_d} &= \sum_{j_1,\dots,j_d} A_{i_1\cdots i_d, j_1\cdots
    178         j_d} U_{j_1\cdots j_d}\nonumber \\
    179         &= \sum_{j_1, \dots, j_d}
    180         \sum_{\alpha_1=1}^{p_1} \cdots \sum_{\alpha_{d-1}=1}^{p_{d-1}}
    181         \prod_{k=1}^d A_k(\alpha_{k-1}, i_k, j_k, \alpha_k) \cdot
    182         \sum_{\beta_1=1}^{q_1} \cdots \sum_{\beta_{d-1}=1}^{q_{d-1}}
    183         \prod_{k=1}^d U_k(\beta_{k-1} j_k, \beta_k) \cdot \nonumber\\
    184         &= \sum_{\alpha_1\beta_1} \cdots \sum_{\alpha_{d-1}\beta_{d-1}}
    185         \prod_{k=1}^{d} \left(
    186         \sum_{j_k}^{n_k} A_k(\alpha_{k-1}, i_k, j_k, \alpha_k)
    187         U_K(\beta_{k-1}, j_k, \beta_k)
    188         \right) \nonumber \\
    189         &= \sum_{\gamma_1}^{r_1} \cdots \sum_{\gamma_{d-1}}^{r_{d-1}}
    190         \prod_{k=1}^{d} W_k(\gamma_{k-1}, i_k, \gamma_k),
    191 \end{align}
    192 for $r_k = q_k \cdot p_k$.
    193 The computer reads
    194 \begin{align}
    195     (W_k)_{:, i_k, :} = \sum_{j_k=1}^{n_k} (A_k)_{:, i_k, j_k, :} \otimes
    196     (U_k)_{:, j_k, :} \;\;\;\;\; \forall i_k \in \{1, \dots, n_k\}
    197 \end{align}
    198 for all $k = 1,\dots, d$
    199 \subsection{Testing}
    200 Consider the grid for $n=51$
    201 \begin{align}
    202     t_i = 2\frac{i-1}{n-1} - 1 \;\;\;\;\; i = 1, \dots ,n
    203 \end{align}
    204 for the tensors $X, Y \in \mathbb{R}^{n\times n\times n\times n}$ given by
    205 \begin{align}
    206     x_{i_1,\dots, i_4} &= T_p\left(\sum_{k=1}^4 \frac{t_{i_k}}{4}\right) \\
    207     y_{i_1,\dots, i_4} &= T_q\left(\sum_{k=1}^4 \frac{t_{i_k}}{4}\right) \\
    208 \end{align}
    209 for $p, q \in \mathbb{N}_0$ and $T_r$ is the Chebyshev polynomial for a $k
    210 \in \mathbb{N}_0$. The Chebyshev polynomials are defined by
    211 \begin{align}
    212     T_r(x) = \begin{cases}
    213         \cos(r\cdot\text{arccos}(x)) & \;\;\;\;\; |x| \leq 1\\
    214         \cosh(r\cdot\text{arccosh}(x))&\;\;\;\;\; x \geq 1\\
    215         (-1)^r\cosh(r\cdot\text{arccosh}(x))&\;\;\;\;\; x \leq -1
    216             \end{cases}.
    217 \end{align}
    218 Additionally we define
    219 \begin{align}
    220     S := X + Y\\
    221     Z := X \otimes Y.
    222 \end{align}
    223 The following figures show for $(p, q) = 3,4$ and $(p, q) = 5,7$ the TT-MPS
    224 unfolding singular values of tensors $X, Y, S, Z$.
    225 \begin{figure}[H]
    226     \centering
    227     \includegraphics[width=\textwidth]{./plots/sigma_34.png}
    228     \caption{Some text}
    229 \end{figure}
    230 
    231 \begin{figure}[H]
    232     \centering
    233     \includegraphics[width=\textwidth]{./plots/sigma_57.png}
    234     \caption{Some text}
    235 \end{figure}
    236 
    237 The following figures show the ranks MPS-TT unfolding matrices of $X, Y, S,
    238 Z$ for $(p, q) = 3,4$ and $(p, q) = 5,7$ respectively
    239 
    240 \begin{figure}[H]
    241     \centering
    242     \includegraphics[width=0.48\textwidth]{./plots/rank_34.png}
    243     \includegraphics[width=0.48\textwidth]{./plots/rank_57.png}
    244     \caption{Some text}
    245 \end{figure}
    246 \nocite{code}
    247 \printbibliography
    248 \end{document}