{"id":1843,"date":"2024-06-25T19:28:53","date_gmt":"2024-06-25T19:28:53","guid":{"rendered":"https:\/\/www.ethanepperly.com\/?p=1843"},"modified":"2024-06-28T22:00:41","modified_gmt":"2024-06-28T22:00:41","slug":"neat-randomized-algorithms-randomized-cholesky-qr","status":"publish","type":"post","link":"https:\/\/www.ethanepperly.com\/index.php\/2024\/06\/25\/neat-randomized-algorithms-randomized-cholesky-qr\/","title":{"rendered":"Neat Randomized Algorithms: Randomized Cholesky QR"},"content":{"rendered":"\n<p><em>As a research area, randomized numerical linear algebra (RNLA) is as hot as ever. To celebrate the exciting work in this space, I&#8217;m starting a new series on my blog where I celebrate cool recent algorithms in the area. At some future point, I might talk about my own work in this series, but for now I&#8217;m hoping to use this series to highlight some of the awesome work being done by my colleagues.<\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>Given a tall matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e81c38fa599438625bed14b552fa0283_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#109;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#110;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"79\" style=\"vertical-align: -1px;\"\/> with <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-f209d489cf55da3b932170cf2ab3ff33_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#109;&#92;&#103;&#101;&#32;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"50\" style=\"vertical-align: -3px;\"\/>, its (<a href=\"https:\/\/en.wikipedia.org\/wiki\/QR_decomposition#Rectangular_matrix\">economy-size<\/a>) <a href=\"https:\/\/en.wikipedia.org\/wiki\/QR_decomposition\">QR factorization<\/a> is a decomposition of the form <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3c26c2e14b53fed06932cc32c29d3bb5_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#32;&#61;&#32;&#81;&#82;\" title=\"Rendered by QuickLaTeX.com\" height=\"17\" width=\"65\" style=\"vertical-align: -4px;\"\/>, where <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-053c97f8d5f227895b67f3f762ad8f12_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#109;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#110;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"17\" width=\"80\" style=\"vertical-align: -4px;\"\/> is a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Orthonormal_matrix\">matrix with orthonormal columns<\/a> and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5bc95bfb4164295542d26c4ab62e94e1_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#82;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#110;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#110;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"75\" style=\"vertical-align: -1px;\"\/> is <a href=\"https:\/\/en.wikipedia.org\/wiki\/Triangular_matrix\">upper triangular<\/a>. QR factorizations are used to <a href=\"https:\/\/johnwlambert.github.io\/least-squares\/\">solve least-squares problems<\/a> and as a computational procedure to orthonormalize the columns of a matrix.<\/p>\n\n\n\n<p>Here&#8217;s an example in MATLAB, where we use QR factorization to orthonormalize the columns of a <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-bd14b6719312a0c320311398e4fd0bca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;&#48;&#94;&#54;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#49;&#48;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"71\" style=\"vertical-align: 0px;\"\/> test matrix. It takes about 2.5 seconds to run.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt; A = randn(1e6, 1e2) * randn(1e2) * randn(1e2); <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">% test matrix<\/mark>\n&gt;&gt; tic; &#091;Q,R] = qr(A,\"econ\"); toc\nElapsed time is 2.647317 seconds.<\/code><\/pre>\n\n\n\n<p>The <a href=\"https:\/\/en.wikipedia.org\/wiki\/QR_decomposition#Using_Householder_reflections\">classical algorithm<\/a> for computing a QR factorization uses <a href=\"https:\/\/en.wikipedia.org\/wiki\/Householder_reflection\">Householder reflectors<\/a> and is exceptionally numerically stable. Since <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e7f252699e1616398a7ce5179d3e425e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"14\" style=\"vertical-align: -4px;\"\/> has orthonormal columns, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c2027d18e5c4de036513eb465647de0d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;&#94;&#92;&#116;&#111;&#112;&#32;&#81;&#32;&#61;&#32;&#73;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"72\" style=\"vertical-align: -4px;\"\/> is the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Identity_matrix\">identity matrix<\/a>. Indeed, this relation holds up to a tiny error for the <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e7f252699e1616398a7ce5179d3e425e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"14\" style=\"vertical-align: -4px;\"\/> computed by Householder QR:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt; norm(Q'*Q - eye(1e2)) <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">% || Q^T Q - I ||<\/mark>\nans =\n   7.0396e-14<\/code><\/pre>\n\n\n\n<p>The relative error <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-442edd8725c5869a8c6f2401713da440_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#124;&#65;&#32;&#45;&#32;&#81;&#82;&#92;&#124;&#47;&#92;&#124;&#65;&#92;&#124;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"116\" style=\"vertical-align: -5px;\"\/> is also small:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>>> norm(A - Q*R) \/ norm(A)\nans =\n   4.8981e-14<\/code><\/pre>\n\n\n\n<p>Here is an alternate procedure for computing a QR factorization, known as Cholesky QR:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function &#091;Q,R] = cholesky_qr(A)\n   R = chol(A'*A);\n   Q = A \/ R;       <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">% Q = A * R^{-1}<\/mark>\nend<\/code><\/pre>\n\n\n\n<p>This algorithm works by forming <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-841e32306afba64e7ef539a005755747_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#94;&#92;&#116;&#111;&#112;&#32;&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"38\" style=\"vertical-align: 0px;\"\/>, computing its (upper triangular) <a href=\"https:\/\/en.wikipedia.org\/wiki\/Cholesky_decomposition\">Cholesky decomposition<\/a> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-eb37a78cff25185c4603f1455df5dcfa_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#94;&#92;&#116;&#111;&#112;&#32;&#65;&#32;&#61;&#32;&#82;&#94;&#92;&#116;&#111;&#112;&#32;&#82;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"101\" style=\"vertical-align: 0px;\"\/>, and setting <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-d4f3a580b922090b917b075717143375_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;&#32;&#61;&#32;&#65;&#82;&#94;&#123;&#45;&#49;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"82\" style=\"vertical-align: -4px;\"\/>. Cholesky QR is very fast, about <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-484b85355027e98122fe0ab025a405ae_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#53;&#92;&#116;&#105;&#109;&#101;&#115;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"21\" style=\"vertical-align: 0px;\"\/> faster than Householder QR for this example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt; tic; &#091;Q,R] = cholesky_qr(A); toc\nElapsed time is 0.536694 seconds.<\/code><\/pre>\n\n\n\n<p>Unfortunately, Cholesky QR is much less accurate and numerically stable than Householder QR. Here, for instance, is the value of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-15075333539db648bf8e2fbf8139f5e1_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#124;&#81;&#94;&#92;&#116;&#111;&#112;&#32;&#81;&#32;&#45;&#32;&#73;&#92;&#124;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"84\" style=\"vertical-align: -5px;\"\/>, about ten million times larger than for Householder QR!:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt; norm(Q'*Q - eye(1e2))\nans =\n   7.5929e-07<\/code><\/pre>\n\n\n\n<p>What&#8217;s going on? As we&#8217;ve discussed <a href=\"https:\/\/www.ethanepperly.com\/index.php\/2022\/07\/26\/dont-solve-the-normal-equations\/\">before<\/a> <a href=\"https:\/\/www.ethanepperly.com\/index.php\/2021\/03\/18\/the-better-way-to-convert-an-svd-into-a-symmetric-eigenvalue-problem\/\">on this blog<\/a>, forming <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-841e32306afba64e7ef539a005755747_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#94;&#92;&#116;&#111;&#112;&#32;&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"38\" style=\"vertical-align: 0px;\"\/> <a href=\"https:\/\/nhigham.com\/2022\/10\/11\/seven-sins-of-numerical-linear-algebra\/\">is typically problematic in linear algebraic computations<\/a>. The &#8220;badness&#8221; of a matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-11f4f587954b361e7d78940f65b8d70d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"13\" style=\"vertical-align: 0px;\"\/> is measured by its <em><a href=\"https:\/\/en.wikipedia.org\/wiki\/Condition_number#Matrices\">condition number<\/a><\/em>, defined to be the ratio of its largest and smallest <a href=\"https:\/\/en.wikipedia.org\/wiki\/Singular_value\">singular values<\/a> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3f768ccac1473e43294da02289e25316_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#107;&#97;&#112;&#112;&#97;&#40;&#65;&#41;&#32;&#61;&#32;&#92;&#115;&#105;&#103;&#109;&#97;&#95;&#123;&#92;&#114;&#109;&#32;&#109;&#97;&#120;&#125;&#40;&#65;&#41;&#47;&#92;&#115;&#105;&#103;&#109;&#97;&#95;&#123;&#92;&#114;&#109;&#32;&#109;&#105;&#110;&#125;&#40;&#65;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"193\" style=\"vertical-align: -5px;\"\/>. The condition number of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-841e32306afba64e7ef539a005755747_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#94;&#92;&#116;&#111;&#112;&#32;&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"38\" style=\"vertical-align: 0px;\"\/> is the square of the condition number of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-11f4f587954b361e7d78940f65b8d70d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"13\" style=\"vertical-align: 0px;\"\/>, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-628c75fa15fa4ac5bfa1d042900f4042_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#107;&#97;&#112;&#112;&#97;&#40;&#65;&#94;&#92;&#116;&#111;&#112;&#32;&#65;&#41;&#32;&#61;&#32;&#92;&#107;&#97;&#112;&#112;&#97;&#40;&#65;&#41;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"130\" style=\"vertical-align: -5px;\"\/>, which is at the root of Cholesky QR&#8217;s loss of accuracy. Thus, Cholesky QR is only appropriate for matrices that are <em>well-conditioned<\/em>, having a small condition number <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-757718b83213409b723f2e2e6b9b9809_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#107;&#97;&#112;&#112;&#97;&#40;&#65;&#41;&#32;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"69\" style=\"vertical-align: -5px;\"\/>, say <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-a91ca510336d52fb9077ad0d5ebff2d1_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#107;&#97;&#112;&#112;&#97;&#40;&#65;&#41;&#32;&#92;&#108;&#101;&#32;&#49;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"79\" style=\"vertical-align: -5px;\"\/>.<\/p>\n\n\n\n<p>The idea of <strong>randomized Cholesky QR<\/strong> is to use randomness to <em><a href=\"https:\/\/en.wikipedia.org\/wiki\/Preconditioner\">precondition<\/a><\/em> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-11f4f587954b361e7d78940f65b8d70d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"13\" style=\"vertical-align: 0px;\"\/>, producing a matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-cd8637c06848e628eb23a8bcc681e2c3_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#82;&#95;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"19\" style=\"vertical-align: -3px;\"\/> that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b1109a750dc6dff798968106dca647f7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#66;&#32;&#61;&#32;&#65;&#82;&#95;&#49;&#94;&#123;&#45;&#49;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"21\" width=\"82\" style=\"vertical-align: -5px;\"\/> is well-conditioned. Then, since <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-06d2c1a5a171b6d7d9c5df87d123c5a4_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#66;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/> is well-conditioned, we can apply ordinary Cholesky QR to it without issue. Here are the steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Draw a sketching matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b89471a11dd7fd85184a38ddb3ea9145_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"12\" style=\"vertical-align: 0px;\"\/> of size <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-7ea5e84ee47df84d5a5a0286720c8c2b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#50;&#110;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#109;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"56\" style=\"vertical-align: 0px;\"\/>; see <a href=\"https:\/\/www.ethanepperly.com\/index.php\/2023\/11\/13\/does-sketching-work\/\">these<\/a> <a href=\"https:\/\/www.ethanepperly.com\/index.php\/2023\/11\/27\/which-sketch-should-i-use\/\">posts<\/a> of mine for an introduction to sketching.<\/li>\n\n\n\n<li>Form the sketch <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-f6b6ffdfa7888fa001ee9e26544c7384_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"25\" style=\"vertical-align: 0px;\"\/>. This step compresses the very tall matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-7c060ad3084ad1de4a3ce67946c1e82a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#109;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"9\" width=\"48\" style=\"vertical-align: 0px;\"\/> to the much shorter matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-f6b6ffdfa7888fa001ee9e26544c7384_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"25\" style=\"vertical-align: 0px;\"\/> of size <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5d85fec68bf7a09135fb7a60523a04dd_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#50;&#110;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"52\" style=\"vertical-align: 0px;\"\/>.<\/li>\n\n\n\n<li>Compute a QR factorization <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b3af250525d9fa366fd668e53e608e6d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#65;&#32;&#61;&#32;&#81;&#95;&#49;&#82;&#95;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"17\" width=\"90\" style=\"vertical-align: -4px;\"\/> using Householder QR. Since the matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-f6b6ffdfa7888fa001ee9e26544c7384_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"25\" style=\"vertical-align: 0px;\"\/> is small, this factorization will be quick to compute.<\/li>\n\n\n\n<li>Form the preconditioned matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b1109a750dc6dff798968106dca647f7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#66;&#32;&#61;&#32;&#65;&#82;&#95;&#49;&#94;&#123;&#45;&#49;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"21\" width=\"82\" style=\"vertical-align: -5px;\"\/>.<\/li>\n\n\n\n<li>Apply Cholesky QR to <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-06d2c1a5a171b6d7d9c5df87d123c5a4_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#66;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/> to compute <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-8b3d893604de838872643042324cc971_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#66;&#32;&#61;&#32;&#81;&#82;&#95;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"72\" style=\"vertical-align: -4px;\"\/>.<\/li>\n\n\n\n<li>Set <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c5045a5a02f7a1bf2a011c39194d990a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#82;&#32;&#61;&#32;&#82;&#95;&#50;&#82;&#95;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"77\" style=\"vertical-align: -3px;\"\/>. Observe that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-f565851a34db033d1c4b1f1ebe434b8b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#32;&#61;&#32;&#66;&#82;&#95;&#49;&#32;&#61;&#32;&#81;&#82;&#95;&#50;&#82;&#95;&#49;&#32;&#61;&#32;&#81;&#82;\" title=\"Rendered by QuickLaTeX.com\" height=\"17\" width=\"204\" style=\"vertical-align: -4px;\"\/>, as desired.<\/li>\n<\/ol>\n\n\n\n<p>MATLAB code for randomized Cholesky QR is provided below:<sup class=\"modern-footnotes-footnote \" data-mfn=\"1\" data-mfn-post-scope=\"000000000000057f0000000000000000_1843\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057f0000000000000000_1843-1\">1<\/a><\/sup><span id=\"mfn-content-000000000000057f0000000000000000_1843-1\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"1\">Code for the sparsesign subroutine can be found <a href=\"https:\/\/github.com\/eepperly\/Iterative-Sketching-Is-Stable\/blob\/main\/code\/sparsesign.c\">here<\/a>.<\/span>\n\n\n\n<pre class=\"wp-block-code\"><code>function &#091;Q,R] = rand_cholesky_qr(A)\n   S = sparsesign(2*size(A,2),size(A,1),8); <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">% sparse sign embedding<\/mark>\n   R1 = qr(S*A,\"econ\"); <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">% sketch and (Householder) QR factorize<\/mark>\n   B = A \/ R1; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">% B = A * R_1^{-1}<\/mark>\n   &#091;Q,R2] = cholesky_qr(B);\n   R = R2*R1;\nend<\/code><\/pre>\n\n\n\n<p>Randomized Cholesky QR is still faster than ordinary Householder QR, about <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-ce69880b0fdb2479927a99449a90453a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#51;&#92;&#116;&#105;&#109;&#101;&#115;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"21\" style=\"vertical-align: 0px;\"\/> faster in our experiment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt; tic; &#091;Q,R] = rand_cholesky_qr(A); toc\nElapsed time is 0.920787 seconds.<\/code><\/pre>\n\n\n\n<p>Randomized Cholesky QR greatly improves on ordinary Cholesky QR in terms of accuracy and numerical stability. In fact, the size of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-15075333539db648bf8e2fbf8139f5e1_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#124;&#81;&#94;&#92;&#116;&#111;&#112;&#32;&#81;&#32;&#45;&#32;&#73;&#92;&#124;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"84\" style=\"vertical-align: -5px;\"\/> is even smaller than for Householder QR!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&gt;&gt; norm(Q'*Q - eye(1e2))\nans =\n   1.0926e-14<\/code><\/pre>\n\n\n\n<p>The relative error <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-442edd8725c5869a8c6f2401713da440_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#124;&#65;&#32;&#45;&#32;&#81;&#82;&#92;&#124;&#47;&#92;&#124;&#65;&#92;&#124;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"116\" style=\"vertical-align: -5px;\"\/> is small, too! Even smaller than for Householder QR in fact:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>>> norm(A - Q*R) \/ norm(A)\nans =\n   4.0007e-16<\/code><\/pre>\n\n\n\n<p>Like many great ideas, randomized Cholesky QR was developed independently by a number of research groups. A version of this algorithm was first introduced in 2021 by <a href=\"https:\/\/arxiv.org\/abs\/2111.11148\">Fan, Guo, and Lin<\/a>. Similar algorithms were investigated in 2022 and 2023 by <a href=\"https:\/\/arxiv.org\/abs\/2210.09953\">Balabanov<\/a>, <a href=\"https:\/\/arxiv.org\/abs\/2309.05868\">Higgins et al.<\/a>, and <a href=\"https:\/\/arxiv.org\/abs\/2311.08316\">Melnichenko et al.<\/a> Check out <a href=\"https:\/\/arxiv.org\/abs\/2311.08316\">Melnichenko et al.<\/a>&#8216;s paper in particular, which shows very impressive results for using randomized Cholesky QR to compute <a href=\"https:\/\/en.wikipedia.org\/wiki\/QR_decomposition#Column_pivoting\"><em>column pivoted<\/em> QR factorizations<\/a>.<\/p>\n\n\n\n<p><strong>References: <\/strong>Primary references are <em><a href=\"https:\/\/arxiv.org\/abs\/2111.11148\">A Novel Randomized XR-Based Preconditioned CholeskyQR Algorithm<\/a><\/em> by Fan, Guo, and Lin (2021); <em><a href=\"https:\/\/arxiv.org\/abs\/2210.09953\">Randomized Cholesky QR factorizations<\/a><\/em> by Balabanov (2022); <em><a href=\"https:\/\/arxiv.org\/abs\/2309.05868\">Analysis of Randomized Householder-Cholesky QR Factorization with Multisketching<\/a><\/em> by Higgins et al. (2023); <em><a href=\"https:\/\/arxiv.org\/abs\/2311.08316\">CholeskyQR with Randomization and Pivoting for Tall Matrices (CQRRPT)<\/a><\/em> by Melnichenko et al. (2023). The idea of using sketching to precondition tall matrices originates in the paper <em><a href=\"https:\/\/www.pnas.org\/doi\/full\/10.1073\/pnas.0804869105\">A fast randomized algorithm for overdetermined linear least-squares regression<\/a><\/em> by Rokhlin and Tygert (2008).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a research area, randomized numerical linear algebra (RNLA) is as hot as ever. To celebrate the exciting work in this space, I&#8217;m starting a new series on my blog where I celebrate cool recent algorithms in the area. At some future point, I might talk about my own work in this series, but for<a class=\"more-link\" href=\"https:\/\/www.ethanepperly.com\/index.php\/2024\/06\/25\/neat-randomized-algorithms-randomized-cholesky-qr\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,15,12],"tags":[],"class_list":["post-1843","post","type-post","status-publish","format-standard","hentry","category-expository","category-neat-randomized-algorithms","category-sketching"],"_links":{"self":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts\/1843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/comments?post=1843"}],"version-history":[{"count":10,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts\/1843\/revisions"}],"predecessor-version":[{"id":1867,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts\/1843\/revisions\/1867"}],"wp:attachment":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/media?parent=1843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/categories?post=1843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/tags?post=1843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}