tensor_methods

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

main.tex (10880B)


      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 4}
     65 \subsection{HOSVD Algorithm}
     66 The HOSVD algorithm is used to compute the Tucker approximation of a given tensor $A \in \mathbb{R}^{n_1
     67 \times \cdots \times n_d}$ with given ranks $r_1, \dots, r_d\ \in \mathbb{N}$ ($d
     68 \in \mathbb{N}$ and $n_1, \dots, n_d\ \in \mathbb{N}$. Additionally we would
     69 like to compute and save
     70 \begin{itemize}
     71     \item  the Forbenius norms of the error produced at each step of the
     72             algorithm $\frac{\| A - \hat{A}_k\|_F}{\|A\|_F}$ and the vectors of
     73     \item the vector of singular values directly approximated by the
     74         algorithm
     75 \end{itemize}
     76 The Tucker decomposition for $A$, with the ranks above is the following
     77 \begin{align}
     78     A_{i_1,\cdots,i_d} = \sum_{\alpha_1=1}^{r_1} \cdot
     79     \sum_{\alpha_d=1}^{r_d} (U_1)_{i_1,\alpha_1} \cdots (U_d)_{i_d,\alpha_d}
     80     S_{\alpha_1, \dots, \alpha_d},
     81 \end{align}
     82 where $U_k \in \mathbb{R}^{n_k \times r_k}$ for all $k \in \{1, \cdots, d\}$
     83 and $S \in \mathbb{R}^{r_1 \times \cdots \times r_d}$ is called the
     84 Tucker-core.
     85 
     86 The HOSVD algorithm with the additional requirements for the Tucker
     87 decomposition of $A$ is the following
     88 \begin{algorithm}[H]
     89   \caption{HOSVD algorithm}\label{alg: hosvd}
     90 \begin{algorithmic}
     91     \State $\hat{S}_0 \gets A$
     92     \State $A_0 \gets A$
     93     \For{$k = 1, \dots, d$}
     94         \State $(B_k)_{\alpha_1\cdots\alpha_{k-1}\cdot i_{k+1} \cdots
     95         i_d,i_k} \gets (\hat{S}_{k-1})_{\alpha_1, \dots, \alpha_{k-1}, i_k,
     96         \dots, i_d}$ \Comment{permute then reshape}
     97 
     98         \State $\hat{B}_k \gets \hat{U}_k \hat{\Sigma}_k \hat{V}_k^*$
     99         \Comment{rank $r_k$ T-SVD for $B_k$}
    100 
    101         \State $(\hat{S}_k)_{\alpha_{1}, \dots, \alpha_{k}, i_{k+1},\dots,i_d
    102         } \gets (B_k \hat{V}_k)_{\alpha_{1}, \dots, \alpha_{k-1}, i_{k+1}, \dots,
    103         i_d, \alpha_k}$ \Comment{reshape then permute}
    104 
    105         \State $(A_k)_{i_1,\cdots,i_d} \gets \sum_{\alpha_1=1}^{r_1} \cdot
    106         \sum_{\alpha_k=1}^{r_k} (\hat{V}_1)_{i_1,\alpha_1} \cdots (\hat{V}_k)_{i_d,\alpha_d}
    107         S_{\alpha_1, \dots, \alpha_{k}, i_{k+1}, \dots, i_d}$
    108 
    109         \State \text{save} $\frac{\| A - \hat{A}_k\|_F}{\|A\|_F}$
    110         \State \text{save} $\hat{V}_k$
    111         \State \text{save} $\hat{\Sigma}_k$
    112         \EndFor
    113 \end{algorithmic}
    114 \end{algorithm}
    115 We note that at the $k-th$ step of the algorithm the shapes of the tensors
    116 are
    117 \begin{align}
    118     \hat{S}_{k-1} &\in \mathbb{R}^{r_1 \times \cdots \times r_{k-1} \times n_k
    119     \times \cdots n_d} \\
    120         \hat{V}_k &\in \mathbb{R}^{n_k \times r_k},\\
    121         \hat{B}_k &\in \mathbb{R}^{r_1\cdots r_{k-1}\cdot n_{k+1} \cdots n_d,
    122         \times n_k},\\
    123         \hat{\Sigma}_k &\in \mathbb{R}^{r_k \times 1}.
    124 \end{align}
    125 \subsection{Testing the HOSVD}
    126 For the case $d=4$ we construct a quasirandom Tucker decomposition by drawing
    127 the entries for $U_k \in \mathbb{R}^{n_k \times r_k}$ and $S \in \mathbb{R}^{r_1
    128 \times \cdots \times r_d}$ uniformly on $[-1, 1]$. The output of the errors in
    129 the $k-th$ steps is in the figure bellow
    130 \begin{figure}[H]
    131     \centering
    132     \includegraphics[width=\textwidth]{"./plots/hosvd-uniform-error.png"}
    133     \caption{Tucker approximation error on the $k-th$ step of a quasirandom
    134     Tensor}
    135 \end{figure}
    136 \subsection{Tucker approximation of function-related tensors \label{sec:
    137 repeat}}
    138 Consider two multivariable functions $f(x_1, \dots, x_d)$ and $g(x_1, \dots,
    139 x_d)$, defined as
    140 \begin{align}
    141     f(x_1, \dots, x_d) &= \left(1+\sum_{k=1}^d \frac{x^2_k}{8^{k-1}}
    142         \right)^{-1}\\
    143     g(x_1, \dots, x_d) &= \sqrt{\sum_{k=1}^d \frac{x_k^2}{8^{k-1}}} \cdot
    144     \left(1+\frac{1}{2}\cos\left(\sum_{k=1}^d \frac{4\pi x_k}{4^{k-1}}\right) \right)
    145 \end{align}
    146 for $x_1, \dots, x_d \in [-1, 1]$. Additionally we define a grid of points
    147 \begin{align}
    148     t_i = 2 \frac{i-1}{n-1} -1 ,
    149 \end{align}
    150 for $i = 1, \dots, n$. With this we can construct a $d$ dimensional tensor of
    151 size $n \times \cdots \times n$ by
    152 \begin{align}
    153     b_{i_1, \cdots, i_d} = f(t_{i_1}, \dots, t_{i_d}),\\
    154     a_{i_1, \cdots, i_d} = g(t_{i_1}, \dots, t_{i_d}),
    155 \end{align}
    156 for all $i_1, \cdots, i_d \in \{1, \cdots, n\}$.
    157 
    158 For $C = A$ and $C =B$.
    159 For every $k \in \{1, \dots , d\}$, we compute the singular values of the $k-th$
    160 Tucker unfolding matrix of C.
    161 \begin{figure}[H]
    162     \centering
    163     \includegraphics[width=0.49\textwidth]{./plots/singular-dec-A.png}
    164     \includegraphics[width=0.49\textwidth]{./plots/singular-dec-B.png}
    165     \caption{Decrease of singular values of the $k-th$ Tucker unfolding of A,
    166     B produced by its SVD}
    167 \end{figure}
    168 
    169 For the accuracy Threshold $\eps_j = 10^{-j}$ with $j \in \{2, 4, \dots,
    170 12\}$, for each $j$ and every $k$ we find the smallest $r_{jk}$ such that the
    171 $k-th$ unfolding matrix can be approximated with ranks $r_{jk}$, where the
    172 approximations relative error does not exceed $\eps_j$. Additionally we
    173 compute the $\eps_{jk}$ error in the $k-th$ unfolding, which
    174 should by the error analysis be bounded by $\eps_{jk} \leq \eps_{j}$ for all
    175 $j$.
    176 \begin{figure}[H]
    177     \centering
    178     \includegraphics[width=0.49\textwidth]{./plots/hosvd-error-A.png}
    179     \includegraphics[width=0.49\textwidth]{./plots/hosvd-error-B.png}
    180     \caption{Dependence of the approximated ranks $r_{jk}$ on $j =
    181     \log_{10}\eps^{-j}$}
    182 \end{figure}
    183 
    184 For every $j$ we use our implementation of the HOSVD algorithm to compute the
    185 Tucker approximation of $C$ for the ranks $r_{jk}$ for $k = 1, \cdots ,d$ and
    186 the number of total entries $N_j$ produced by the output decomposition. In
    187 the code \cite{code} it is checked during run-time that the error produced by
    188 the HOSVD algorithm does not exceed $\|\eps_{jk}\|_F$ and agrees wit the
    189 error analysis.
    190 
    191 For $j = 12$ we plot the ratio of the singular values produced by the HOSVD
    192 algorithm and during the SVD approximation of the $k-th$ Tucker unfolding
    193 matrix
    194 \begin{figure}[H]
    195     \centering
    196     \includegraphics[width=0.49\textwidth]{./plots/hosvd-sigmaratio-a.png}
    197     \includegraphics[width=0.49\textwidth]{./plots/hosvd-sigmaratio-b.png}
    198     \caption{Ratio of Singular values produced by the HOSVD and the $k-th$
    199     Tucker unfolding approximation of $C$.}
    200 \end{figure}
    201 
    202 \begin{figure}[H]
    203     \centering
    204     \includegraphics[width=0.49\textwidth]{./plots/hosvd-Nj-a.png}
    205     \includegraphics[width=0.49\textwidth]{./plots/hosvd-Nj-b.png}
    206     \caption{Number of parameters $N_j$ produced by the HOSVD for $C$}
    207 \end{figure}
    208 
    209 
    210 \subsection{TT-SVD for MPS-TT}
    211 The TT-MPS (Tensor Train or Matrix Product States decomposition) for a given
    212 tensor $A \in \mathbb{R}^{n_1 \times \cdots \times n_d}$ with ranks $r_1,
    213 \dots, r_{d-1} \in \mathbb{N}$ is the following
    214 \begin{align}
    215     A_{i_1,\dots, i_d} =
    216     \sum_{\alpha_1=1}^{r_1}\cdots\sum_{\alpha_{d-1}=1}^{r_{d-1}}U_1(\alpha_0,i_1,
    217     \alpha_1) \cdots U_d(\alpha_{d-1}, i_d, \alpha_d)
    218 \end{align}
    219 for $\alpha_0 = \alpha_d = 1$, $i_k \in \{1, \dots, n_k\}$. The
    220 decomposition factors are given by
    221 \begin{align}
    222     V_k(i_k) &\in \mathbb{R}^{r_{k-1}\cdot n_k \times r_k}, \\
    223     (V_k(i_k))_{\alpha_{k-1}, \alpha_k} &= U_k (\alpha_{k-1}, i_k, \alpha_k),
    224 \end{align}
    225 where $i_k$ is called the mode index.
    226 
    227 The TT-SVD algorithm for $A$ as above is the following
    228 \begin{algorithm}[H]
    229   \caption{TT-SVD algorithm}\label{alg: ttsvd}
    230 \begin{algorithmic}
    231     \State $\hat{S}_0 \gets A$
    232     \State $A_0 \gets A$
    233     \State $r_0 \gets 1$
    234     \State $r_d \gets 1$
    235     \For{$k = 1, \dots, d-1$}
    236         \State $(B_k)_{\alpha_{k-1}\cdot i_k, i_{k+1} \cdots i_d} \gets
    237                 (\hat{S}_{k-1})_{\alpha_{k-1}, i_k, i_{k+1}, \dots, i_d}$
    238                 \Comment{reshape}
    239 
    240         \State $\hat{B}_k \gets \hat{U}_k \hat{\Sigma}_k \hat{V}_k^*$
    241         \Comment{rank $r_k$ T-SVD for $B_k$}
    242 
    243         \State $(\hat{C}_k)_{\alpha_{k-1},i_k,\alpha_k} \gets
    244         (\hat{U}_k)_{\alpha_{k-1}i_k, \alpha_k}$ \Comment{reshape}
    245 
    246         \State $(\hat{S}_k)_{\alpha_k, i_k, \dots, i_d} \gets
    247         (\hat{\Sigma}_k\hat{V}_k)_{\alpha_k, i_{k+1} \dots i_d}$
    248         \Comment{reshape}
    249 
    250         \State \text{save} $\frac{\| A - \hat{A}_k\|_F}{\|A\|_F}$
    251         \State \text{save} $\hat{C}_k$
    252         \State \text{save} $\hat{\Sigma}_k$
    253     \EndFor
    254 \end{algorithmic}
    255 \end{algorithm}
    256 \subsection{Testing the TT-SVD}
    257 For the case $d=4$ we construct a quasirandom Tucker decomposition by drawing
    258 the entries for $C_k \in \mathbb{R}^{r_{k-1} \cdot n_k \times r_k}$  uniformly
    259 on $[-1, 1]$. The output of the errors in the $k-th$ steps is in the figure
    260 bellow
    261 \begin{figure}[H]
    262     \centering
    263     \includegraphics[width=\textwidth]{"./plots/ttsvd-uniform-error.png"}
    264     \caption{TT-MPS error on the $k-th$ step of a quasirandom Tensor in the
    265     TT-SVD algorithm}
    266 \end{figure}
    267 \subsection{TT-MPS of function-related tensors}
    268 In this section we repeat everything we did in section \ref{sec: repeat},
    269 replacing the HOSVD algorithm for the Tucker approximation with the TT-SVD
    270 algorithm for the TT-MPS approximation
    271 
    272 \begin{figure}[H]
    273     \centering
    274     \includegraphics[width=0.49\textwidth]{./plots/ttsvd-sigmaratio-a.png}
    275     \includegraphics[width=0.49\textwidth]{./plots/ttsvd-sigmaratio-b.png}
    276     \caption{Ratio of Singular values produced by the TT-SVD and the $k-th$
    277     Tucker unfolding approximation of $C$.}
    278 \end{figure}
    279 
    280 \begin{figure}[H]
    281     \centering
    282     \includegraphics[width=0.49\textwidth]{./plots/ttsvd-Nj-a.png}
    283     \includegraphics[width=0.49\textwidth]{./plots/ttsvd-Nj-b.png}
    284     \caption{Number of parameters $N_j$ produced by the TT-SVD for $C$}
    285 \end{figure}
    286 
    287 
    288 \nocite{code}
    289 \printbibliography
    290 \end{document}