update
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
\relax
|
||||
\providecommand\zref@newlabel[2]{}
|
||||
\providecommand\hyper@newdestlabel[2]{}
|
||||
\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
|
||||
\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
|
||||
\global\let\oldcontentsline\contentsline
|
||||
\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}}
|
||||
\global\let\oldnewlabel\newlabel
|
||||
\gdef\newlabel#1#2{\newlabelxx{#1}#2}
|
||||
\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
|
||||
\AtEndDocument{\ifx\hyper@anchor\@undefined
|
||||
\let\contentsline\oldcontentsline
|
||||
\let\newlabel\oldnewlabel
|
||||
\fi}
|
||||
\fi}
|
||||
\global\let\hyper@last\relax
|
||||
\gdef\HyperFirstAtBeginDocument#1{#1}
|
||||
\providecommand\HyField@AuxAddToFields[1]{}
|
||||
\providecommand\HyField@AuxAddToCoFields[2]{}
|
||||
\citation{le1997reading}
|
||||
\citation{krizhevsky2012imagenet}
|
||||
\citation{zeiler2011adaptive,zeiler2014visualizing,long2015fully,radford2015unsupervised,visin15,im2016generating}
|
||||
\citation{bergstra2010theano,bastien2012theano}
|
||||
\citation{collobert2011torch7}
|
||||
\citation{abaditensorflow}
|
||||
\citation{jia2014caffe}
|
||||
\@writefile{toc}{\contentsline {chapter}{\numberline {1}Introduction}{5}{chapter.1}}
|
||||
\@writefile{lof}{\addvspace {10\p@ }}
|
||||
\@writefile{lot}{\addvspace {10\p@ }}
|
||||
\citation{Goodfellow-et-al-2016-Book}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {1.1}Discrete convolutions}{6}{section.1.1}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1.1}{\ignorespaces Computing the output values of a discrete convolution.\relax }}{7}{figure.caption.3}}
|
||||
\providecommand*\caption@xref[2]{\@setref\relax\@undefined{#1}}
|
||||
\newlabel{fig:numerical_no_padding_no_strides}{{1.1}{7}{Computing the output values of a discrete convolution.\relax }{figure.caption.3}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1.2}{\ignorespaces Computing the output values of a discrete convolution for $N = 2$, $i_1 = i_2 = 5$, $k_1 = k_2 = 3$, $s_1 = s_2 = 2$, and $p_1 = p_2 = 1$.\relax }}{7}{figure.caption.4}}
|
||||
\newlabel{fig:numerical_padding_strides}{{1.2}{7}{Computing the output values of a discrete convolution for $N = 2$, $i_1 = i_2 = 5$, $k_1 = k_2 = 3$, $s_1 = s_2 = 2$, and $p_1 = p_2 = 1$.\relax }{figure.caption.4}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1.3}{\ignorespaces A convolution mapping from two input feature maps to three output feature maps using a $3 \times 2 \times 3 \times 3$ collection of kernels $\mathbf {w}$. In the left pathway, input feature map 1 is convolved with kernel $\mathbf {w}_{1,1}$ and input feature map 2 is convolved with kernel $\mathbf {w}_{1,2}$, and the results are summed together elementwise to form the first output feature map. The same is repeated for the middle and right pathways to form the second and third feature maps, and all three output feature maps are grouped together to form the output.\relax }}{9}{figure.caption.5}}
|
||||
\newlabel{fig:full_picture}{{1.3}{9}{A convolution mapping from two input feature maps to three output feature maps using a $3 \times 2 \times 3 \times 3$ collection of kernels $\mathbf {w}$. In the left pathway, input feature map 1 is convolved with kernel $\mathbf {w}_{1,1}$ and input feature map 2 is convolved with kernel $\mathbf {w}_{1,2}$, and the results are summed together elementwise to form the first output feature map. The same is repeated for the middle and right pathways to form the second and third feature maps, and all three output feature maps are grouped together to form the output.\relax }{figure.caption.5}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1.4}{\ignorespaces An alternative way of viewing strides. Instead of translating the $3 \times 3$ kernel by increments of $s = 2$ (left), the kernel is translated by increments of $1$ and only one in $s = 2$ output elements is retained (right).\relax }}{9}{figure.caption.6}}
|
||||
\newlabel{fig:strides_subsampling}{{1.4}{9}{An alternative way of viewing strides. Instead of translating the $3 \times 3$ kernel by increments of $s = 2$ (left), the kernel is translated by increments of $1$ and only one in $s = 2$ output elements is retained (right).\relax }{figure.caption.6}{}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {1.2}Pooling}{10}{section.1.2}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1.5}{\ignorespaces Computing the output values of a $3 \times 3$ average pooling operation on a $5 \times 5$ input using $1 \times 1$ strides.\relax }}{11}{figure.caption.7}}
|
||||
\newlabel{fig:numerical_average_pooling}{{1.5}{11}{Computing the output values of a $3 \times 3$ average pooling operation on a $5 \times 5$ input using $1 \times 1$ strides.\relax }{figure.caption.7}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {1.6}{\ignorespaces Computing the output values of a $3 \times 3$ max pooling operation on a $5 \times 5$ input using $1 \times 1$ strides.\relax }}{11}{figure.caption.8}}
|
||||
\newlabel{fig:numerical_max_pooling}{{1.6}{11}{Computing the output values of a $3 \times 3$ max pooling operation on a $5 \times 5$ input using $1 \times 1$ strides.\relax }{figure.caption.8}{}}
|
||||
\@writefile{toc}{\contentsline {chapter}{\numberline {2}Convolution arithmetic}{12}{chapter.2}}
|
||||
\@writefile{lof}{\addvspace {10\p@ }}
|
||||
\@writefile{lot}{\addvspace {10\p@ }}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {2.1}No zero padding, unit strides}{12}{section.2.1}}
|
||||
\newlabel{rel:no_padding_no_strides}{{1}{13}{}{relationship.1}{}}
|
||||
\pgfsyspdfmark {pgfid4}{9782558}{40989860}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {2.2}Zero padding, unit strides}{13}{section.2.2}}
|
||||
\newlabel{rel:arbitrary_padding_no_strides}{{2}{13}{}{relationship.2}{}}
|
||||
\pgfsyspdfmark {pgfid5}{9782558}{31382350}
|
||||
\@writefile{toc}{\contentsline {subsection}{\numberline {2.2.1}Half (same) padding}{13}{subsection.2.2.1}}
|
||||
\newlabel{rel:same_padding_no_strides}{{3}{13}{}{relationship.3}{}}
|
||||
\pgfsyspdfmark {pgfid6}{9782558}{18692419}
|
||||
\@writefile{toc}{\contentsline {subsection}{\numberline {2.2.2}Full padding}{13}{subsection.2.2.2}}
|
||||
\newlabel{rel:full_padding_no_strides}{{4}{13}{}{relationship.4}{}}
|
||||
\pgfsyspdfmark {pgfid7}{9782558}{7844659}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2.1}{\ignorespaces (No padding, unit strides) Convolving a $3 \times 3$ kernel over a $4 \times 4$ input using unit strides (i.e., $i = 4$, $k = 3$, $s = 1$ and $p = 0$).\relax }}{14}{figure.caption.9}}
|
||||
\newlabel{fig:no_padding_no_strides}{{2.1}{14}{(No padding, unit strides) Convolving a $3 \times 3$ kernel over a $4 \times 4$ input using unit strides (i.e., $i = 4$, $k = 3$, $s = 1$ and $p = 0$).\relax }{figure.caption.9}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2.2}{\ignorespaces (Arbitrary padding, unit strides) Convolving a $4 \times 4$ kernel over a $5 \times 5$ input padded with a $2 \times 2$ border of zeros using unit strides (i.e., $i = 5$, $k = 4$, $s = 1$ and $p = 2$).\relax }}{14}{figure.caption.10}}
|
||||
\newlabel{fig:arbitrary_padding_no_strides}{{2.2}{14}{(Arbitrary padding, unit strides) Convolving a $4 \times 4$ kernel over a $5 \times 5$ input padded with a $2 \times 2$ border of zeros using unit strides (i.e., $i = 5$, $k = 4$, $s = 1$ and $p = 2$).\relax }{figure.caption.10}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2.3}{\ignorespaces (Half padding, unit strides) Convolving a $3 \times 3$ kernel over a $5 \times 5$ input using half padding and unit strides (i.e., $i = 5$, $k = 3$, $s = 1$ and $p = 1$).\relax }}{14}{figure.caption.11}}
|
||||
\newlabel{fig:same_padding_no_strides}{{2.3}{14}{(Half padding, unit strides) Convolving a $3 \times 3$ kernel over a $5 \times 5$ input using half padding and unit strides (i.e., $i = 5$, $k = 3$, $s = 1$ and $p = 1$).\relax }{figure.caption.11}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2.4}{\ignorespaces (Full padding, unit strides) Convolving a $3 \times 3$ kernel over a $5 \times 5$ input using full padding and unit strides (i.e., $i = 5$, $k = 3$, $s = 1$ and $p = 2$).\relax }}{14}{figure.caption.12}}
|
||||
\newlabel{fig:full_padding_no_strides}{{2.4}{14}{(Full padding, unit strides) Convolving a $3 \times 3$ kernel over a $5 \times 5$ input using full padding and unit strides (i.e., $i = 5$, $k = 3$, $s = 1$ and $p = 2$).\relax }{figure.caption.12}{}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {2.3}No zero padding, non-unit strides}{15}{section.2.3}}
|
||||
\newlabel{rel:no_padding_strides}{{5}{15}{}{relationship.5}{}}
|
||||
\pgfsyspdfmark {pgfid8}{9782558}{25170765}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {2.4}Zero padding, non-unit strides}{15}{section.2.4}}
|
||||
\newlabel{rel:padding_strides}{{6}{15}{}{relationship.6}{}}
|
||||
\pgfsyspdfmark {pgfid9}{9782558}{12981054}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2.5}{\ignorespaces (No zero padding, arbitrary strides) Convolving a $3 \times 3$ kernel over a $5 \times 5$ input using $2 \times 2$ strides (i.e., $i = 5$, $k = 3$, $s = 2$ and $p = 0$).\relax }}{17}{figure.caption.13}}
|
||||
\newlabel{fig:no_padding_strides}{{2.5}{17}{(No zero padding, arbitrary strides) Convolving a $3 \times 3$ kernel over a $5 \times 5$ input using $2 \times 2$ strides (i.e., $i = 5$, $k = 3$, $s = 2$ and $p = 0$).\relax }{figure.caption.13}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2.6}{\ignorespaces (Arbitrary padding and strides) Convolving a $3 \times 3$ kernel over a $5 \times 5$ input padded with a $1 \times 1$ border of zeros using $2 \times 2$ strides (i.e., $i = 5$, $k = 3$, $s = 2$ and $p = 1$).\relax }}{17}{figure.caption.14}}
|
||||
\newlabel{fig:padding_strides}{{2.6}{17}{(Arbitrary padding and strides) Convolving a $3 \times 3$ kernel over a $5 \times 5$ input padded with a $1 \times 1$ border of zeros using $2 \times 2$ strides (i.e., $i = 5$, $k = 3$, $s = 2$ and $p = 1$).\relax }{figure.caption.14}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2.7}{\ignorespaces (Arbitrary padding and strides) Convolving a $3 \times 3$ kernel over a $6 \times 6$ input padded with a $1 \times 1$ border of zeros using $2 \times 2$ strides (i.e., $i = 6$, $k = 3$, $s = 2$ and $p = 1$). In this case, the bottom row and right column of the zero padded input are not covered by the kernel.\relax }}{17}{figure.caption.15}}
|
||||
\newlabel{fig:padding_strides_odd}{{2.7}{17}{(Arbitrary padding and strides) Convolving a $3 \times 3$ kernel over a $6 \times 6$ input padded with a $1 \times 1$ border of zeros using $2 \times 2$ strides (i.e., $i = 6$, $k = 3$, $s = 2$ and $p = 1$). In this case, the bottom row and right column of the zero padded input are not covered by the kernel.\relax }{figure.caption.15}{}}
|
||||
\newlabel{fig:no_padding_no_strides_explained}{{2.8a}{17}{The kernel has to slide two steps to the right to touch the right side of the input (and equivalently downwards). Adding one to account for the initial kernel position, the output size is $3 \times 3$.\relax }{figure.caption.16}{}}
|
||||
\newlabel{sub@fig:no_padding_no_strides_explained}{{a}{17}{The kernel has to slide two steps to the right to touch the right side of the input (and equivalently downwards). Adding one to account for the initial kernel position, the output size is $3 \times 3$.\relax }{figure.caption.16}{}}
|
||||
\newlabel{fig:no_padding_strides_explained}{{2.8b}{17}{The kernel has to slide one step of size two to the right to touch the right side of the input (and equivalently downwards). Adding one to account for the initial kernel position, the output size is $2 \times 2$.\relax }{figure.caption.16}{}}
|
||||
\newlabel{sub@fig:no_padding_strides_explained}{{b}{17}{The kernel has to slide one step of size two to the right to touch the right side of the input (and equivalently downwards). Adding one to account for the initial kernel position, the output size is $2 \times 2$.\relax }{figure.caption.16}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {2.8}{\ignorespaces Counting kernel positions.\relax }}{17}{figure.caption.16}}
|
||||
\citation{boureau-cvpr-10,boureau-icml-10,boureau-iccv-11,ICML2011Saxe_551}
|
||||
\@writefile{toc}{\contentsline {chapter}{\numberline {3}Pooling arithmetic}{18}{chapter.3}}
|
||||
\@writefile{lof}{\addvspace {10\p@ }}
|
||||
\@writefile{lot}{\addvspace {10\p@ }}
|
||||
\newlabel{rel:pooling}{{7}{18}{}{relationship.7}{}}
|
||||
\pgfsyspdfmark {pgfid12}{9782558}{18616645}
|
||||
\@writefile{toc}{\contentsline {chapter}{\numberline {4}Transposed convolution arithmetic}{19}{chapter.4}}
|
||||
\@writefile{lof}{\addvspace {10\p@ }}
|
||||
\@writefile{lot}{\addvspace {10\p@ }}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {4.1}Convolution as a matrix operation}{20}{section.4.1}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {4.2}Transposed convolution}{20}{section.4.2}}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {4.3}No zero padding, unit strides, transposed}{21}{section.4.3}}
|
||||
\newlabel{rel:no_padding_no_strides_transposed}{{8}{22}{}{relationship.8}{}}
|
||||
\pgfsyspdfmark {pgfid13}{9782558}{39416996}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {4.4}Zero padding, unit strides, transposed}{22}{section.4.4}}
|
||||
\newlabel{rel:arbitrary_padding_no_strides_transposed}{{9}{22}{}{relationship.9}{}}
|
||||
\pgfsyspdfmark {pgfid14}{9782558}{25985771}
|
||||
\@writefile{toc}{\contentsline {subsection}{\numberline {4.4.1}Half (same) padding, transposed}{22}{subsection.4.4.1}}
|
||||
\newlabel{rel:half_padding_no_strides_transposed}{{10}{22}{}{relationship.10}{}}
|
||||
\pgfsyspdfmark {pgfid15}{9782558}{13476983}
|
||||
\@writefile{toc}{\contentsline {subsection}{\numberline {4.4.2}Full padding, transposed}{22}{subsection.4.4.2}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {4.1}{\ignorespaces The transpose of convolving a $3 \times 3$ kernel over a $4 \times 4$ input using unit strides (i.e., $i = 4$, $k = 3$, $s = 1$ and $p = 0$). It is equivalent to convolving a $3 \times 3$ kernel over a $2 \times 2$ input padded with a $2 \times 2$ border of zeros using unit strides (i.e., $i' = 2$, $k' = k$, $s' = 1$ and $p' = 2$).\relax }}{23}{figure.caption.17}}
|
||||
\newlabel{fig:no_padding_no_strides_transposed}{{4.1}{23}{The transpose of convolving a $3 \times 3$ kernel over a $4 \times 4$ input using unit strides (i.e., $i = 4$, $k = 3$, $s = 1$ and $p = 0$). It is equivalent to convolving a $3 \times 3$ kernel over a $2 \times 2$ input padded with a $2 \times 2$ border of zeros using unit strides (i.e., $i' = 2$, $k' = k$, $s' = 1$ and $p' = 2$).\relax }{figure.caption.17}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {4.2}{\ignorespaces The transpose of convolving a $4 \times 4$ kernel over a $5 \times 5$ input padded with a $2 \times 2$ border of zeros using unit strides (i.e., $i = 5$, $k = 4$, $s = 1$ and $p = 2$). It is equivalent to convolving a $4 \times 4$ kernel over a $6 \times 6$ input padded with a $1 \times 1$ border of zeros using unit strides (i.e., $i' = 6$, $k' = k$, $s' = 1$ and $p' = 1$).\relax }}{23}{figure.caption.18}}
|
||||
\newlabel{fig:arbitrary_padding_no_strides_transposed}{{4.2}{23}{The transpose of convolving a $4 \times 4$ kernel over a $5 \times 5$ input padded with a $2 \times 2$ border of zeros using unit strides (i.e., $i = 5$, $k = 4$, $s = 1$ and $p = 2$). It is equivalent to convolving a $4 \times 4$ kernel over a $6 \times 6$ input padded with a $1 \times 1$ border of zeros using unit strides (i.e., $i' = 6$, $k' = k$, $s' = 1$ and $p' = 1$).\relax }{figure.caption.18}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {4.3}{\ignorespaces The transpose of convolving a $3 \times 3$ kernel over a $5 \times 5$ input using half padding and unit strides (i.e., $i = 5$, $k = 3$, $s = 1$ and $p = 1$). It is equivalent to convolving a $3 \times 3$ kernel over a $5 \times 5$ input using half padding and unit strides (i.e., $i' = 5$, $k' = k$, $s' = 1$ and $p' = 1$).\relax }}{23}{figure.caption.19}}
|
||||
\newlabel{fig:same_padding_no_strides_transposed}{{4.3}{23}{The transpose of convolving a $3 \times 3$ kernel over a $5 \times 5$ input using half padding and unit strides (i.e., $i = 5$, $k = 3$, $s = 1$ and $p = 1$). It is equivalent to convolving a $3 \times 3$ kernel over a $5 \times 5$ input using half padding and unit strides (i.e., $i' = 5$, $k' = k$, $s' = 1$ and $p' = 1$).\relax }{figure.caption.19}{}}
|
||||
\newlabel{rel:full_padding_no_strides_transposed}{{11}{24}{}{relationship.11}{}}
|
||||
\pgfsyspdfmark {pgfid16}{9782558}{38404829}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {4.5}No zero padding, non-unit strides, transposed}{24}{section.4.5}}
|
||||
\newlabel{rel:no_padding_strides_transposed}{{12}{24}{}{relationship.12}{}}
|
||||
\pgfsyspdfmark {pgfid17}{9782558}{17976964}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {4.6}Zero padding, non-unit strides, transposed}{24}{section.4.6}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {4.4}{\ignorespaces The transpose of convolving a $3 \times 3$ kernel over a $5 \times 5$ input using full padding and unit strides (i.e., $i = 5$, $k = 3$, $s = 1$ and $p = 2$). It is equivalent to convolving a $3 \times 3$ kernel over a $7 \times 7$ input using unit strides (i.e., $i' = 7$, $k' = k$, $s' = 1$ and $p' = 0$).\relax }}{25}{figure.caption.20}}
|
||||
\newlabel{fig:full_padding_no_strides_transposed}{{4.4}{25}{The transpose of convolving a $3 \times 3$ kernel over a $5 \times 5$ input using full padding and unit strides (i.e., $i = 5$, $k = 3$, $s = 1$ and $p = 2$). It is equivalent to convolving a $3 \times 3$ kernel over a $7 \times 7$ input using unit strides (i.e., $i' = 7$, $k' = k$, $s' = 1$ and $p' = 0$).\relax }{figure.caption.20}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {4.5}{\ignorespaces The transpose of convolving a $3 \times 3$ kernel over a $5 \times 5$ input using $2 \times 2$ strides (i.e., $i = 5$, $k = 3$, $s = 2$ and $p = 0$). It is equivalent to convolving a $3 \times 3$ kernel over a $2 \times 2$ input (with $1$ zero inserted between inputs) padded with a $2 \times 2$ border of zeros using unit strides (i.e., $i' = 2$, $\mathaccentV {tilde}07E{i}' = 3$, $k' = k$, $s' = 1$ and $p' = 2$).\relax }}{25}{figure.caption.21}}
|
||||
\newlabel{fig:no_padding_strides_transposed}{{4.5}{25}{The transpose of convolving a $3 \times 3$ kernel over a $5 \times 5$ input using $2 \times 2$ strides (i.e., $i = 5$, $k = 3$, $s = 2$ and $p = 0$). It is equivalent to convolving a $3 \times 3$ kernel over a $2 \times 2$ input (with $1$ zero inserted between inputs) padded with a $2 \times 2$ border of zeros using unit strides (i.e., $i' = 2$, $\tilde {i}' = 3$, $k' = k$, $s' = 1$ and $p' = 2$).\relax }{figure.caption.21}{}}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {4.6}{\ignorespaces The transpose of convolving a $3 \times 3$ kernel over a $5 \times 5$ input padded with a $1 \times 1$ border of zeros using $2 \times 2$ strides (i.e., $i = 5$, $k = 3$, $s = 2$ and $p = 1$). It is equivalent to convolving a $3 \times 3$ kernel over a $3 \times 3$ input (with $1$ zero inserted between inputs) padded with a $1 \times 1$ border of zeros using unit strides (i.e., $i' = 3$, $\mathaccentV {tilde}07E{i}' = 5$, $k' = k$, $s' = 1$ and $p' = 1$).\relax }}{25}{figure.caption.22}}
|
||||
\newlabel{fig:padding_strides_transposed}{{4.6}{25}{The transpose of convolving a $3 \times 3$ kernel over a $5 \times 5$ input padded with a $1 \times 1$ border of zeros using $2 \times 2$ strides (i.e., $i = 5$, $k = 3$, $s = 2$ and $p = 1$). It is equivalent to convolving a $3 \times 3$ kernel over a $3 \times 3$ input (with $1$ zero inserted between inputs) padded with a $1 \times 1$ border of zeros using unit strides (i.e., $i' = 3$, $\tilde {i}' = 5$, $k' = k$, $s' = 1$ and $p' = 1$).\relax }{figure.caption.22}{}}
|
||||
\newlabel{rel:padding_strides_transposed}{{13}{26}{}{relationship.13}{}}
|
||||
\pgfsyspdfmark {pgfid18}{9782558}{37677014}
|
||||
\newlabel{rel:padding_strides_transposed_odd}{{14}{26}{}{relationship.14}{}}
|
||||
\pgfsyspdfmark {pgfid19}{9782558}{26483833}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {4.7}{\ignorespaces The transpose of convolving a $3 \times 3$ kernel over a $6 \times 6$ input padded with a $1 \times 1$ border of zeros using $2 \times 2$ strides (i.e., $i = 6$, $k = 3$, $s = 2$ and $p = 1$). It is equivalent to convolving a $3 \times 3$ kernel over a $2 \times 2$ input (with $1$ zero inserted between inputs) padded with a $1 \times 1$ border of zeros (with an additional border of size $1$ added to the bottom and right edges) using unit strides (i.e., $i' = 3$, $\mathaccentV {tilde}07E{i}' = 5$, $a = 1$, $k' = k$, $s' = 1$ and $p' = 1$).\relax }}{27}{figure.caption.23}}
|
||||
\newlabel{fig:padding_strides_odd_transposed}{{4.7}{27}{The transpose of convolving a $3 \times 3$ kernel over a $6 \times 6$ input padded with a $1 \times 1$ border of zeros using $2 \times 2$ strides (i.e., $i = 6$, $k = 3$, $s = 2$ and $p = 1$). It is equivalent to convolving a $3 \times 3$ kernel over a $2 \times 2$ input (with $1$ zero inserted between inputs) padded with a $1 \times 1$ border of zeros (with an additional border of size $1$ added to the bottom and right edges) using unit strides (i.e., $i' = 3$, $\tilde {i}' = 5$, $a = 1$, $k' = k$, $s' = 1$ and $p' = 1$).\relax }{figure.caption.23}{}}
|
||||
\citation{chen2014semantic,yu2015multi}
|
||||
\citation{oord2016wavenet}
|
||||
\bibdata{bibliography}
|
||||
\@writefile{toc}{\contentsline {chapter}{\numberline {5}Miscellaneous convolutions}{28}{chapter.5}}
|
||||
\@writefile{lof}{\addvspace {10\p@ }}
|
||||
\@writefile{lot}{\addvspace {10\p@ }}
|
||||
\@writefile{toc}{\contentsline {section}{\numberline {5.1}Dilated convolutions}{28}{section.5.1}}
|
||||
\newlabel{rel:dilation}{{15}{28}{}{relationship.15}{}}
|
||||
\pgfsyspdfmark {pgfid20}{9782558}{7844659}
|
||||
\@writefile{lof}{\contentsline {figure}{\numberline {5.1}{\ignorespaces (Dilated convolution) Convolving a $3 \times 3$ kernel over a $7 \times 7$ input with a dilation factor of 2 (i.e., $i = 7$, $k = 3$, $d = 2$, $s = 1$ and $p = 0$).\relax }}{29}{figure.caption.24}}
|
||||
\newlabel{fig:dilation}{{5.1}{29}{(Dilated convolution) Convolving a $3 \times 3$ kernel over a $7 \times 7$ input with a dilation factor of 2 (i.e., $i = 7$, $k = 3$, $d = 2$, $s = 1$ and $p = 0$).\relax }{figure.caption.24}{}}
|
||||
\bibcite{abaditensorflow}{{1}{2015}{{Abadi {\em et~al.}}}{{Abadi, Agarwal, Barham, Brevdo, Chen, Citro, Corrado, Davis, Dean, Devin, {\em et~al.}}}}
|
||||
\bibcite{bastien2012theano}{{2}{2012}{{Bastien {\em et~al.}}}{{Bastien, Lamblin, Pascanu, Bergstra, Goodfellow, Bergeron, Bouchard, Warde-Farley, and Bengio}}}
|
||||
\bibcite{bergstra2010theano}{{3}{2010}{{Bergstra {\em et~al.}}}{{Bergstra, Breuleux, Bastien, Lamblin, Pascanu, Desjardins, Turian, Warde-Farley, and Bengio}}}
|
||||
\bibcite{boureau-cvpr-10}{{4}{2010a}{{Boureau {\em et~al.}}}{{Boureau, Bach, LeCun, and Ponce}}}
|
||||
\bibcite{boureau-icml-10}{{5}{2010b}{{Boureau {\em et~al.}}}{{Boureau, Ponce, and LeCun}}}
|
||||
\bibcite{boureau-iccv-11}{{6}{2011}{{Boureau {\em et~al.}}}{{Boureau, {Le Roux}, Bach, Ponce, and LeCun}}}
|
||||
\bibcite{chen2014semantic}{{7}{2014}{{Chen {\em et~al.}}}{{Chen, Papandreou, Kokkinos, Murphy, and Yuille}}}
|
||||
\bibcite{collobert2011torch7}{{8}{2011}{{Collobert {\em et~al.}}}{{Collobert, Kavukcuoglu, and Farabet}}}
|
||||
\bibcite{Goodfellow-et-al-2016-Book}{{9}{2016}{{Goodfellow {\em et~al.}}}{{Goodfellow, Bengio, and Courville}}}
|
||||
\bibcite{im2016generating}{{10}{2016}{{Im {\em et~al.}}}{{Im, Kim, Jiang, and Memisevic}}}
|
||||
\bibcite{jia2014caffe}{{11}{2014}{{Jia {\em et~al.}}}{{Jia, Shelhamer, Donahue, Karayev, Long, Girshick, Guadarrama, and Darrell}}}
|
||||
\bibcite{krizhevsky2012imagenet}{{12}{2012}{{Krizhevsky {\em et~al.}}}{{Krizhevsky, Sutskever, and Hinton}}}
|
||||
\bibcite{le1997reading}{{13}{1997}{{Le~Cun {\em et~al.}}}{{Le~Cun, Bottou, and Bengio}}}
|
||||
\bibcite{long2015fully}{{14}{2015}{{Long {\em et~al.}}}{{Long, Shelhamer, and Darrell}}}
|
||||
\bibcite{oord2016wavenet}{{15}{2016}{{Oord {\em et~al.}}}{{Oord, Dieleman, Zen, Simonyan, Vinyals, Graves, Kalchbrenner, Senior, and Kavukcuoglu}}}
|
||||
\bibcite{radford2015unsupervised}{{16}{2015}{{Radford {\em et~al.}}}{{Radford, Metz, and Chintala}}}
|
||||
\bibcite{ICML2011Saxe_551}{{17}{2011}{{Saxe {\em et~al.}}}{{Saxe, Koh, Chen, Bhand, Suresh, and Ng}}}
|
||||
\bibcite{visin15}{{18}{2015}{{Visin {\em et~al.}}}{{Visin, Kastner, Courville, Bengio, Matteucci, and Cho}}}
|
||||
\bibcite{yu2015multi}{{19}{2015}{{Yu and Koltun}}{{Yu and Koltun}}}
|
||||
\bibcite{zeiler2014visualizing}{{20}{2014}{{Zeiler and Fergus}}{{Zeiler and Fergus}}}
|
||||
\bibcite{zeiler2011adaptive}{{21}{2011}{{Zeiler {\em et~al.}}}{{Zeiler, Taylor, and Fergus}}}
|
||||
\bibstyle{natbib}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
||||
\BOOKMARK [0][-]{chapter.1}{Introduction}{}% 1
|
||||
\BOOKMARK [1][-]{section.1.1}{Discrete convolutions}{chapter.1}% 2
|
||||
\BOOKMARK [1][-]{section.1.2}{Pooling}{chapter.1}% 3
|
||||
\BOOKMARK [0][-]{chapter.2}{Convolution arithmetic}{}% 4
|
||||
\BOOKMARK [1][-]{section.2.1}{No zero padding, unit strides}{chapter.2}% 5
|
||||
\BOOKMARK [1][-]{section.2.2}{Zero padding, unit strides}{chapter.2}% 6
|
||||
\BOOKMARK [2][-]{subsection.2.2.1}{Half \(same\) padding}{section.2.2}% 7
|
||||
\BOOKMARK [2][-]{subsection.2.2.2}{Full padding}{section.2.2}% 8
|
||||
\BOOKMARK [1][-]{section.2.3}{No zero padding, non-unit strides}{chapter.2}% 9
|
||||
\BOOKMARK [1][-]{section.2.4}{Zero padding, non-unit strides}{chapter.2}% 10
|
||||
\BOOKMARK [0][-]{chapter.3}{Pooling arithmetic}{}% 11
|
||||
\BOOKMARK [0][-]{chapter.4}{Transposed convolution arithmetic}{}% 12
|
||||
\BOOKMARK [1][-]{section.4.1}{Convolution as a matrix operation}{chapter.4}% 13
|
||||
\BOOKMARK [1][-]{section.4.2}{Transposed convolution}{chapter.4}% 14
|
||||
\BOOKMARK [1][-]{section.4.3}{No zero padding, unit strides, transposed}{chapter.4}% 15
|
||||
\BOOKMARK [1][-]{section.4.4}{Zero padding, unit strides, transposed}{chapter.4}% 16
|
||||
\BOOKMARK [2][-]{subsection.4.4.1}{Half \(same\) padding, transposed}{section.4.4}% 17
|
||||
\BOOKMARK [2][-]{subsection.4.4.2}{Full padding, transposed}{section.4.4}% 18
|
||||
\BOOKMARK [1][-]{section.4.5}{No zero padding, non-unit strides, transposed}{chapter.4}% 19
|
||||
\BOOKMARK [1][-]{section.4.6}{Zero padding, non-unit strides, transposed}{chapter.4}% 20
|
||||
\BOOKMARK [0][-]{chapter.5}{Miscellaneous convolutions}{}% 21
|
||||
\BOOKMARK [1][-]{section.5.1}{Dilated convolutions}{chapter.5}% 22
|
||||
@@ -0,0 +1,22 @@
|
||||
\contentsline {chapter}{\numberline {1}Introduction}{5}{chapter.1}
|
||||
\contentsline {section}{\numberline {1.1}Discrete convolutions}{6}{section.1.1}
|
||||
\contentsline {section}{\numberline {1.2}Pooling}{10}{section.1.2}
|
||||
\contentsline {chapter}{\numberline {2}Convolution arithmetic}{12}{chapter.2}
|
||||
\contentsline {section}{\numberline {2.1}No zero padding, unit strides}{12}{section.2.1}
|
||||
\contentsline {section}{\numberline {2.2}Zero padding, unit strides}{13}{section.2.2}
|
||||
\contentsline {subsection}{\numberline {2.2.1}Half (same) padding}{13}{subsection.2.2.1}
|
||||
\contentsline {subsection}{\numberline {2.2.2}Full padding}{13}{subsection.2.2.2}
|
||||
\contentsline {section}{\numberline {2.3}No zero padding, non-unit strides}{15}{section.2.3}
|
||||
\contentsline {section}{\numberline {2.4}Zero padding, non-unit strides}{15}{section.2.4}
|
||||
\contentsline {chapter}{\numberline {3}Pooling arithmetic}{18}{chapter.3}
|
||||
\contentsline {chapter}{\numberline {4}Transposed convolution arithmetic}{19}{chapter.4}
|
||||
\contentsline {section}{\numberline {4.1}Convolution as a matrix operation}{20}{section.4.1}
|
||||
\contentsline {section}{\numberline {4.2}Transposed convolution}{20}{section.4.2}
|
||||
\contentsline {section}{\numberline {4.3}No zero padding, unit strides, transposed}{21}{section.4.3}
|
||||
\contentsline {section}{\numberline {4.4}Zero padding, unit strides, transposed}{22}{section.4.4}
|
||||
\contentsline {subsection}{\numberline {4.4.1}Half (same) padding, transposed}{22}{subsection.4.4.1}
|
||||
\contentsline {subsection}{\numberline {4.4.2}Full padding, transposed}{22}{subsection.4.4.2}
|
||||
\contentsline {section}{\numberline {4.5}No zero padding, non-unit strides, transposed}{24}{section.4.5}
|
||||
\contentsline {section}{\numberline {4.6}Zero padding, non-unit strides, transposed}{24}{section.4.6}
|
||||
\contentsline {chapter}{\numberline {5}Miscellaneous convolutions}{28}{chapter.5}
|
||||
\contentsline {section}{\numberline {5.1}Dilated convolutions}{28}{section.5.1}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,721 @@
|
||||
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) (format=pdflatex 2017.9.13) 11 JAN 2018 11:57
|
||||
entering extended mode
|
||||
restricted \write18 enabled.
|
||||
%&-line parsing enabled.
|
||||
**\documentclass[class=minimal,border=10pt]{standalone}
|
||||
|
||||
*\usepackage[paperwidth=4in]{geometry}
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/standalone/standalone.cls
|
||||
Document Class: standalone 2012/09/15 v1.1b Class to compile TeX sub-files stan
|
||||
dalone
|
||||
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifluatex.sty
|
||||
Package: ifluatex 2010/03/01 v1.3 Provides the ifluatex switch (HO)
|
||||
Package ifluatex Info: LuaTeX not detected.
|
||||
)
|
||||
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifpdf.sty
|
||||
Package: ifpdf 2011/01/30 v2.3 Provides the ifpdf switch (HO)
|
||||
Package ifpdf Info: pdfTeX in PDF mode is detected.
|
||||
)
|
||||
(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty
|
||||
Package: ifxetex 2010/09/12 v0.6 Provides ifxetex conditional
|
||||
)
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/xkeyval/xkeyval.sty
|
||||
Package: xkeyval 2012/10/14 v2.6b package option processing (HA)
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkeyval.tex
|
||||
\XKV@toks=\toks14
|
||||
\XKV@tempa@toks=\toks15
|
||||
\XKV@depth=\count79
|
||||
File: xkeyval.tex 2012/10/14 v2.6b key=value parser (HA)
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/keyval.tex)))
|
||||
\sa@internal=\count80
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/standalone/standalone.cfg
|
||||
File: standalone.cfg 2012/09/15 v1.1b Default configuration file for 'standalon
|
||||
e' class
|
||||
)
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/base/minimal.cls
|
||||
Document Class: minimal 2001/05/25 Standard LaTeX minimal class
|
||||
)
|
||||
\sa@box=\box26
|
||||
)
|
||||
*\usepackage{tikz}
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/geometry/geometry.sty
|
||||
Package: geometry 2010/09/12 v5.6 Page Geometry
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifvtex.sty
|
||||
Package: ifvtex 2010/03/01 v1.5 Detect VTeX and its facilities (HO)
|
||||
Package ifvtex Info: VTeX not detected.
|
||||
)
|
||||
\Gm@cnth=\count81
|
||||
\Gm@cntv=\count82
|
||||
\c@Gm@tempcnt=\count83
|
||||
\Gm@bindingoffset=\dimen102
|
||||
\Gm@wd@mp=\dimen103
|
||||
\Gm@odd@mp=\dimen104
|
||||
\Gm@even@mp=\dimen105
|
||||
\Gm@layoutwidth=\dimen106
|
||||
\Gm@layoutheight=\dimen107
|
||||
\Gm@layouthoffset=\dimen108
|
||||
\Gm@layoutvoffset=\dimen109
|
||||
\Gm@dimlist=\toks16
|
||||
|
||||
|
||||
! Package geometry Error: \paperheight (0.0pt) too short.
|
||||
|
||||
See the geometry package documentation for explanation.
|
||||
Type H <return> for immediate help.
|
||||
...
|
||||
|
||||
l.995 \Gm@process
|
||||
|
||||
? \usepackage{xcolor}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \definecolor{blue}{RGB}{38,139,210}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \definecolor{cyan}{RGB}{42,161,152}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \definecolor{base01}{RGB}{88,110,117}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \definecolor{base02}{RGB}{7,54,66}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \definecolor{base03}{RGB}{0,43,54}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \usetikzlibrary{calc,shapes,positioning}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \begin{document}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \begin{tikzpicture}[scale=.5,every node/.style={minimum size=1cm},on grid]
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \begin{scope}[node/.append style={yslant=0.5,xslant=-0.7},
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? yslant=0.5,xslant=-0.7]
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[step=10mm, base03, dashed, thick] (0,0) grid (7,7);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (1,1) rectangle (2,2);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (1,2) rectangle (2,3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (1,3) rectangle (2,4);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (1,4) rectangle (2,5);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (1,5) rectangle (2,6);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (2,1) rectangle (3,2);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (2,2) rectangle (3,3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (2,3) rectangle (3,4);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (2,4) rectangle (3,5);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (2,5) rectangle (3,6);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (3,1) rectangle (4,2);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (3,2) rectangle (4,3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (3,3) rectangle (4,4);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (3,4) rectangle (4,5);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (3,5) rectangle (4,6);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (4,1) rectangle (5,2);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (4,2) rectangle (5,3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (4,3) rectangle (5,4);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (4,4) rectangle (5,5);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (4,5) rectangle (5,6);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (5,1) rectangle (6,2);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (5,2) rectangle (6,3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (5,3) rectangle (6,4);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (5,4) rectangle (6,5);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[draw=base03, fill=blue, thick] (5,5) rectangle (6,6);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something, E to edit your file,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
?
|
||||
)
|
||||
*
|
||||
(/usr/share/texmf/tex/latex/pgf/frontendlayer/tikz.sty
|
||||
(/usr/share/texmf/tex/latex/pgf/basiclayer/pgf.sty
|
||||
(/usr/share/texmf/tex/latex/pgf/utilities/pgfrcs.sty
|
||||
(/usr/share/texmf/tex/generic/pgf/utilities/pgfutil-common.tex
|
||||
\pgfutil@everybye=\toks17
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/utilities/pgfutil-latex.def
|
||||
\pgfutil@abb=\box27
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/ms/everyshi.sty
|
||||
Package: everyshi 2001/05/15 v3.00 EveryShipout Package (MS)
|
||||
))
|
||||
(/usr/share/texmf/tex/generic/pgf/utilities/pgfrcs.code.tex
|
||||
Package: pgfrcs 2010/10/25 v2.10 (rcs-revision 1.24)
|
||||
))
|
||||
Package: pgf 2008/01/15 v2.10 (rcs-revision 1.12)
|
||||
|
||||
(/usr/share/texmf/tex/latex/pgf/basiclayer/pgfcore.sty
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
|
||||
Package: graphicx 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
|
||||
Package: graphics 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty
|
||||
Package: trig 1999/03/16 v1.09 sin cos tan (DPC)
|
||||
)
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/graphics.cfg
|
||||
File: graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live
|
||||
)
|
||||
Package graphics Info: Driver file: pdftex.def on input line 91.
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/pdftex-def/pdftex.def
|
||||
File: pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/infwarerr.sty
|
||||
Package: infwarerr 2010/04/08 v1.3 Providing info/warning/error messages (HO)
|
||||
)
|
||||
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ltxcmds.sty
|
||||
Package: ltxcmds 2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
|
||||
)
|
||||
\Gread@gobject=\count84
|
||||
))
|
||||
\Gin@req@height=\dimen110
|
||||
\Gin@req@width=\dimen111
|
||||
)
|
||||
(/usr/share/texmf/tex/latex/pgf/systemlayer/pgfsys.sty
|
||||
(/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsys.code.tex
|
||||
Package: pgfsys 2010/06/30 v2.10 (rcs-revision 1.37)
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/utilities/pgfkeys.code.tex
|
||||
\pgfkeys@pathtoks=\toks18
|
||||
\pgfkeys@temptoks=\toks19
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/utilities/pgfkeysfiltered.code.tex
|
||||
\pgfkeys@tmptoks=\toks20
|
||||
))
|
||||
\pgf@x=\dimen112
|
||||
\pgf@y=\dimen113
|
||||
\pgf@xa=\dimen114
|
||||
\pgf@ya=\dimen115
|
||||
\pgf@xb=\dimen116
|
||||
\pgf@yb=\dimen117
|
||||
\pgf@xc=\dimen118
|
||||
\pgf@yc=\dimen119
|
||||
\w@pgf@writea=\write3
|
||||
\r@pgf@reada=\read1
|
||||
\c@pgf@counta=\count85
|
||||
\c@pgf@countb=\count86
|
||||
\c@pgf@countc=\count87
|
||||
\c@pgf@countd=\count88
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/systemlayer/pgf.cfg
|
||||
File: pgf.cfg 2008/05/14 (rcs-revision 1.7)
|
||||
)
|
||||
Package pgfsys Info: Driver file for pgf: pgfsys-pdftex.def on input line 900.
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsys-pdftex.def
|
||||
File: pgfsys-pdftex.def 2009/05/22 (rcs-revision 1.26)
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsys-common-pdf.def
|
||||
File: pgfsys-common-pdf.def 2008/05/19 (rcs-revision 1.10)
|
||||
)))
|
||||
(/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsyssoftpath.code.tex
|
||||
File: pgfsyssoftpath.code.tex 2008/07/18 (rcs-revision 1.7)
|
||||
\pgfsyssoftpath@smallbuffer@items=\count89
|
||||
\pgfsyssoftpath@bigbuffer@items=\count90
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/systemlayer/pgfsysprotocol.code.tex
|
||||
File: pgfsysprotocol.code.tex 2006/10/16 (rcs-revision 1.4)
|
||||
))
|
||||
(/usr/share/texmf/tex/latex/xcolor/xcolor.sty
|
||||
Package: xcolor 2007/01/21 v2.11 LaTeX color extensions (UK)
|
||||
|
||||
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/color.cfg
|
||||
File: color.cfg 2007/01/18 v1.5 color configuration of teTeX/TeXLive
|
||||
)
|
||||
Package xcolor Info: Driver file: pdftex.def on input line 225.
|
||||
Package xcolor Info: Model `cmy' substituted by `cmy0' on input line 1337.
|
||||
Package xcolor Info: Model `hsb' substituted by `rgb' on input line 1341.
|
||||
Package xcolor Info: Model `RGB' extended on input line 1353.
|
||||
Package xcolor Info: Model `HTML' substituted by `rgb' on input line 1355.
|
||||
Package xcolor Info: Model `Hsb' substituted by `hsb' on input line 1356.
|
||||
Package xcolor Info: Model `tHsb' substituted by `hsb' on input line 1357.
|
||||
Package xcolor Info: Model `HSB' substituted by `hsb' on input line 1358.
|
||||
Package xcolor Info: Model `Gray' substituted by `gray' on input line 1359.
|
||||
Package xcolor Info: Model `wave' substituted by `hsb' on input line 1360.
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcore.code.tex
|
||||
Package: pgfcore 2010/04/11 v2.10 (rcs-revision 1.7)
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmath.code.tex
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathcalc.code.tex
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathutil.code.tex)
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathparser.code.tex
|
||||
\pgfmath@dimen=\dimen120
|
||||
\pgfmath@count=\count91
|
||||
\pgfmath@box=\box28
|
||||
\pgfmath@toks=\toks21
|
||||
\pgfmath@stack@operand=\toks22
|
||||
\pgfmath@stack@operation=\toks23
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.code.tex
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex)
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code.tex)
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.random.code.tex)
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.comparison.code.tex)
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.base.code.tex)
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.round.code.tex)
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex)))
|
||||
(/usr/share/texmf/tex/generic/pgf/math/pgfmathfloat.code.tex
|
||||
\c@pgfmathroundto@lastzeros=\count92
|
||||
))
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepoints.code.tex
|
||||
File: pgfcorepoints.code.tex 2010/04/09 (rcs-revision 1.20)
|
||||
\pgf@picminx=\dimen121
|
||||
\pgf@picmaxx=\dimen122
|
||||
\pgf@picminy=\dimen123
|
||||
\pgf@picmaxy=\dimen124
|
||||
\pgf@pathminx=\dimen125
|
||||
\pgf@pathmaxx=\dimen126
|
||||
\pgf@pathminy=\dimen127
|
||||
\pgf@pathmaxy=\dimen128
|
||||
\pgf@xx=\dimen129
|
||||
\pgf@xy=\dimen130
|
||||
\pgf@yx=\dimen131
|
||||
\pgf@yy=\dimen132
|
||||
\pgf@zx=\dimen133
|
||||
\pgf@zy=\dimen134
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepathconstruct.code.tex
|
||||
File: pgfcorepathconstruct.code.tex 2010/08/03 (rcs-revision 1.24)
|
||||
\pgf@path@lastx=\dimen135
|
||||
\pgf@path@lasty=\dimen136
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepathusage.code.tex
|
||||
File: pgfcorepathusage.code.tex 2008/04/22 (rcs-revision 1.12)
|
||||
\pgf@shorten@end@additional=\dimen137
|
||||
\pgf@shorten@start@additional=\dimen138
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorescopes.code.tex
|
||||
File: pgfcorescopes.code.tex 2010/09/08 (rcs-revision 1.34)
|
||||
\pgfpic=\box29
|
||||
\pgf@hbox=\box30
|
||||
\pgf@layerbox@main=\box31
|
||||
\pgf@picture@serial@count=\count93
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoregraphicstate.code.tex
|
||||
File: pgfcoregraphicstate.code.tex 2008/04/22 (rcs-revision 1.9)
|
||||
\pgflinewidth=\dimen139
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoretransformations.code.tex
|
||||
File: pgfcoretransformations.code.tex 2009/06/10 (rcs-revision 1.11)
|
||||
\pgf@pt@x=\dimen140
|
||||
\pgf@pt@y=\dimen141
|
||||
\pgf@pt@temp=\dimen142
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorequick.code.tex
|
||||
File: pgfcorequick.code.tex 2008/10/09 (rcs-revision 1.3)
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoreobjects.code.tex
|
||||
File: pgfcoreobjects.code.tex 2006/10/11 (rcs-revision 1.2)
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepathprocessing.code.tex
|
||||
File: pgfcorepathprocessing.code.tex 2008/10/09 (rcs-revision 1.8)
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorearrows.code.tex
|
||||
File: pgfcorearrows.code.tex 2008/04/23 (rcs-revision 1.11)
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoreshade.code.tex
|
||||
File: pgfcoreshade.code.tex 2008/11/23 (rcs-revision 1.13)
|
||||
\pgf@max=\dimen143
|
||||
\pgf@sys@shading@range@num=\count94
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoreimage.code.tex
|
||||
File: pgfcoreimage.code.tex 2010/03/25 (rcs-revision 1.16)
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoreexternal.code.tex
|
||||
File: pgfcoreexternal.code.tex 2010/09/01 (rcs-revision 1.17)
|
||||
\pgfexternal@startupbox=\box32
|
||||
))
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorelayers.code.tex
|
||||
File: pgfcorelayers.code.tex 2010/08/27 (rcs-revision 1.2)
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcoretransparency.code.tex
|
||||
File: pgfcoretransparency.code.tex 2008/01/17 (rcs-revision 1.2)
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/basiclayer/pgfcorepatterns.code.tex
|
||||
File: pgfcorepatterns.code.tex 2009/07/02 (rcs-revision 1.3)
|
||||
)))
|
||||
(/usr/share/texmf/tex/generic/pgf/modules/pgfmoduleshapes.code.tex
|
||||
File: pgfmoduleshapes.code.tex 2010/09/09 (rcs-revision 1.13)
|
||||
\pgfnodeparttextbox=\box33
|
||||
)
|
||||
(/usr/share/texmf/tex/generic/pgf/modules/pgfmoduleplot.code.tex
|
||||
File: pgfmoduleplot.code.tex 2010/10/22 (rcs-revision 1.8)
|
||||
)
|
||||
(/usr/share/texmf/tex/latex/pgf/compatibility/pgfcomp-version-0-65.sty
|
||||
Package: pgfcomp-version-0-65 2007/07/03 v2.10 (rcs-revision 1.7)
|
||||
\pgf@nodesepstart=\dimen144
|
||||
\pgf@nodesepend=\dimen145
|
||||
)
|
||||
(/usr/share/texmf/tex/latex/pgf/compatibility/pgfcomp-version-1-18.sty
|
||||
Package: pgfcomp-version-1-18 2007/07/23 v2.10 (rcs-revision 1.1)
|
||||
))
|
||||
(/usr/share/texmf/tex/latex/pgf/utilities/pgffor.sty
|
||||
(/usr/share/texmf/tex/latex/pgf/utilities/pgfkeys.sty
|
||||
(/usr/share/texmf/tex/generic/pgf/utilities/pgfkeys.code.tex))
|
||||
(/usr/share/texmf/tex/generic/pgf/utilities/pgffor.code.tex
|
||||
Package: pgffor 2010/03/23 v2.10 (rcs-revision 1.18)
|
||||
\pgffor@iter=\dimen146
|
||||
\pgffor@skip=\dimen147
|
||||
\pgffor@stack=\toks24
|
||||
\pgffor@toks=\toks25
|
||||
))
|
||||
(/usr/share/texmf/tex/generic/pgf/frontendlayer/tikz/tikz.code.tex
|
||||
Package: tikz 2010/10/13 v2.10 (rcs-revision 1.76)
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/libraries/pgflibraryplothandlers.code.tex
|
||||
File: pgflibraryplothandlers.code.tex 2010/05/31 v2.10 (rcs-revision 1.15)
|
||||
\pgf@plot@mark@count=\count95
|
||||
\pgfplotmarksize=\dimen148
|
||||
)
|
||||
\tikz@lastx=\dimen149
|
||||
\tikz@lasty=\dimen150
|
||||
\tikz@lastxsaved=\dimen151
|
||||
\tikz@lastysaved=\dimen152
|
||||
\tikzleveldistance=\dimen153
|
||||
\tikzsiblingdistance=\dimen154
|
||||
\tikz@figbox=\box34
|
||||
\tikz@tempbox=\box35
|
||||
\tikztreelevel=\count96
|
||||
\tikznumberofchildren=\count97
|
||||
\tikznumberofcurrentchild=\count98
|
||||
\tikz@fig@count=\count99
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/modules/pgfmodulematrix.code.tex
|
||||
File: pgfmodulematrix.code.tex 2010/08/24 (rcs-revision 1.4)
|
||||
\pgfmatrixcurrentrow=\count100
|
||||
\pgfmatrixcurrentcolumn=\count101
|
||||
\pgf@matrix@numberofcolumns=\count102
|
||||
)
|
||||
\tikz@expandcount=\count103
|
||||
|
||||
(/usr/share/texmf/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarytopat
|
||||
hs.code.tex
|
||||
File: tikzlibrarytopaths.code.tex 2008/06/17 v2.10 (rcs-revision 1.2)
|
||||
)))
|
||||
(Please type a command or say `\end')
|
||||
* \foreach \x in { 4,\number\numexpr 4+1,...,\number\numexpr 7-1 } {
|
||||
|
||||
* \foreach \y in { 0,\number\numexpr 0+1,...,\number\numexpr 3-1 } {
|
||||
|
||||
|
||||
* \draw[fill=base02, opacity=0.4] (\x,\y) rectangle
|
||||
|
||||
* (\x+1,\y+1);
|
||||
|
||||
* }
|
||||
|
||||
* }
|
||||
! Undefined control sequence.
|
||||
\pgffor@body -> \draw
|
||||
[fill=base02, opacity=0.4] (\x ,\y ) rectangle (\x +1,...
|
||||
<*> }
|
||||
|
||||
? \draw[step=10mm, base03, thick] (4, 0) grid
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? (7, 3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \coordinate (BL) at (4,0);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \coordinate (BR) at (7,0);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \coordinate (TL) at (4,3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \coordinate (TR) at (7,3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \end{scope}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \begin{scope}[xshift=-5, yshift=8cm,
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? every node/.append style={yslant=0.5,xslant=-0.7},
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? yslant=0.5,xslant=-0.7]
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw (BL) -- (2,0) (BR) -- (3,0)
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? (TL) -- (2,1) (TR) -- (3,1);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[fill=cyan] (0,0) rectangle (3,3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[step=10mm, base03, thick] (0,0) grid (3,3);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[fill=base02, opacity=0.4] (2,0) rectangle
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? (3,1);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \draw[base03, thick] (2,0) rectangle (3,1);
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \end{scope}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \end{tikzpicture}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
? \end{document}
|
||||
Type <return> to proceed, S to scroll future error messages,
|
||||
R to run without stopping, Q to run quietly,
|
||||
I to insert something,
|
||||
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
|
||||
H for help, X to quit.
|
||||
?
|
||||
! Emergency stop.
|
||||
\pgffor@body -> \draw
|
||||
[fill=base02, opacity=0.4] (\x ,\y ) rectangle (\x +1,...
|
||||
<*> }
|
||||
|
||||
End of file on the terminal!
|
||||
|
||||
|
||||
Here is how much of TeX's memory you used:
|
||||
9773 strings out of 495028
|
||||
187135 string characters out of 6181497
|
||||
226517 words of memory out of 5000000
|
||||
12831 multiletter control sequences out of 15000+600000
|
||||
3640 words of font info for 14 fonts, out of 8000000 for 9000
|
||||
14 hyphenation exceptions out of 8191
|
||||
55i,0n,56p,385b,98s stack positions out of 5000i,500n,10000p,200000b,80000s
|
||||
! ==> Fatal error occurred, no output PDF file produced!
|
||||
@@ -0,0 +1,17 @@
|
||||
Translating doconce text in chapter1.do.txt to ipynb
|
||||
*** replacing \bm{...} by \boldsymbol{...} (\bm is not supported by MathJax)
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{cases} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
Failed to remove ans_at_end environment
|
||||
Failed to remove sol_at_end environment
|
||||
output in chapter1.ipynb
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
Translating doconce text in chapter2.do.txt to ipynb
|
||||
*** replacing \bm{...} by \boldsymbol{...} (\bm is not supported by MathJax)
|
||||
|
||||
*** warning: latex envir \begin{eqnarray*} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
Failed to remove ans_at_end environment
|
||||
Failed to remove sol_at_end environment
|
||||
output in chapter2.ipynb
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
*** error: file has a mako construction ${\bf X}'
|
||||
but seemingly no definition in <%...%>'
|
||||
(it is not a command-line given mako variable either).
|
||||
However, if this is a variable in a Makefile or Bash script
|
||||
run with --no_mako - and you cannot use mako and Makefile or Bash variables
|
||||
in the same document!
|
||||
|
||||
Translating doconce text in chapter3.do.txt to ipynb
|
||||
*** replacing \bm{...} by \boldsymbol{...} (\bm is not supported by MathJax)
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
|
||||
*** warning: latex envir \begin{bmatrix} does not work well in Markdown. Stick to \[ ... \], equation, equation*, align, or align* environments in math environments.
|
||||
Failed to remove ans_at_end environment
|
||||
Failed to remove sol_at_end environment
|
||||
output in chapter3.ipynb
|
||||
@@ -0,0 +1,848 @@
|
||||
======= Ridge and Lasso Regression =======
|
||||
|
||||
"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember10.mp4?vrtx=view-as-webpage"
|
||||
|
||||
|
||||
===== The singular value decomposition =====
|
||||
|
||||
The examples we have looked at so far are cases where we normally can
|
||||
invert the matrix $\bm{X}^T\bm{X}$. Using a polynomial expansion as we
|
||||
did both for the masses and the fitting of the equation of state,
|
||||
leads to row vectors of the design matrix which are essentially
|
||||
orthogonal due to the polynomial character of our model. Obtaining the inverse of the design matrix is then often done via a so-called LU, QR or Cholesky decomposition.
|
||||
|
||||
|
||||
|
||||
This may
|
||||
however not the be case in general and a standard matrix inversion
|
||||
algorithm based on say LU, QR or Cholesky decomposition may lead to singularities. We will see examples of this below.
|
||||
|
||||
There is however a way to partially circumvent this problem and also gain some insights about the ordinary least squares approach, and later shrinkage methods like Ridge and Lasso regressions.
|
||||
|
||||
This is given by the _Singular Value Decomposition_ algorithm, perhaps
|
||||
the most powerful linear algebra algorithm. Let us look at a
|
||||
different example where we may have problems with the standard matrix
|
||||
inversion algorithm. Thereafter we dive into the math of the SVD.
|
||||
|
||||
|
||||
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix $\bm{X}$ (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of $\bm{X}$
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
!bt
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
!et
|
||||
|
||||
The columns of $\bm{X}$ are linearly dependent. We see this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of $\mathbf{X}$ is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
Super-collinearity of an $(n \times p)$-dimensional design matrix $\mathbf{X}$ implies
|
||||
that the inverse of the matrix $\bm{X}^T\bm{X}$ (the matrix we need to invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
!bt
|
||||
\begin{align*}
|
||||
\bm{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
!et
|
||||
We see easily that $\mbox{det}(\bm{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0$. Hence, $\mathbf{X}$ is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix $\bm{X}$ has at least an eigenvalue which is zero.
|
||||
|
||||
|
||||
If our design matrix $\bm{X}$ which enters the linear regression problem
|
||||
!bt
|
||||
\begin{align}
|
||||
\bm{\beta} & = (\bm{X}^{T} \bm{X})^{-1} \bm{X}^{T} \bm{y},
|
||||
\end{align}
|
||||
!et
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of $\bm{X}^T\bm{X}$ and we cannot find the parameters (estimators) $\beta_i$.
|
||||
The estimators are only well-defined if $(\bm{X}^{T}\bm{X})^{-1}$ exits.
|
||||
This is more likely to happen when the matrix $\bm{X}$ is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters $\beta_i$ cannot be estimated.
|
||||
|
||||
A cheap *ad hoc* approach is simply to add a small diagonal component to the matrix to invert, that is we change
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^{T} \bm{X} \rightarrow \bm{X}^{T} \bm{X}+\lambda \bm{I},
|
||||
\]
|
||||
!et
|
||||
where $\bm{I}$ is the identity matrix. When we discuss _Ridge_ regression this is actually what we end up evaluating. The parameter $\lambda$ is called a hyperparameter. More about this later.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
From standard linear algebra we know that a square matrix $\bm{X}$ can be diagonalized if and only it is
|
||||
a so-called "normal matrix":"https://en.wikipedia.org/wiki/Normal_matrix", that is if $\bm{X}\in {\mathbb{R}}^{n\times n}$
|
||||
we have $\bm{X}\bm{X}^T=\bm{X}^T\bm{X}$ or if $\bm{X}\in {\mathbb{C}}^{n\times n}$ we have $\bm{X}\bm{X}^{\dagger}=\bm{X}^{\dagger}\bm{X}$.
|
||||
The matrix has then a set of eigenpairs
|
||||
|
||||
!bt
|
||||
\[
|
||||
(\lambda_1,\bm{u}_1),\dots, (\lambda_n,\bm{u}_n),
|
||||
!et
|
||||
and the eigenvalues are given by the diagonal matrix
|
||||
!bt
|
||||
\[
|
||||
\bm{\Sigma}=\mathrm{Diag}(\lambda_1, \dots,\lambda_n).
|
||||
\]
|
||||
!et
|
||||
The matrix $\bm{X}$ can be written in terms of an orthogonal/unitary transformation $\bm{U}$
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \bm{U}\bm{\Sigma}\bm{V}^T,
|
||||
\]
|
||||
!et
|
||||
with $\bm{U}\bm{U}^T=\bm{I}$ or $\bm{U}\bm{U}^{\dagger}=\bm{I}$.
|
||||
|
||||
Not all square matrices are diagonalizable. A matrix like the one discussed above
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \begin{bmatrix}
|
||||
1& -1 \\
|
||||
1& -1\\
|
||||
\end{bmatrix}
|
||||
\]
|
||||
!et
|
||||
is not diagonalizable, it is a so-called "defective matrix":"https://en.wikipedia.org/wiki/Defective_matrix". It is easy to see that the condition
|
||||
$\bm{X}\bm{X}^T=\bm{X}^T\bm{X}$ is not fulfilled.
|
||||
|
||||
|
||||
|
||||
===== The SVD, a Fantastic Algorithm =====
|
||||
|
||||
|
||||
However, and this is the strength of the SVD algorithm, any general
|
||||
matrix $\bm{X}$ can be decomposed in terms of a diagonal matrix and
|
||||
two orthogonal/unitary matrices. The "Singular Value Decompostion
|
||||
(SVD) theorem":"https://en.wikipedia.org/wiki/Singular_value_decomposition"
|
||||
states that a general $m\times n$ matrix $\bm{X}$ can be written in
|
||||
terms of a diagonal matrix $\bm{\Sigma}$ of dimensionality $m\times n$
|
||||
and two orthognal matrices $\bm{U}$ and $\bm{V}$, where the first has
|
||||
dimensionality $m \times m$ and the last dimensionality $n\times n$.
|
||||
We have then
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \bm{U}\bm{\Sigma}\bm{V}^T
|
||||
\]
|
||||
!et
|
||||
|
||||
As an example, the above defective matrix can be decomposed as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 2& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\bm{U}\bm{\Sigma}\bm{V}^T,
|
||||
\]
|
||||
!et
|
||||
|
||||
with eigenvalues $\sigma_1=2$ and $\sigma_2=0$.
|
||||
The SVD exits always!
|
||||
|
||||
The SVD
|
||||
decomposition (singular values) gives eigenvalues
|
||||
$\sigma_i\geq\sigma_{i+1}$ for all $i$ and for dimensions larger than $i=p$, the
|
||||
eigenvalues (singular values) are zero.
|
||||
|
||||
In the general case, where our design matrix $\bm{X}$ has dimension
|
||||
$n\times p$, the matrix is thus decomposed into an $n\times n$
|
||||
orthogonal matrix $\bm{U}$, a $p\times p$ orthogonal matrix $\bm{V}$
|
||||
and a diagonal matrix $\bm{\Sigma}$ with $r=\mathrm{min}(n,p)$
|
||||
singular values $\sigma_i\geq 0$ on the main diagonal and zeros filling
|
||||
the rest of the matrix. There are at most $p$ singular values
|
||||
assuming that $n > p$. In our regression examples for the nuclear
|
||||
masses and the equation of state this is indeed the case, while for
|
||||
the Ising model we have $p > n$. These are often cases that lead to
|
||||
near singular or singular matrices.
|
||||
|
||||
The columns of $\bm{U}$ are called the left singular vectors while the columns of $\bm{V}$ are the right singular vectors.
|
||||
|
||||
===== Economy-size SVD =====
|
||||
|
||||
If we assume that $n > p$, then our matrix $\bm{U}$ has dimension $n
|
||||
\times n$. The last $n-p$ columns of $\bm{U}$ become however
|
||||
irrelevant in our calculations since they are multiplied with the
|
||||
zeros in $\bm{\Sigma}$.
|
||||
|
||||
The economy-size decomposition removes extra rows or columns of zeros
|
||||
from the diagonal matrix of singular values, $\bm{\Sigma}$, along with the columns
|
||||
in either $\bm{U}$ or $\bm{V}$ that multiply those zeros in the expression.
|
||||
Removing these zeros and columns can improve execution time
|
||||
and reduce storage requirements without compromising the accuracy of
|
||||
the decomposition.
|
||||
|
||||
If $n > p$, we keep only the first $p$ columns of $\bm{U}$ and $\bm{\Sigma}$ has dimension $p\times p$.
|
||||
If $p > n$, then only the first $n$ columns of $\bm{V}$ are computed and $\bm{\Sigma}$ has dimension $n\times n$.
|
||||
The $n=p$ case is obvious, we retain the full SVD.
|
||||
In general the economy-size SVD leads to less FLOPS and still conserving the desired accuracy.
|
||||
|
||||
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
# SVD inversion
|
||||
def SVDinv(A):
|
||||
''' Takes as input a numpy matrix A and returns inv(A) based on singular value decomposition (SVD).
|
||||
SVD is numerically more stable than the inversion algorithms provided by
|
||||
numpy and scipy.linalg at the cost of being slower.
|
||||
'''
|
||||
U, s, VT = np.linalg.svd(A)
|
||||
# print('test U')
|
||||
# print( (np.transpose(U) @ U - U @np.transpose(U)))
|
||||
# print('test VT')
|
||||
# print( (np.transpose(VT) @ VT - VT @np.transpose(VT)))
|
||||
print(U)
|
||||
print(s)
|
||||
print(VT)
|
||||
|
||||
D = np.zeros((len(U),len(VT)))
|
||||
for i in range(0,len(VT)):
|
||||
D[i,i]=s[i]
|
||||
UT = np.transpose(U); V = np.transpose(VT); invD = np.linalg.inv(D)
|
||||
return np.matmul(V,np.matmul(invD,UT))
|
||||
|
||||
|
||||
X = np.array([ [1.0, -1.0, 2.0], [1.0, 0.0, 1.0], [1.0, 2.0, -1.0], [1.0, 1.0, 0.0] ])
|
||||
print(X)
|
||||
A = np.transpose(X) @ X
|
||||
print(A)
|
||||
# Brute force inversion of super-collinear matrix
|
||||
#B = np.linalg.inv(A)
|
||||
#print(B)
|
||||
C = SVDinv(A)
|
||||
print(C)
|
||||
|
||||
!ec
|
||||
|
||||
The matrix $\bm{X}$ has columns that are linearly dependent. The first
|
||||
column is the row-wise sum of the other two columns. The rank of a
|
||||
matrix (the column rank) is the dimension of space spanned by the
|
||||
column vectors. The rank of the matrix is the number of linearly
|
||||
independent columns, in this case just $2$. We see this from the
|
||||
singular values when running the above code. Running the standard
|
||||
inversion algorithm for matrix inversion with $\bm{X}^T\bm{X}$ results
|
||||
in the program terminating due to a singular matrix.
|
||||
|
||||
|
||||
|
||||
|
||||
There are several interesting mathematical properties which will be
|
||||
relevant when we are going to discuss the differences between say
|
||||
ordinary least squares (OLS) and _Ridge_ regression.
|
||||
|
||||
We have from OLS that the parameters of the linear approximation are given by
|
||||
!bt
|
||||
\[
|
||||
\bm{\tilde{y}} = \bm{X}\bm{\beta} = \bm{X}\left(\bm{X}^T\bm{X}\right)^{-1}\bm{X}^T\bm{y}.
|
||||
\]
|
||||
!et
|
||||
|
||||
The matrix to invert can be rewritten in terms of our SVD decomposition as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^T\bm{X} = \bm{V}\bm{\Sigma}^T\bm{U}^T\bm{U}\bm{\Sigma}\bm{V}^T.
|
||||
\]
|
||||
!et
|
||||
Using the orthogonality properties of $\bm{U}$ we have
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^T\bm{X} = \bm{V}\bm{\Sigma}^T\bm{\Sigma}\bm{V}^T = \bm{V}\bm{D}\bm{V}^T,
|
||||
\]
|
||||
!et
|
||||
with $\bm{D}$ being a diagonal matrix with values along the diagonal given by the singular values squared.
|
||||
|
||||
This means that
|
||||
!bt
|
||||
\[
|
||||
(\bm{X}^T\bm{X})\bm{V} = \bm{V}\bm{D},
|
||||
\]
|
||||
!et
|
||||
that is the eigenvectors of $(\bm{X}^T\bm{X})$ are given by the columns of the right singular matrix of $\bm{X}$ and the eigenvalues are the squared singular values. It is easy to show (show this) that
|
||||
!bt
|
||||
\[
|
||||
(\bm{X}\bm{X}^T)\bm{U} = \bm{U}\bm{D},
|
||||
\]
|
||||
!et
|
||||
that is, the eigenvectors of $(\bm{X}\bm{X})^T$ are the columns of the left singular matrix and the eigenvalues are the same.
|
||||
|
||||
Going back to our OLS equation we have
|
||||
!bt
|
||||
\[
|
||||
\bm{X}\bm{\beta} = \bm{X}\left(\bm{V}\bm{D}\bm{V}^T \right)^{-1}\bm{X}^T\bm{y}=\bm{U\Sigma V^T}\left(\bm{V}\bm{D}\bm{V}^T \right)^{-1}(\bm{U\Sigma V^T})^T\bm{y}=\bm{U}\bm{U}^T\bm{y}.
|
||||
\]
|
||||
!et
|
||||
We will come back to this expression when we discuss Ridge regression.
|
||||
|
||||
|
||||
$$ \tilde{y}^{OLS}=\bm{X}\hat{\beta}^{OLS}=\sum_{j=1}^p \bm{u}_j\bm{u}_j^T\bm{y}$$ and for Ridge we have
|
||||
|
||||
$$ \tilde{y}^{Ridge}=\bm{X}\hat{\beta}^{Ridge}=\sum_{j=1}^p \bm{u}_j\frac{\sigma_j^2}{\sigma_j^2+\lambda}\bm{u}_j^T\bm{y}$$ .
|
||||
|
||||
It is indeed the economy-sized SVD, note the summation runs up tp $$p$$ only and not $$n$$.
|
||||
|
||||
Here we have that $$\bm{X} = \bm{U}\bm{\Sigma}\bm{V}^T$$, with $$\Sigma$$ being an $$ n\times p$$ matrix and $$\bm{V}$$ being a $$ p\times p$$ matrix. We also have assumed here that $$ n > p$$.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
===== Ridge and LASSO Regression =====
|
||||
|
||||
"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember11.mp4?vrtx=view-as-webpage"
|
||||
|
||||
Let us remind ourselves about the expression for the standard Mean Squared Error (MSE) which we used to define our cost function and the equations for the ordinary least squares (OLS) method, that is
|
||||
our optimization problem is
|
||||
!bt
|
||||
\[
|
||||
{\displaystyle \min_{\bm{\beta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\beta}\right)^T\left(\bm{y}-\bm{X}\bm{\beta}\right)\right\}.
|
||||
\]
|
||||
!et
|
||||
or we can state it as
|
||||
!bt
|
||||
\[
|
||||
{\displaystyle \min_{\bm{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2,
|
||||
\]
|
||||
!et
|
||||
where we have used the definition of a norm-2 vector, that is
|
||||
!bt
|
||||
\[
|
||||
\vert\vert \bm{x}\vert\vert_2 = \sqrt{\sum_i x_i^2}.
|
||||
\]
|
||||
!et
|
||||
|
||||
By minimizing the above equation with respect to the parameters
|
||||
$\bm{\beta}$ we could then obtain an analytical expression for the
|
||||
parameters $\bm{\beta}$. We can add a regularization parameter $\lambda$ by
|
||||
defining a new cost function to be optimized, that is
|
||||
|
||||
!bt
|
||||
\[
|
||||
{\displaystyle \min_{\bm{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2+\lambda\vert\vert \bm{\beta}\vert\vert_2^2
|
||||
\]
|
||||
!et
|
||||
|
||||
which leads to the Ridge regression minimization problem where we
|
||||
require that $\vert\vert \bm{\beta}\vert\vert_2^2\le t$, where $t$ is
|
||||
a finite number larger than zero. By defining
|
||||
|
||||
!bt
|
||||
\[
|
||||
C(\bm{X},\bm{\beta})=\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2+\lambda\vert\vert \bm{\beta}\vert\vert_1,
|
||||
\]
|
||||
!et
|
||||
|
||||
we have a new optimization equation
|
||||
!bt
|
||||
\[
|
||||
{\displaystyle \min_{\bm{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2+\lambda\vert\vert \bm{\beta}\vert\vert_1
|
||||
\]
|
||||
!et
|
||||
which leads to Lasso regression. Lasso stands for least absolute shrinkage and selection operator.
|
||||
|
||||
Here we have defined the norm-1 as
|
||||
!bt
|
||||
\[
|
||||
\vert\vert \bm{x}\vert\vert_1 = \sum_i \vert x_i\vert.
|
||||
\]
|
||||
!et
|
||||
|
||||
|
||||
|
||||
Using the matrix-vector expression for Ridge regression,
|
||||
|
||||
!bt
|
||||
\[
|
||||
C(\bm{X},\bm{\beta})=\frac{1}{n}\left\{(\bm{y}-\bm{X}\bm{\beta})^T(\bm{y}-\bm{X}\bm{\beta})\right\}+\lambda\bm{\beta}^T\bm{\beta},
|
||||
\]
|
||||
!et
|
||||
|
||||
by taking the derivatives with respect to $\bm{\beta}$ we obtain then
|
||||
a slightly modified matrix inversion problem which for finite values
|
||||
of $\lambda$ does not suffer from singularity problems. We obtain
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{\beta}^{\mathrm{Ridge}} = \left(\bm{X}^T\bm{X}+\lambda\bm{I}\right)^{-1}\bm{X}^T\bm{y},
|
||||
\]
|
||||
!et
|
||||
|
||||
with $\bm{I}$ being a $p\times p$ identity matrix with the constraint that
|
||||
|
||||
!bt
|
||||
\[
|
||||
\sum_{i=0}^{p-1} \beta_i^2 \leq t,
|
||||
\]
|
||||
!et
|
||||
|
||||
with $t$ a finite positive number.
|
||||
|
||||
We see that Ridge regression is nothing but the standard
|
||||
OLS with a modified diagonal term added to $\bm{X}^T\bm{X}$. The
|
||||
consequences, in particular for our discussion of the bias-variance tradeoff
|
||||
are rather interesting.
|
||||
|
||||
Furthermore, if we use the result above in terms of the SVD decomposition (our analysis was done for the OLS method), we had
|
||||
!bt
|
||||
\[
|
||||
(\bm{X}\bm{X}^T)\bm{U} = \bm{U}\bm{D}.
|
||||
\]
|
||||
!et
|
||||
|
||||
We can analyse the OLS solutions in terms of the eigenvectors (the columns) of the right singular value matrix $\bm{U}$ as
|
||||
!bt
|
||||
\[
|
||||
\bm{X}\bm{\beta} = \bm{X}\left(\bm{V}\bm{D}\bm{V}^T \right)^{-1}\bm{X}^T\bm{y}=\bm{U\Sigma V^T}\left(\bm{V}\bm{D}\bm{V}^T \right)^{-1}(\bm{U\Sigma V^T})^T\bm{y}=\bm{U}\bm{U}^T\bm{y}
|
||||
\]
|
||||
!et
|
||||
|
||||
|
||||
For Ridge regression this becomes
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}\bm{\beta}^{\mathrm{Ridge}} = \bm{U\Sigma V^T}\left(\bm{V}\bm{D}\bm{V}^T+\lambda\bm{I} \right)^{-1}(\bm{U\Sigma V^T})^T\bm{y}=\sum_{j=0}^{p-1}\bm{u}_j\bm{u}_j^T\frac{\sigma_j^2}{\sigma_j^2+\lambda}\bm{y},
|
||||
\]
|
||||
!et
|
||||
|
||||
with the vectors $\bm{u}_j$ being the columns of $\bm{U}$.
|
||||
|
||||
|
||||
Since $\lambda \geq 0$, it means that compared to OLS, we have
|
||||
|
||||
!bt
|
||||
\[
|
||||
\frac{\sigma_j^2}{\sigma_j^2+\lambda} \leq 1.
|
||||
\]
|
||||
!et
|
||||
|
||||
Ridge regression finds the coordinates of $\bm{y}$ with respect to the
|
||||
orthonormal basis $\bm{U}$, it then shrinks the coordinates by
|
||||
$\frac{\sigma_j^2}{\sigma_j^2+\lambda}$. Recall that the SVD has
|
||||
eigenvalues ordered in a descending way, that is $\sigma_i \geq
|
||||
\sigma_{i+1}$.
|
||||
|
||||
For small eigenvalues $\sigma_i$ it means that their contributions become less important, a fact which can be used to reduce the number of degrees of freedom.
|
||||
Actually, calculating the variance of $\bm{X}\bm{v}_j$ shows that this quantity is equal to $\sigma_j^2/n$.
|
||||
With a parameter $\lambda$ we can thus shrink the role of specific parameters.
|
||||
|
||||
|
||||
|
||||
For the sake of simplicity, let us assume that the design matrix is orthonormal, that is
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^T\bm{X}=(\bm{X}^T\bm{X})^{-1} =\bm{I}.
|
||||
\]
|
||||
!et
|
||||
|
||||
In this case the standard OLS results in
|
||||
!bt
|
||||
\[
|
||||
\bm{\beta}^{\mathrm{OLS}} = \bm{X}^T\bm{y}=\sum_{i=0}^{p-1}\bm{u}_j\bm{u}_j^T\bm{y},
|
||||
\]
|
||||
!et
|
||||
|
||||
and
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{\beta}^{\mathrm{Ridge}} = \left(\bm{I}+\lambda\bm{I}\right)^{-1}\bm{X}^T\bm{y}=\left(1+\lambda\right)^{-1}\bm{\beta}^{\mathrm{OLS}},
|
||||
\]
|
||||
!et
|
||||
|
||||
that is the Ridge estimator scales the OLS estimator by the inverse of a factor $1+\lambda$, and
|
||||
the Ridge estimator converges to zero when the hyperparameter goes to
|
||||
infinity.
|
||||
|
||||
We will come back to more interpreations after we have gone through some of the statistical analysis part.
|
||||
|
||||
For more discussions of Ridge and Lasso regression, "Wessel van Wieringen's":"https://arxiv.org/abs/1509.09169" article is highly recommended.
|
||||
Similarly, "Mehta et al's article":"https://arxiv.org/abs/1803.08823" is also recommended.
|
||||
|
||||
|
||||
|
||||
===== A better understanding of regularization =====
|
||||
|
||||
The parameter $\lambda$ that we have introduced in the Ridge (and
|
||||
Lasso as well) regression is often called a regularization parameter
|
||||
or shrinkage parameter. It is common to call it a hyperparameter. What does it mean mathemtically?
|
||||
|
||||
Here we will first look at how to analyze the difference between the
|
||||
standard OLS equations and the Ridge expressions in terms of a linear
|
||||
algebra analysis using the SVD algorithm. Thereafter, we will link
|
||||
(see the material on the bias-variance tradeoff below) these
|
||||
observation to the statisical analysis of the results. In particular
|
||||
we consider how the variance of the parameters $\bm{\beta}$ is
|
||||
affected by changing the parameter $\lambda$.
|
||||
|
||||
|
||||
We have our design matrix
|
||||
$\bm{X}\in {\mathbb{R}}^{n\times p}$. With the SVD we decompose it as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \bm{U\Sigma V^T},
|
||||
\]
|
||||
!et
|
||||
|
||||
with $\bm{U}\in {\mathbb{R}}^{n\times n}$, $\bm{\Sigma}\in {\mathbb{R}}^{n\times p}$
|
||||
and $\bm{V}\in {\mathbb{R}}^{p\times p}$.
|
||||
|
||||
The matrices $\bm{U}$ and $\bm{V}$ are unitary/orthonormal matrices, that is in case the matrices are real we have $\bm{U}^T\bm{U}=\bm{U}\bm{U}^T=\bm{I}$ and $\bm{V}^T\bm{V}=\bm{V}\bm{V}^T=\bm{I}$.
|
||||
|
||||
|
||||
|
||||
===== Introducing the Covariance and Correlation functions =====
|
||||
|
||||
Before we discuss the link between for example Ridge regression and the singular value decomposition, we need to remind ourselves about
|
||||
the definition of the covariance and the correlation function. These are quantities
|
||||
|
||||
Suppose we have defined two vectors
|
||||
$\hat{x}$ and $\hat{y}$ with $n$ elements each. The covariance matrix $\bm{C}$ is defined as
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x},\bm{y}] = \begin{bmatrix} \mathrm{cov}[\bm{x},\bm{x}] & \mathrm{cov}[\bm{x},\bm{y}] \\
|
||||
\mathrm{cov}[\bm{y},\bm{x}] & \mathrm{cov}[\bm{y},\bm{y}] \\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
where for example
|
||||
!bt
|
||||
\[
|
||||
\mathrm{cov}[\bm{x},\bm{y}] =\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})(y_i- \overline{y}).
|
||||
\]
|
||||
!et
|
||||
With this definition and recalling that the variance is defined as
|
||||
!bt
|
||||
\[
|
||||
\mathrm{var}[\bm{x}]=\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})^2,
|
||||
\]
|
||||
!et
|
||||
we can rewrite the covariance matrix as
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x},\bm{y}] = \begin{bmatrix} \mathrm{var}[\bm{x}] & \mathrm{cov}[\bm{x},\bm{y}] \\
|
||||
\mathrm{cov}[\bm{x},\bm{y}] & \mathrm{var}[\bm{y}] \\
|
||||
\end{bmatrix}.
|
||||
\]
|
||||
!et
|
||||
|
||||
The covariance takes values between zero and infinity and may thus
|
||||
lead to problems with loss of numerical precision for particularly
|
||||
large values. It is common to scale the covariance matrix by
|
||||
introducing instead the correlation matrix defined via the so-called
|
||||
correlation function
|
||||
|
||||
!bt
|
||||
\[
|
||||
\mathrm{corr}[\bm{x},\bm{y}]=\frac{\mathrm{cov}[\bm{x},\bm{y}]}{\sqrt{\mathrm{var}[\bm{x}] \mathrm{var}[\bm{y}]}}.
|
||||
\]
|
||||
!et
|
||||
|
||||
The correlation function is then given by values $\mathrm{corr}[\bm{x},\bm{y}]
|
||||
\in [-1,1]$. This avoids eventual problems with too large values. We
|
||||
can then define the correlation matrix for the two vectors $\bm{x}$
|
||||
and $\bm{y}$ as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{K}[\bm{x},\bm{y}] = \begin{bmatrix} 1 & \mathrm{corr}[\bm{x},\bm{y}] \\
|
||||
\mathrm{corr}[\bm{y},\bm{x}] & 1 \\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
|
||||
In the above example this is the function we constructed using _pandas_.
|
||||
|
||||
|
||||
|
||||
In our derivation of the various regression algorithms like _Ordinary Least Squares_ or _Ridge regression_
|
||||
we defined the design/feature matrix $\bm{X}$ as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}=\begin{bmatrix}
|
||||
x_{0,0} & x_{0,1} & x_{0,2}& \dots & \dots x_{0,p-1}\\
|
||||
x_{1,0} & x_{1,1} & x_{1,2}& \dots & \dots x_{1,p-1}\\
|
||||
x_{2,0} & x_{2,1} & x_{2,2}& \dots & \dots x_{2,p-1}\\
|
||||
\dots & \dots & \dots & \dots \dots & \dots \\
|
||||
x_{n-2,0} & x_{n-2,1} & x_{n-2,2}& \dots & \dots x_{n-2,p-1}\\
|
||||
x_{n-1,0} & x_{n-1,1} & x_{n-1,2}& \dots & \dots x_{n-1,p-1}\\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
with $\bm{X}\in {\mathbb{R}}^{n\times p}$, with the predictors/features $p$ refering to the column numbers and the
|
||||
entries $n$ being the row elements.
|
||||
We can rewrite the design/feature matrix in terms of its column vectors as
|
||||
!bt
|
||||
\[
|
||||
\bm{X}=\begin{bmatrix} \bm{x}_0 & \bm{x}_1 & \bm{x}_2 & \dots & \dots & \bm{x}_{p-1}\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
with a given vector
|
||||
!bt
|
||||
\[
|
||||
\bm{x}_i^T = \begin{bmatrix}x_{0,i} & x_{1,i} & x_{2,i}& \dots & \dots x_{n-1,i}\end{bmatrix}.
|
||||
\]
|
||||
!et
|
||||
|
||||
With these definitions, we can now rewrite our $2\times 2$
|
||||
correaltion/covariance matrix in terms of a moe general design/feature
|
||||
matrix $\bm{X}\in {\mathbb{R}}^{n\times p}$. This leads to a $p\times p$
|
||||
covariance matrix for the vectors $\bm{x}_i$ with $i=0,1,\dots,p-1$
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x}] = \begin{bmatrix}
|
||||
\mathrm{var}[\bm{x}_0] & \mathrm{cov}[\bm{x}_0,\bm{x}_1] & \mathrm{cov}[\bm{x}_0,\bm{x}_2] & \dots & \dots & \mathrm{cov}[\bm{x}_0,\bm{x}_{p-1}]\\
|
||||
\mathrm{cov}[\bm{x}_1,\bm{x}_0] & \mathrm{var}[\bm{x}_1] & \mathrm{cov}[\bm{x}_1,\bm{x}_2] & \dots & \dots & \mathrm{cov}[\bm{x}_1,\bm{x}_{p-1}]\\
|
||||
\mathrm{cov}[\bm{x}_2,\bm{x}_0] & \mathrm{cov}[\bm{x}_2,\bm{x}_1] & \mathrm{var}[\bm{x}_2] & \dots & \dots & \mathrm{cov}[\bm{x}_2,\bm{x}_{p-1}]\\
|
||||
\dots & \dots & \dots & \dots & \dots & \dots \\
|
||||
\dots & \dots & \dots & \dots & \dots & \dots \\
|
||||
\mathrm{cov}[\bm{x}_{p-1},\bm{x}_0] & \mathrm{cov}[\bm{x}_{p-1},\bm{x}_1] & \mathrm{cov}[\bm{x}_{p-1},\bm{x}_{2}] & \dots & \dots & \mathrm{var}[\bm{x}_{p-1}]\\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
and the correlation matrix
|
||||
!bt
|
||||
\[
|
||||
\bm{K}[\bm{x}] = \begin{bmatrix}
|
||||
1 & \mathrm{corr}[\bm{x}_0,\bm{x}_1] & \mathrm{corr}[\bm{x}_0,\bm{x}_2] & \dots & \dots & \mathrm{corr}[\bm{x}_0,\bm{x}_{p-1}]\\
|
||||
\mathrm{corr}[\bm{x}_1,\bm{x}_0] & 1 & \mathrm{corr}[\bm{x}_1,\bm{x}_2] & \dots & \dots & \mathrm{corr}[\bm{x}_1,\bm{x}_{p-1}]\\
|
||||
\mathrm{corr}[\bm{x}_2,\bm{x}_0] & \mathrm{corr}[\bm{x}_2,\bm{x}_1] & 1 & \dots & \dots & \mathrm{corr}[\bm{x}_2,\bm{x}_{p-1}]\\
|
||||
\dots & \dots & \dots & \dots & \dots & \dots \\
|
||||
\dots & \dots & \dots & \dots & \dots & \dots \\
|
||||
\mathrm{corr}[\bm{x}_{p-1},\bm{x}_0] & \mathrm{corr}[\bm{x}_{p-1},\bm{x}_1] & \mathrm{corr}[\bm{x}_{p-1},\bm{x}_{2}] & \dots & \dots & 1\\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
|
||||
|
||||
|
||||
The Numpy function _np.cov_ calculates the covariance elements using
|
||||
the factor $1/(n-1)$ instead of $1/n$ since it assumes we do not have
|
||||
the exact mean values. The following simple function uses the
|
||||
_np.vstack_ function which takes each vector of dimension $1\times n$
|
||||
and produces a $2\times n$ matrix $\bm{W}$
|
||||
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{W} = \begin{bmatrix} x_0 & y_0 \\
|
||||
x_1 & y_1 \\
|
||||
x_2 & y_2\\
|
||||
\dots & \dots \\
|
||||
x_{n-2} & y_{n-2}\\
|
||||
x_{n-1} & y_{n-1} &
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
|
||||
which in turn is converted into into the $2\times 2$ covariance matrix
|
||||
$\bm{C}$ via the Numpy function _np.cov()_. We note that we can also calculate
|
||||
the mean value of each set of samples $\bm{x}$ etc using the Numpy
|
||||
function _np.mean(x)_. We can also extract the eigenvalues of the
|
||||
covariance matrix through the _np.linalg.eig()_ function.
|
||||
|
||||
!bc pycod
|
||||
# Importing various packages
|
||||
import numpy as np
|
||||
n = 100
|
||||
x = np.random.normal(size=n)
|
||||
print(np.mean(x))
|
||||
y = 4+3*x+np.random.normal(size=n)
|
||||
print(np.mean(y))
|
||||
W = np.vstack((x, y))
|
||||
C = np.cov(W)
|
||||
print(C)
|
||||
!ec
|
||||
|
||||
|
||||
The previous example can be converted into the correlation matrix by
|
||||
simply scaling the matrix elements with the variances. We should also
|
||||
subtract the mean values for each column. This leads to the following
|
||||
code which sets up the correlations matrix for the previous example in
|
||||
a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the $2\times 2$ correlation matrix (since we have only two vectors).
|
||||
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
n = 100
|
||||
# define two vectors
|
||||
x = np.random.random(size=n)
|
||||
y = 4+3*x+np.random.normal(size=n)
|
||||
#scaling the x and y vectors
|
||||
x = x - np.mean(x)
|
||||
y = y - np.mean(y)
|
||||
variance_x = np.sum(x@x)/n
|
||||
variance_y = np.sum(y@y)/n
|
||||
print(variance_x)
|
||||
print(variance_y)
|
||||
cov_xy = np.sum(x@y)/n
|
||||
cov_xx = np.sum(x@x)/n
|
||||
cov_yy = np.sum(y@y)/n
|
||||
C = np.zeros((2,2))
|
||||
C[0,0]= cov_xx/variance_x
|
||||
C[1,1]= cov_yy/variance_y
|
||||
C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)
|
||||
C[1,0]= C[0,1]
|
||||
print(C)
|
||||
!ec
|
||||
|
||||
We see that the matrix elements along the diagonal are one as they
|
||||
should be and that the matrix is symmetric. Furthermore, diagonalizing
|
||||
this matrix we easily see that it is a positive definite matrix.
|
||||
|
||||
The above procedure with _numpy_ can be made more compact if we use _pandas_.
|
||||
|
||||
|
||||
We whow here how we can set up the correlation matrix using _pandas_, as done in this simple code
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
n = 10
|
||||
x = np.random.normal(size=n)
|
||||
x = x - np.mean(x)
|
||||
y = 4+3*x+np.random.normal(size=n)
|
||||
y = y - np.mean(y)
|
||||
X = (np.vstack((x, y))).T
|
||||
print(X)
|
||||
Xpd = pd.DataFrame(X)
|
||||
print(Xpd)
|
||||
correlation_matrix = Xpd.corr()
|
||||
print(correlation_matrix)
|
||||
!ec
|
||||
|
||||
|
||||
We expand this model to the Franke function discussed above.
|
||||
|
||||
|
||||
|
||||
!bc pycod
|
||||
# Common imports
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def FrankeFunction(x,y):
|
||||
term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
|
||||
term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
|
||||
term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
|
||||
term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
|
||||
return term1 + term2 + term3 + term4
|
||||
|
||||
|
||||
def create_X(x, y, n ):
|
||||
if len(x.shape) > 1:
|
||||
x = np.ravel(x)
|
||||
y = np.ravel(y)
|
||||
|
||||
N = len(x)
|
||||
l = int((n+1)*(n+2)/2) # Number of elements in beta
|
||||
X = np.ones((N,l))
|
||||
|
||||
for i in range(1,n+1):
|
||||
q = int((i)*(i+1)/2)
|
||||
for k in range(i+1):
|
||||
X[:,q+k] = (x**(i-k))*(y**k)
|
||||
|
||||
return X
|
||||
|
||||
|
||||
# Making meshgrid of datapoints and compute Franke's function
|
||||
n = 4
|
||||
N = 100
|
||||
x = np.sort(np.random.uniform(0, 1, N))
|
||||
y = np.sort(np.random.uniform(0, 1, N))
|
||||
z = FrankeFunction(x, y)
|
||||
X = create_X(x, y, n=n)
|
||||
|
||||
Xpd = pd.DataFrame(X)
|
||||
# subtract the mean values and set up the covariance matrix
|
||||
Xpd = Xpd - Xpd.mean()
|
||||
covariance_matrix = Xpd.cov()
|
||||
print(covariance_matrix)
|
||||
!ec
|
||||
|
||||
We note here that the covariance is zero for the first rows and
|
||||
columns since all matrix elements in the design matrix were set to one
|
||||
(we are fitting the function in terms of a polynomial of degree $n$).
|
||||
|
||||
This means that the variance for these elements will be zero and will
|
||||
cause problems when we set up the correlation matrix. We can simply
|
||||
drop these elements and construct a correlation
|
||||
matrix without these elements.
|
||||
|
||||
|
||||
|
||||
|
||||
We can rewrite the covariance matrix in a more compact form in terms of the design/feature matrix $\bm{X}$ as
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x}] = \frac{1}{n}\bm{X}^T\bm{X}= \mathbb{E}[\bm{X}^T\bm{X}].
|
||||
\]
|
||||
!et
|
||||
|
||||
To see this let us simply look at a design matrix $\bm{X}\in {\mathbb{R}}^{2\times 2}$
|
||||
!bt
|
||||
\[
|
||||
\bm{X}=\begin{bmatrix}
|
||||
x_{00} & x_{01}\\
|
||||
x_{10} & x_{11}\\
|
||||
\end{bmatrix}=\begin{bmatrix}
|
||||
\bm{x}_{0} & \bm{x}_{1}\\
|
||||
\end{bmatrix}.
|
||||
\]
|
||||
!et
|
||||
|
||||
If we then compute the expectation value
|
||||
!bt
|
||||
\[
|
||||
\mathbb{E}[\bm{X}^T\bm{X}] = \frac{1}{n}\bm{X}^T\bm{X}=\begin{bmatrix}
|
||||
x_{00}^2+x_{01}^2 & x_{00}x_{10}+x_{01}x_{11}\\
|
||||
x_{10}x_{00}+x_{11}x_{01} & x_{10}^2+x_{11}^2\\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
which is just
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x}_0,\bm{x}_1] = \bm{C}[\bm{x}]=\begin{bmatrix} \mathrm{var}[\bm{x}_0] & \mathrm{cov}[\bm{x}_0,\bm{x}_1] \\
|
||||
\mathrm{cov}[\bm{x}_1,\bm{x}_0] & \mathrm{var}[\bm{x}_1] \\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
where we wrote $$\bm{C}[\bm{x}_0,\bm{x}_1] = \bm{C}[\bm{x}]$$ to indicate that this the covariance of the vectors $\bm{x}$ of the design/feature matrix $\bm{X}$.
|
||||
|
||||
It is easy to generalize this to a matrix $\bm{X}\in {\mathbb{R}}^{n\times p}$.
|
||||
|
||||
|
||||
===== Linking with SVD =====
|
||||
|
||||
@@ -0,0 +1,848 @@
|
||||
======= Ridge and Lasso Regression =======
|
||||
|
||||
"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember10.mp4?vrtx=view-as-webpage"
|
||||
|
||||
|
||||
===== The singular value decomposition =====
|
||||
|
||||
The examples we have looked at so far are cases where we normally can
|
||||
invert the matrix $\bm{X}^T\bm{X}$. Using a polynomial expansion as we
|
||||
did both for the masses and the fitting of the equation of state,
|
||||
leads to row vectors of the design matrix which are essentially
|
||||
orthogonal due to the polynomial character of our model. Obtaining the inverse of the design matrix is then often done via a so-called LU, QR or Cholesky decomposition.
|
||||
|
||||
|
||||
|
||||
This may
|
||||
however not the be case in general and a standard matrix inversion
|
||||
algorithm based on say LU, QR or Cholesky decomposition may lead to singularities. We will see examples of this below.
|
||||
|
||||
There is however a way to partially circumvent this problem and also gain some insights about the ordinary least squares approach, and later shrinkage methods like Ridge and Lasso regressions.
|
||||
|
||||
This is given by the _Singular Value Decomposition_ algorithm, perhaps
|
||||
the most powerful linear algebra algorithm. Let us look at a
|
||||
different example where we may have problems with the standard matrix
|
||||
inversion algorithm. Thereafter we dive into the math of the SVD.
|
||||
|
||||
|
||||
|
||||
One of the typical problems we encounter with linear regression, in particular
|
||||
when the matrix $\bm{X}$ (our so-called design matrix) is high-dimensional,
|
||||
are problems with near singular or singular matrices. The column vectors of $\bm{X}$
|
||||
may be linearly dependent, normally referred to as super-collinearity.
|
||||
This means that the matrix may be rank deficient and it is basically impossible to
|
||||
to model the data using linear regression. As an example, consider the matrix
|
||||
!bt
|
||||
\begin{align*}
|
||||
\mathbf{X} & = \left[
|
||||
\begin{array}{rrr}
|
||||
1 & -1 & 2
|
||||
\\
|
||||
1 & 0 & 1
|
||||
\\
|
||||
1 & 2 & -1
|
||||
\\
|
||||
1 & 1 & 0
|
||||
\end{array} \right]
|
||||
\end{align*}
|
||||
!et
|
||||
|
||||
The columns of $\bm{X}$ are linearly dependent. We see this easily since the
|
||||
the first column is the row-wise sum of the other two columns. The rank (more correct,
|
||||
the column rank) of a matrix is the dimension of the space spanned by the
|
||||
column vectors. Hence, the rank of $\mathbf{X}$ is equal to the number
|
||||
of linearly independent columns. In this particular case the matrix has rank 2.
|
||||
|
||||
Super-collinearity of an $(n \times p)$-dimensional design matrix $\mathbf{X}$ implies
|
||||
that the inverse of the matrix $\bm{X}^T\bm{X}$ (the matrix we need to invert to solve the linear regression equations) is non-invertible. If we have a square matrix that does not have an inverse, we say this matrix singular. The example here demonstrates this
|
||||
!bt
|
||||
\begin{align*}
|
||||
\bm{X} & = \left[
|
||||
\begin{array}{rr}
|
||||
1 & -1
|
||||
\\
|
||||
1 & -1
|
||||
\end{array} \right].
|
||||
\end{align*}
|
||||
!et
|
||||
We see easily that $\mbox{det}(\bm{X}) = x_{11} x_{22} - x_{12} x_{21} = 1 \times (-1) - 1 \times (-1) = 0$. Hence, $\mathbf{X}$ is singular and its inverse is undefined.
|
||||
This is equivalent to saying that the matrix $\bm{X}$ has at least an eigenvalue which is zero.
|
||||
|
||||
|
||||
If our design matrix $\bm{X}$ which enters the linear regression problem
|
||||
!bt
|
||||
\begin{align}
|
||||
\bm{\beta} & = (\bm{X}^{T} \bm{X})^{-1} \bm{X}^{T} \bm{y},
|
||||
\end{align}
|
||||
!et
|
||||
has linearly dependent column vectors, we will not be able to compute the inverse
|
||||
of $\bm{X}^T\bm{X}$ and we cannot find the parameters (estimators) $\beta_i$.
|
||||
The estimators are only well-defined if $(\bm{X}^{T}\bm{X})^{-1}$ exits.
|
||||
This is more likely to happen when the matrix $\bm{X}$ is high-dimensional. In this case it is likely to encounter a situation where
|
||||
the regression parameters $\beta_i$ cannot be estimated.
|
||||
|
||||
A cheap *ad hoc* approach is simply to add a small diagonal component to the matrix to invert, that is we change
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^{T} \bm{X} \rightarrow \bm{X}^{T} \bm{X}+\lambda \bm{I},
|
||||
\]
|
||||
!et
|
||||
where $\bm{I}$ is the identity matrix. When we discuss _Ridge_ regression this is actually what we end up evaluating. The parameter $\lambda$ is called a hyperparameter. More about this later.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
From standard linear algebra we know that a square matrix $\bm{X}$ can be diagonalized if and only it is
|
||||
a so-called "normal matrix":"https://en.wikipedia.org/wiki/Normal_matrix", that is if $\bm{X}\in {\mathbb{R}}^{n\times n}$
|
||||
we have $\bm{X}\bm{X}^T=\bm{X}^T\bm{X}$ or if $\bm{X}\in {\mathbb{C}}^{n\times n}$ we have $\bm{X}\bm{X}^{\dagger}=\bm{X}^{\dagger}\bm{X}$.
|
||||
The matrix has then a set of eigenpairs
|
||||
|
||||
!bt
|
||||
\[
|
||||
(\lambda_1,\bm{u}_1),\dots, (\lambda_n,\bm{u}_n),
|
||||
!et
|
||||
and the eigenvalues are given by the diagonal matrix
|
||||
!bt
|
||||
\[
|
||||
\bm{\Sigma}=\mathrm{Diag}(\lambda_1, \dots,\lambda_n).
|
||||
\]
|
||||
!et
|
||||
The matrix $\bm{X}$ can be written in terms of an orthogonal/unitary transformation $\bm{U}$
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \bm{U}\bm{\Sigma}\bm{V}^T,
|
||||
\]
|
||||
!et
|
||||
with $\bm{U}\bm{U}^T=\bm{I}$ or $\bm{U}\bm{U}^{\dagger}=\bm{I}$.
|
||||
|
||||
Not all square matrices are diagonalizable. A matrix like the one discussed above
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \begin{bmatrix}
|
||||
1& -1 \\
|
||||
1& -1\\
|
||||
\end{bmatrix}
|
||||
\]
|
||||
!et
|
||||
is not diagonalizable, it is a so-called "defective matrix":"https://en.wikipedia.org/wiki/Defective_matrix". It is easy to see that the condition
|
||||
$\bm{X}\bm{X}^T=\bm{X}^T\bm{X}$ is not fulfilled.
|
||||
|
||||
|
||||
|
||||
===== The SVD, a Fantastic Algorithm =====
|
||||
|
||||
|
||||
However, and this is the strength of the SVD algorithm, any general
|
||||
matrix $\bm{X}$ can be decomposed in terms of a diagonal matrix and
|
||||
two orthogonal/unitary matrices. The "Singular Value Decompostion
|
||||
(SVD) theorem":"https://en.wikipedia.org/wiki/Singular_value_decomposition"
|
||||
states that a general $m\times n$ matrix $\bm{X}$ can be written in
|
||||
terms of a diagonal matrix $\bm{\Sigma}$ of dimensionality $m\times n$
|
||||
and two orthognal matrices $\bm{U}$ and $\bm{V}$, where the first has
|
||||
dimensionality $m \times m$ and the last dimensionality $n\times n$.
|
||||
We have then
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \bm{U}\bm{\Sigma}\bm{V}^T
|
||||
\]
|
||||
!et
|
||||
|
||||
As an example, the above defective matrix can be decomposed as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \frac{1}{\sqrt{2}}\begin{bmatrix} 1& 1 \\ 1& -1\\ \end{bmatrix} \begin{bmatrix} 2& 0 \\ 0& 0\\ \end{bmatrix} \frac{1}{\sqrt{2}}\begin{bmatrix} 1& -1 \\ 1& 1\\ \end{bmatrix}=\bm{U}\bm{\Sigma}\bm{V}^T,
|
||||
\]
|
||||
!et
|
||||
|
||||
with eigenvalues $\sigma_1=2$ and $\sigma_2=0$.
|
||||
The SVD exits always!
|
||||
|
||||
The SVD
|
||||
decomposition (singular values) gives eigenvalues
|
||||
$\sigma_i\geq\sigma_{i+1}$ for all $i$ and for dimensions larger than $i=p$, the
|
||||
eigenvalues (singular values) are zero.
|
||||
|
||||
In the general case, where our design matrix $\bm{X}$ has dimension
|
||||
$n\times p$, the matrix is thus decomposed into an $n\times n$
|
||||
orthogonal matrix $\bm{U}$, a $p\times p$ orthogonal matrix $\bm{V}$
|
||||
and a diagonal matrix $\bm{\Sigma}$ with $r=\mathrm{min}(n,p)$
|
||||
singular values $\sigma_i\geq 0$ on the main diagonal and zeros filling
|
||||
the rest of the matrix. There are at most $p$ singular values
|
||||
assuming that $n > p$. In our regression examples for the nuclear
|
||||
masses and the equation of state this is indeed the case, while for
|
||||
the Ising model we have $p > n$. These are often cases that lead to
|
||||
near singular or singular matrices.
|
||||
|
||||
The columns of $\bm{U}$ are called the left singular vectors while the columns of $\bm{V}$ are the right singular vectors.
|
||||
|
||||
===== Economy-size SVD =====
|
||||
|
||||
If we assume that $n > p$, then our matrix $\bm{U}$ has dimension $n
|
||||
\times n$. The last $n-p$ columns of $\bm{U}$ become however
|
||||
irrelevant in our calculations since they are multiplied with the
|
||||
zeros in $\bm{\Sigma}$.
|
||||
|
||||
The economy-size decomposition removes extra rows or columns of zeros
|
||||
from the diagonal matrix of singular values, $\bm{\Sigma}$, along with the columns
|
||||
in either $\bm{U}$ or $\bm{V}$ that multiply those zeros in the expression.
|
||||
Removing these zeros and columns can improve execution time
|
||||
and reduce storage requirements without compromising the accuracy of
|
||||
the decomposition.
|
||||
|
||||
If $n > p$, we keep only the first $p$ columns of $\bm{U}$ and $\bm{\Sigma}$ has dimension $p\times p$.
|
||||
If $p > n$, then only the first $n$ columns of $\bm{V}$ are computed and $\bm{\Sigma}$ has dimension $n\times n$.
|
||||
The $n=p$ case is obvious, we retain the full SVD.
|
||||
In general the economy-size SVD leads to less FLOPS and still conserving the desired accuracy.
|
||||
|
||||
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
# SVD inversion
|
||||
def SVDinv(A):
|
||||
''' Takes as input a numpy matrix A and returns inv(A) based on singular value decomposition (SVD).
|
||||
SVD is numerically more stable than the inversion algorithms provided by
|
||||
numpy and scipy.linalg at the cost of being slower.
|
||||
'''
|
||||
U, s, VT = np.linalg.svd(A)
|
||||
# print('test U')
|
||||
# print( (np.transpose(U) @ U - U @np.transpose(U)))
|
||||
# print('test VT')
|
||||
# print( (np.transpose(VT) @ VT - VT @np.transpose(VT)))
|
||||
print(U)
|
||||
print(s)
|
||||
print(VT)
|
||||
|
||||
D = np.zeros((len(U),len(VT)))
|
||||
for i in range(0,len(VT)):
|
||||
D[i,i]=s[i]
|
||||
UT = np.transpose(U); V = np.transpose(VT); invD = np.linalg.inv(D)
|
||||
return np.matmul(V,np.matmul(invD,UT))
|
||||
|
||||
|
||||
X = np.array([ [1.0, -1.0, 2.0], [1.0, 0.0, 1.0], [1.0, 2.0, -1.0], [1.0, 1.0, 0.0] ])
|
||||
print(X)
|
||||
A = np.transpose(X) @ X
|
||||
print(A)
|
||||
# Brute force inversion of super-collinear matrix
|
||||
#B = np.linalg.inv(A)
|
||||
#print(B)
|
||||
C = SVDinv(A)
|
||||
print(C)
|
||||
|
||||
!ec
|
||||
|
||||
The matrix $\bm{X}$ has columns that are linearly dependent. The first
|
||||
column is the row-wise sum of the other two columns. The rank of a
|
||||
matrix (the column rank) is the dimension of space spanned by the
|
||||
column vectors. The rank of the matrix is the number of linearly
|
||||
independent columns, in this case just $2$. We see this from the
|
||||
singular values when running the above code. Running the standard
|
||||
inversion algorithm for matrix inversion with $\bm{X}^T\bm{X}$ results
|
||||
in the program terminating due to a singular matrix.
|
||||
|
||||
|
||||
|
||||
|
||||
There are several interesting mathematical properties which will be
|
||||
relevant when we are going to discuss the differences between say
|
||||
ordinary least squares (OLS) and _Ridge_ regression.
|
||||
|
||||
We have from OLS that the parameters of the linear approximation are given by
|
||||
!bt
|
||||
\[
|
||||
\bm{\tilde{y}} = \bm{X}\bm{\beta} = \bm{X}\left(\bm{X}^T\bm{X}\right)^{-1}\bm{X}^T\bm{y}.
|
||||
\]
|
||||
!et
|
||||
|
||||
The matrix to invert can be rewritten in terms of our SVD decomposition as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^T\bm{X} = \bm{V}\bm{\Sigma}^T\bm{U}^T\bm{U}\bm{\Sigma}\bm{V}^T.
|
||||
\]
|
||||
!et
|
||||
Using the orthogonality properties of $\bm{U}$ we have
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^T\bm{X} = \bm{V}\bm{\Sigma}^T\bm{\Sigma}\bm{V}^T = \bm{V}\bm{D}\bm{V}^T,
|
||||
\]
|
||||
!et
|
||||
with $\bm{D}$ being a diagonal matrix with values along the diagonal given by the singular values squared.
|
||||
|
||||
This means that
|
||||
!bt
|
||||
\[
|
||||
(\bm{X}^T\bm{X})\bm{V} = \bm{V}\bm{D},
|
||||
\]
|
||||
!et
|
||||
that is the eigenvectors of $(\bm{X}^T\bm{X})$ are given by the columns of the right singular matrix of $\bm{X}$ and the eigenvalues are the squared singular values. It is easy to show (show this) that
|
||||
!bt
|
||||
\[
|
||||
(\bm{X}\bm{X}^T)\bm{U} = \bm{U}\bm{D},
|
||||
\]
|
||||
!et
|
||||
that is, the eigenvectors of $(\bm{X}\bm{X})^T$ are the columns of the left singular matrix and the eigenvalues are the same.
|
||||
|
||||
Going back to our OLS equation we have
|
||||
!bt
|
||||
\[
|
||||
\bm{X}\bm{\beta} = \bm{X}\left(\bm{V}\bm{D}\bm{V}^T \right)^{-1}\bm{X}^T\bm{y}=\bm{U\Sigma V^T}\left(\bm{V}\bm{D}\bm{V}^T \right)^{-1}(\bm{U\Sigma V^T})^T\bm{y}=\bm{U}\bm{U}^T\bm{y}.
|
||||
\]
|
||||
!et
|
||||
We will come back to this expression when we discuss Ridge regression.
|
||||
|
||||
|
||||
$$ \tilde{y}^{OLS}={\bf X}\hat{\beta}^{OLS}=\sum_{j=1}^p {\bf u}_j{\bf u}_j^T{\bf y}$$ and for Ridge we have
|
||||
|
||||
$$ \tilde{y}^{Ridge}={\bf X}\hat{\beta}^{Ridge}=\sum_{j=1}^p {\bf u}_j\frac{\sigma_j^2}{\sigma_j^2+\lambda}{\bf u}_j^T{\bf y}$$ .
|
||||
|
||||
It is indeed the economy-sized SVD, note the summation runs up tp $$p$$ only and not $$n$$.
|
||||
|
||||
Here we have that $${\bf X} = {\bf U}{\bf \Sigma}{\bf V}^T$$, with $$\Sigma$$ being an $$ n\times p$$ matrix and $${\bf V}$$ being a $$ p\times p$$ matrix. We also have assumed here that $$ n > p$$.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
===== Ridge and LASSO Regression =====
|
||||
|
||||
"Video of Lecture":"https://www.uio.no/studier/emner/matnat/fys/FYS-STK4155/h20/forelesningsvideoer/LectureSeptember11.mp4?vrtx=view-as-webpage"
|
||||
|
||||
Let us remind ourselves about the expression for the standard Mean Squared Error (MSE) which we used to define our cost function and the equations for the ordinary least squares (OLS) method, that is
|
||||
our optimization problem is
|
||||
!bt
|
||||
\[
|
||||
{\displaystyle \min_{\bm{\beta}\in {\mathbb{R}}^{p}}}\frac{1}{n}\left\{\left(\bm{y}-\bm{X}\bm{\beta}\right)^T\left(\bm{y}-\bm{X}\bm{\beta}\right)\right\}.
|
||||
\]
|
||||
!et
|
||||
or we can state it as
|
||||
!bt
|
||||
\[
|
||||
{\displaystyle \min_{\bm{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\sum_{i=0}^{n-1}\left(y_i-\tilde{y}_i\right)^2=\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2,
|
||||
\]
|
||||
!et
|
||||
where we have used the definition of a norm-2 vector, that is
|
||||
!bt
|
||||
\[
|
||||
\vert\vert \bm{x}\vert\vert_2 = \sqrt{\sum_i x_i^2}.
|
||||
\]
|
||||
!et
|
||||
|
||||
By minimizing the above equation with respect to the parameters
|
||||
$\bm{\beta}$ we could then obtain an analytical expression for the
|
||||
parameters $\bm{\beta}$. We can add a regularization parameter $\lambda$ by
|
||||
defining a new cost function to be optimized, that is
|
||||
|
||||
!bt
|
||||
\[
|
||||
{\displaystyle \min_{\bm{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2+\lambda\vert\vert \bm{\beta}\vert\vert_2^2
|
||||
\]
|
||||
!et
|
||||
|
||||
which leads to the Ridge regression minimization problem where we
|
||||
require that $\vert\vert \bm{\beta}\vert\vert_2^2\le t$, where $t$ is
|
||||
a finite number larger than zero. By defining
|
||||
|
||||
!bt
|
||||
\[
|
||||
C(\bm{X},\bm{\beta})=\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2+\lambda\vert\vert \bm{\beta}\vert\vert_1,
|
||||
\]
|
||||
!et
|
||||
|
||||
we have a new optimization equation
|
||||
!bt
|
||||
\[
|
||||
{\displaystyle \min_{\bm{\beta}\in
|
||||
{\mathbb{R}}^{p}}}\frac{1}{n}\vert\vert \bm{y}-\bm{X}\bm{\beta}\vert\vert_2^2+\lambda\vert\vert \bm{\beta}\vert\vert_1
|
||||
\]
|
||||
!et
|
||||
which leads to Lasso regression. Lasso stands for least absolute shrinkage and selection operator.
|
||||
|
||||
Here we have defined the norm-1 as
|
||||
!bt
|
||||
\[
|
||||
\vert\vert \bm{x}\vert\vert_1 = \sum_i \vert x_i\vert.
|
||||
\]
|
||||
!et
|
||||
|
||||
|
||||
|
||||
Using the matrix-vector expression for Ridge regression,
|
||||
|
||||
!bt
|
||||
\[
|
||||
C(\bm{X},\bm{\beta})=\frac{1}{n}\left\{(\bm{y}-\bm{X}\bm{\beta})^T(\bm{y}-\bm{X}\bm{\beta})\right\}+\lambda\bm{\beta}^T\bm{\beta},
|
||||
\]
|
||||
!et
|
||||
|
||||
by taking the derivatives with respect to $\bm{\beta}$ we obtain then
|
||||
a slightly modified matrix inversion problem which for finite values
|
||||
of $\lambda$ does not suffer from singularity problems. We obtain
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{\beta}^{\mathrm{Ridge}} = \left(\bm{X}^T\bm{X}+\lambda\bm{I}\right)^{-1}\bm{X}^T\bm{y},
|
||||
\]
|
||||
!et
|
||||
|
||||
with $\bm{I}$ being a $p\times p$ identity matrix with the constraint that
|
||||
|
||||
!bt
|
||||
\[
|
||||
\sum_{i=0}^{p-1} \beta_i^2 \leq t,
|
||||
\]
|
||||
!et
|
||||
|
||||
with $t$ a finite positive number.
|
||||
|
||||
We see that Ridge regression is nothing but the standard
|
||||
OLS with a modified diagonal term added to $\bm{X}^T\bm{X}$. The
|
||||
consequences, in particular for our discussion of the bias-variance tradeoff
|
||||
are rather interesting.
|
||||
|
||||
Furthermore, if we use the result above in terms of the SVD decomposition (our analysis was done for the OLS method), we had
|
||||
!bt
|
||||
\[
|
||||
(\bm{X}\bm{X}^T)\bm{U} = \bm{U}\bm{D}.
|
||||
\]
|
||||
!et
|
||||
|
||||
We can analyse the OLS solutions in terms of the eigenvectors (the columns) of the right singular value matrix $\bm{U}$ as
|
||||
!bt
|
||||
\[
|
||||
\bm{X}\bm{\beta} = \bm{X}\left(\bm{V}\bm{D}\bm{V}^T \right)^{-1}\bm{X}^T\bm{y}=\bm{U\Sigma V^T}\left(\bm{V}\bm{D}\bm{V}^T \right)^{-1}(\bm{U\Sigma V^T})^T\bm{y}=\bm{U}\bm{U}^T\bm{y}
|
||||
\]
|
||||
!et
|
||||
|
||||
|
||||
For Ridge regression this becomes
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}\bm{\beta}^{\mathrm{Ridge}} = \bm{U\Sigma V^T}\left(\bm{V}\bm{D}\bm{V}^T+\lambda\bm{I} \right)^{-1}(\bm{U\Sigma V^T})^T\bm{y}=\sum_{j=0}^{p-1}\bm{u}_j\bm{u}_j^T\frac{\sigma_j^2}{\sigma_j^2+\lambda}\bm{y},
|
||||
\]
|
||||
!et
|
||||
|
||||
with the vectors $\bm{u}_j$ being the columns of $\bm{U}$.
|
||||
|
||||
|
||||
Since $\lambda \geq 0$, it means that compared to OLS, we have
|
||||
|
||||
!bt
|
||||
\[
|
||||
\frac{\sigma_j^2}{\sigma_j^2+\lambda} \leq 1.
|
||||
\]
|
||||
!et
|
||||
|
||||
Ridge regression finds the coordinates of $\bm{y}$ with respect to the
|
||||
orthonormal basis $\bm{U}$, it then shrinks the coordinates by
|
||||
$\frac{\sigma_j^2}{\sigma_j^2+\lambda}$. Recall that the SVD has
|
||||
eigenvalues ordered in a descending way, that is $\sigma_i \geq
|
||||
\sigma_{i+1}$.
|
||||
|
||||
For small eigenvalues $\sigma_i$ it means that their contributions become less important, a fact which can be used to reduce the number of degrees of freedom.
|
||||
Actually, calculating the variance of $\bm{X}\bm{v}_j$ shows that this quantity is equal to $\sigma_j^2/n$.
|
||||
With a parameter $\lambda$ we can thus shrink the role of specific parameters.
|
||||
|
||||
|
||||
|
||||
For the sake of simplicity, let us assume that the design matrix is orthonormal, that is
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}^T\bm{X}=(\bm{X}^T\bm{X})^{-1} =\bm{I}.
|
||||
\]
|
||||
!et
|
||||
|
||||
In this case the standard OLS results in
|
||||
!bt
|
||||
\[
|
||||
\bm{\beta}^{\mathrm{OLS}} = \bm{X}^T\bm{y}=\sum_{i=0}^{p-1}\bm{u}_j\bm{u}_j^T\bm{y},
|
||||
\]
|
||||
!et
|
||||
|
||||
and
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{\beta}^{\mathrm{Ridge}} = \left(\bm{I}+\lambda\bm{I}\right)^{-1}\bm{X}^T\bm{y}=\left(1+\lambda\right)^{-1}\bm{\beta}^{\mathrm{OLS}},
|
||||
\]
|
||||
!et
|
||||
|
||||
that is the Ridge estimator scales the OLS estimator by the inverse of a factor $1+\lambda$, and
|
||||
the Ridge estimator converges to zero when the hyperparameter goes to
|
||||
infinity.
|
||||
|
||||
We will come back to more interpreations after we have gone through some of the statistical analysis part.
|
||||
|
||||
For more discussions of Ridge and Lasso regression, "Wessel van Wieringen's":"https://arxiv.org/abs/1509.09169" article is highly recommended.
|
||||
Similarly, "Mehta et al's article":"https://arxiv.org/abs/1803.08823" is also recommended.
|
||||
|
||||
|
||||
|
||||
===== A better understanding of regularization =====
|
||||
|
||||
The parameter $\lambda$ that we have introduced in the Ridge (and
|
||||
Lasso as well) regression is often called a regularization parameter
|
||||
or shrinkage parameter. It is common to call it a hyperparameter. What does it mean mathemtically?
|
||||
|
||||
Here we will first look at how to analyze the difference between the
|
||||
standard OLS equations and the Ridge expressions in terms of a linear
|
||||
algebra analysis using the SVD algorithm. Thereafter, we will link
|
||||
(see the material on the bias-variance tradeoff below) these
|
||||
observation to the statisical analysis of the results. In particular
|
||||
we consider how the variance of the parameters $\bm{\beta}$ is
|
||||
affected by changing the parameter $\lambda$.
|
||||
|
||||
|
||||
We have our design matrix
|
||||
$\bm{X}\in {\mathbb{R}}^{n\times p}$. With the SVD we decompose it as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X} = \bm{U\Sigma V^T},
|
||||
\]
|
||||
!et
|
||||
|
||||
with $\bm{U}\in {\mathbb{R}}^{n\times n}$, $\bm{\Sigma}\in {\mathbb{R}}^{n\times p}$
|
||||
and $\bm{V}\in {\mathbb{R}}^{p\times p}$.
|
||||
|
||||
The matrices $\bm{U}$ and $\bm{V}$ are unitary/orthonormal matrices, that is in case the matrices are real we have $\bm{U}^T\bm{U}=\bm{U}\bm{U}^T=\bm{I}$ and $\bm{V}^T\bm{V}=\bm{V}\bm{V}^T=\bm{I}$.
|
||||
|
||||
|
||||
|
||||
===== Introducing the Covariance and Correlation functions =====
|
||||
|
||||
Before we discuss the link between for example Ridge regression and the singular value decomposition, we need to remind ourselves about
|
||||
the definition of the covariance and the correlation function. These are quantities
|
||||
|
||||
Suppose we have defined two vectors
|
||||
$\hat{x}$ and $\hat{y}$ with $n$ elements each. The covariance matrix $\bm{C}$ is defined as
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x},\bm{y}] = \begin{bmatrix} \mathrm{cov}[\bm{x},\bm{x}] & \mathrm{cov}[\bm{x},\bm{y}] \\
|
||||
\mathrm{cov}[\bm{y},\bm{x}] & \mathrm{cov}[\bm{y},\bm{y}] \\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
where for example
|
||||
!bt
|
||||
\[
|
||||
\mathrm{cov}[\bm{x},\bm{y}] =\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})(y_i- \overline{y}).
|
||||
\]
|
||||
!et
|
||||
With this definition and recalling that the variance is defined as
|
||||
!bt
|
||||
\[
|
||||
\mathrm{var}[\bm{x}]=\frac{1}{n} \sum_{i=0}^{n-1}(x_i- \overline{x})^2,
|
||||
\]
|
||||
!et
|
||||
we can rewrite the covariance matrix as
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x},\bm{y}] = \begin{bmatrix} \mathrm{var}[\bm{x}] & \mathrm{cov}[\bm{x},\bm{y}] \\
|
||||
\mathrm{cov}[\bm{x},\bm{y}] & \mathrm{var}[\bm{y}] \\
|
||||
\end{bmatrix}.
|
||||
\]
|
||||
!et
|
||||
|
||||
The covariance takes values between zero and infinity and may thus
|
||||
lead to problems with loss of numerical precision for particularly
|
||||
large values. It is common to scale the covariance matrix by
|
||||
introducing instead the correlation matrix defined via the so-called
|
||||
correlation function
|
||||
|
||||
!bt
|
||||
\[
|
||||
\mathrm{corr}[\bm{x},\bm{y}]=\frac{\mathrm{cov}[\bm{x},\bm{y}]}{\sqrt{\mathrm{var}[\bm{x}] \mathrm{var}[\bm{y}]}}.
|
||||
\]
|
||||
!et
|
||||
|
||||
The correlation function is then given by values $\mathrm{corr}[\bm{x},\bm{y}]
|
||||
\in [-1,1]$. This avoids eventual problems with too large values. We
|
||||
can then define the correlation matrix for the two vectors $\bm{x}$
|
||||
and $\bm{y}$ as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{K}[\bm{x},\bm{y}] = \begin{bmatrix} 1 & \mathrm{corr}[\bm{x},\bm{y}] \\
|
||||
\mathrm{corr}[\bm{y},\bm{x}] & 1 \\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
|
||||
In the above example this is the function we constructed using _pandas_.
|
||||
|
||||
|
||||
|
||||
In our derivation of the various regression algorithms like _Ordinary Least Squares_ or _Ridge regression_
|
||||
we defined the design/feature matrix $\bm{X}$ as
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{X}=\begin{bmatrix}
|
||||
x_{0,0} & x_{0,1} & x_{0,2}& \dots & \dots x_{0,p-1}\\
|
||||
x_{1,0} & x_{1,1} & x_{1,2}& \dots & \dots x_{1,p-1}\\
|
||||
x_{2,0} & x_{2,1} & x_{2,2}& \dots & \dots x_{2,p-1}\\
|
||||
\dots & \dots & \dots & \dots \dots & \dots \\
|
||||
x_{n-2,0} & x_{n-2,1} & x_{n-2,2}& \dots & \dots x_{n-2,p-1}\\
|
||||
x_{n-1,0} & x_{n-1,1} & x_{n-1,2}& \dots & \dots x_{n-1,p-1}\\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
with $\bm{X}\in {\mathbb{R}}^{n\times p}$, with the predictors/features $p$ refering to the column numbers and the
|
||||
entries $n$ being the row elements.
|
||||
We can rewrite the design/feature matrix in terms of its column vectors as
|
||||
!bt
|
||||
\[
|
||||
\bm{X}=\begin{bmatrix} \bm{x}_0 & \bm{x}_1 & \bm{x}_2 & \dots & \dots & \bm{x}_{p-1}\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
with a given vector
|
||||
!bt
|
||||
\[
|
||||
\bm{x}_i^T = \begin{bmatrix}x_{0,i} & x_{1,i} & x_{2,i}& \dots & \dots x_{n-1,i}\end{bmatrix}.
|
||||
\]
|
||||
!et
|
||||
|
||||
With these definitions, we can now rewrite our $2\times 2$
|
||||
correaltion/covariance matrix in terms of a moe general design/feature
|
||||
matrix $\bm{X}\in {\mathbb{R}}^{n\times p}$. This leads to a $p\times p$
|
||||
covariance matrix for the vectors $\bm{x}_i$ with $i=0,1,\dots,p-1$
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x}] = \begin{bmatrix}
|
||||
\mathrm{var}[\bm{x}_0] & \mathrm{cov}[\bm{x}_0,\bm{x}_1] & \mathrm{cov}[\bm{x}_0,\bm{x}_2] & \dots & \dots & \mathrm{cov}[\bm{x}_0,\bm{x}_{p-1}]\\
|
||||
\mathrm{cov}[\bm{x}_1,\bm{x}_0] & \mathrm{var}[\bm{x}_1] & \mathrm{cov}[\bm{x}_1,\bm{x}_2] & \dots & \dots & \mathrm{cov}[\bm{x}_1,\bm{x}_{p-1}]\\
|
||||
\mathrm{cov}[\bm{x}_2,\bm{x}_0] & \mathrm{cov}[\bm{x}_2,\bm{x}_1] & \mathrm{var}[\bm{x}_2] & \dots & \dots & \mathrm{cov}[\bm{x}_2,\bm{x}_{p-1}]\\
|
||||
\dots & \dots & \dots & \dots & \dots & \dots \\
|
||||
\dots & \dots & \dots & \dots & \dots & \dots \\
|
||||
\mathrm{cov}[\bm{x}_{p-1},\bm{x}_0] & \mathrm{cov}[\bm{x}_{p-1},\bm{x}_1] & \mathrm{cov}[\bm{x}_{p-1},\bm{x}_{2}] & \dots & \dots & \mathrm{var}[\bm{x}_{p-1}]\\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
and the correlation matrix
|
||||
!bt
|
||||
\[
|
||||
\bm{K}[\bm{x}] = \begin{bmatrix}
|
||||
1 & \mathrm{corr}[\bm{x}_0,\bm{x}_1] & \mathrm{corr}[\bm{x}_0,\bm{x}_2] & \dots & \dots & \mathrm{corr}[\bm{x}_0,\bm{x}_{p-1}]\\
|
||||
\mathrm{corr}[\bm{x}_1,\bm{x}_0] & 1 & \mathrm{corr}[\bm{x}_1,\bm{x}_2] & \dots & \dots & \mathrm{corr}[\bm{x}_1,\bm{x}_{p-1}]\\
|
||||
\mathrm{corr}[\bm{x}_2,\bm{x}_0] & \mathrm{corr}[\bm{x}_2,\bm{x}_1] & 1 & \dots & \dots & \mathrm{corr}[\bm{x}_2,\bm{x}_{p-1}]\\
|
||||
\dots & \dots & \dots & \dots & \dots & \dots \\
|
||||
\dots & \dots & \dots & \dots & \dots & \dots \\
|
||||
\mathrm{corr}[\bm{x}_{p-1},\bm{x}_0] & \mathrm{corr}[\bm{x}_{p-1},\bm{x}_1] & \mathrm{corr}[\bm{x}_{p-1},\bm{x}_{2}] & \dots & \dots & 1\\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
|
||||
|
||||
|
||||
The Numpy function _np.cov_ calculates the covariance elements using
|
||||
the factor $1/(n-1)$ instead of $1/n$ since it assumes we do not have
|
||||
the exact mean values. The following simple function uses the
|
||||
_np.vstack_ function which takes each vector of dimension $1\times n$
|
||||
and produces a $2\times n$ matrix $\bm{W}$
|
||||
|
||||
|
||||
!bt
|
||||
\[
|
||||
\bm{W} = \begin{bmatrix} x_0 & y_0 \\
|
||||
x_1 & y_1 \\
|
||||
x_2 & y_2\\
|
||||
\dots & \dots \\
|
||||
x_{n-2} & y_{n-2}\\
|
||||
x_{n-1} & y_{n-1} &
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
|
||||
which in turn is converted into into the $2\times 2$ covariance matrix
|
||||
$\bm{C}$ via the Numpy function _np.cov()_. We note that we can also calculate
|
||||
the mean value of each set of samples $\bm{x}$ etc using the Numpy
|
||||
function _np.mean(x)_. We can also extract the eigenvalues of the
|
||||
covariance matrix through the _np.linalg.eig()_ function.
|
||||
|
||||
!bc pycod
|
||||
# Importing various packages
|
||||
import numpy as np
|
||||
n = 100
|
||||
x = np.random.normal(size=n)
|
||||
print(np.mean(x))
|
||||
y = 4+3*x+np.random.normal(size=n)
|
||||
print(np.mean(y))
|
||||
W = np.vstack((x, y))
|
||||
C = np.cov(W)
|
||||
print(C)
|
||||
!ec
|
||||
|
||||
|
||||
The previous example can be converted into the correlation matrix by
|
||||
simply scaling the matrix elements with the variances. We should also
|
||||
subtract the mean values for each column. This leads to the following
|
||||
code which sets up the correlations matrix for the previous example in
|
||||
a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the $2\times 2$ correlation matrix (since we have only two vectors).
|
||||
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
n = 100
|
||||
# define two vectors
|
||||
x = np.random.random(size=n)
|
||||
y = 4+3*x+np.random.normal(size=n)
|
||||
#scaling the x and y vectors
|
||||
x = x - np.mean(x)
|
||||
y = y - np.mean(y)
|
||||
variance_x = np.sum(x@x)/n
|
||||
variance_y = np.sum(y@y)/n
|
||||
print(variance_x)
|
||||
print(variance_y)
|
||||
cov_xy = np.sum(x@y)/n
|
||||
cov_xx = np.sum(x@x)/n
|
||||
cov_yy = np.sum(y@y)/n
|
||||
C = np.zeros((2,2))
|
||||
C[0,0]= cov_xx/variance_x
|
||||
C[1,1]= cov_yy/variance_y
|
||||
C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)
|
||||
C[1,0]= C[0,1]
|
||||
print(C)
|
||||
!ec
|
||||
|
||||
We see that the matrix elements along the diagonal are one as they
|
||||
should be and that the matrix is symmetric. Furthermore, diagonalizing
|
||||
this matrix we easily see that it is a positive definite matrix.
|
||||
|
||||
The above procedure with _numpy_ can be made more compact if we use _pandas_.
|
||||
|
||||
|
||||
We whow here how we can set up the correlation matrix using _pandas_, as done in this simple code
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
n = 10
|
||||
x = np.random.normal(size=n)
|
||||
x = x - np.mean(x)
|
||||
y = 4+3*x+np.random.normal(size=n)
|
||||
y = y - np.mean(y)
|
||||
X = (np.vstack((x, y))).T
|
||||
print(X)
|
||||
Xpd = pd.DataFrame(X)
|
||||
print(Xpd)
|
||||
correlation_matrix = Xpd.corr()
|
||||
print(correlation_matrix)
|
||||
!ec
|
||||
|
||||
|
||||
We expand this model to the Franke function discussed above.
|
||||
|
||||
|
||||
|
||||
!bc pycod
|
||||
# Common imports
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def FrankeFunction(x,y):
|
||||
term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
|
||||
term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
|
||||
term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
|
||||
term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
|
||||
return term1 + term2 + term3 + term4
|
||||
|
||||
|
||||
def create_X(x, y, n ):
|
||||
if len(x.shape) > 1:
|
||||
x = np.ravel(x)
|
||||
y = np.ravel(y)
|
||||
|
||||
N = len(x)
|
||||
l = int((n+1)*(n+2)/2) # Number of elements in beta
|
||||
X = np.ones((N,l))
|
||||
|
||||
for i in range(1,n+1):
|
||||
q = int((i)*(i+1)/2)
|
||||
for k in range(i+1):
|
||||
X[:,q+k] = (x**(i-k))*(y**k)
|
||||
|
||||
return X
|
||||
|
||||
|
||||
# Making meshgrid of datapoints and compute Franke's function
|
||||
n = 4
|
||||
N = 100
|
||||
x = np.sort(np.random.uniform(0, 1, N))
|
||||
y = np.sort(np.random.uniform(0, 1, N))
|
||||
z = FrankeFunction(x, y)
|
||||
X = create_X(x, y, n=n)
|
||||
|
||||
Xpd = pd.DataFrame(X)
|
||||
# subtract the mean values and set up the covariance matrix
|
||||
Xpd = Xpd - Xpd.mean()
|
||||
covariance_matrix = Xpd.cov()
|
||||
print(covariance_matrix)
|
||||
!ec
|
||||
|
||||
We note here that the covariance is zero for the first rows and
|
||||
columns since all matrix elements in the design matrix were set to one
|
||||
(we are fitting the function in terms of a polynomial of degree $n$).
|
||||
|
||||
This means that the variance for these elements will be zero and will
|
||||
cause problems when we set up the correlation matrix. We can simply
|
||||
drop these elements and construct a correlation
|
||||
matrix without these elements.
|
||||
|
||||
|
||||
|
||||
|
||||
We can rewrite the covariance matrix in a more compact form in terms of the design/feature matrix $\bm{X}$ as
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x}] = \frac{1}{n}\bm{X}^T\bm{X}= \mathbb{E}[\bm{X}^T\bm{X}].
|
||||
\]
|
||||
!et
|
||||
|
||||
To see this let us simply look at a design matrix $\bm{X}\in {\mathbb{R}}^{2\times 2}$
|
||||
!bt
|
||||
\[
|
||||
\bm{X}=\begin{bmatrix}
|
||||
x_{00} & x_{01}\\
|
||||
x_{10} & x_{11}\\
|
||||
\end{bmatrix}=\begin{bmatrix}
|
||||
\bm{x}_{0} & \bm{x}_{1}\\
|
||||
\end{bmatrix}.
|
||||
\]
|
||||
!et
|
||||
|
||||
If we then compute the expectation value
|
||||
!bt
|
||||
\[
|
||||
\mathbb{E}[\bm{X}^T\bm{X}] = \frac{1}{n}\bm{X}^T\bm{X}=\begin{bmatrix}
|
||||
x_{00}^2+x_{01}^2 & x_{00}x_{10}+x_{01}x_{11}\\
|
||||
x_{10}x_{00}+x_{11}x_{01} & x_{10}^2+x_{11}^2\\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
which is just
|
||||
!bt
|
||||
\[
|
||||
\bm{C}[\bm{x}_0,\bm{x}_1] = \bm{C}[\bm{x}]=\begin{bmatrix} \mathrm{var}[\bm{x}_0] & \mathrm{cov}[\bm{x}_0,\bm{x}_1] \\
|
||||
\mathrm{cov}[\bm{x}_1,\bm{x}_0] & \mathrm{var}[\bm{x}_1] \\
|
||||
\end{bmatrix},
|
||||
\]
|
||||
!et
|
||||
where we wrote $$\bm{C}[\bm{x}_0,\bm{x}_1] = \bm{C}[\bm{x}]$$ to indicate that this the covariance of the vectors $\bm{x}$ of the design/feature matrix $\bm{X}$.
|
||||
|
||||
It is easy to generalize this to a matrix $\bm{X}\in {\mathbb{R}}^{n\times p}$.
|
||||
|
||||
|
||||
===== Linking with SVD =====
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
*** error: file has a mako construction ${\bf \bm{J}'
|
||||
but seemingly no definition in <%...%>'
|
||||
(it is not a command-line given mako variable either).
|
||||
However, if this is a variable in a Makefile or Bash script
|
||||
run with --no_mako - and you cannot use mako and Makefile or Bash variables
|
||||
in the same document!
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Vendored
BIN
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Reference in New Issue
Block a user