{"id":1668,"date":"2023-11-27T17:09:04","date_gmt":"2023-11-27T17:09:04","guid":{"rendered":"https:\/\/www.ethanepperly.com\/?p=1668"},"modified":"2024-02-13T20:09:44","modified_gmt":"2024-02-13T20:09:44","slug":"which-sketch-should-i-use","status":"publish","type":"post","link":"https:\/\/www.ethanepperly.com\/index.php\/2023\/11\/27\/which-sketch-should-i-use\/","title":{"rendered":"Which Sketch Should I Use?"},"content":{"rendered":"\n<p>This is the second of a sequence of two posts on sketching, which I&#8217;m doing on the occasion of <a href=\"https:\/\/arxiv.org\/abs\/2311.04362\">my new paper<\/a> on the <a href=\"https:\/\/nhigham.com\/2020\/08\/04\/what-is-numerical-stability\/\">numerical stability<\/a> of the <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S10.SS4\">iterative sketching method<\/a>. For more on what sketching is and how it can be used to solve computational problems, I encourage you to check out the <a href=\"https:\/\/www.ethanepperly.com\/index.php\/2023\/11\/13\/does-sketching-work\/\">first post<\/a>.<\/p>\n\n\n\n<p>The goals of this post are more narrow. I seek to answer the question:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Which sketching matrix should I use?<\/p>\n<\/blockquote>\n\n\n\n<p>To cut to the chase, my answer to this question is:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S9.SS2\">Sparse sign embeddings<\/a> are a sensible default for sketching.<\/p>\n<\/blockquote>\n\n\n\n<p>There are certainly cases when sparse sign embeddings are not the best type of sketch to use, but I hope to convince you that they&#8217;re a good sketching matrix to use for most purposes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"experiments\">Experiments<\/h2>\n\n\n\n<p>Let&#8217;s start things off with some numerical experiments.<sup class=\"modern-footnotes-footnote \" data-mfn=\"1\" data-mfn-post-scope=\"000000000000057f0000000000000000_1668\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057f0000000000000000_1668-1\">1<\/a><\/sup><span id=\"mfn-content-000000000000057f0000000000000000_1668-1\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"1\">Code for all numerical experiments can be found on the <a href=\"https:\/\/github.com\/eepperly\/Iterative-Sketching-Is-Stable\/tree\/blogpost\/blogpost\"><em>blogpost<\/em> branch of the Github<\/a> for <a href=\"https:\/\/arxiv.org\/abs\/2311.04362\">my recent paper<\/a>.<\/span> We&#8217;ll compare three types of sketching matrices: <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S8.SS3\">Gaussian embeddings<\/a>, a <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S9.SS3\">subsampled randomized trigonometric transform<\/a> (SRTT), and <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S9.SS2\">sparse sign embeddings<\/a>. See the <a href=\"https:\/\/www.ethanepperly.com\/index.php\/2023\/11\/13\/does-sketching-work\/\">last post<\/a> for descriptions of these sketching matrices. I&#8217;ll discuss a few additional types of sketching matrices that require more discussion at the end of this post.<\/p>\n\n\n\n<p>Recall that a sketching matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9169a11ed0c9a455fe0958b71630faf6_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#100;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#110;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"73\" style=\"vertical-align: -1px;\"\/> seeks to compress a high-dimensional matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1883d8282130674ca1d87fabc88611bf_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#110;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#107;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"74\" style=\"vertical-align: -1px;\"\/> or vector <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-054b34698b3706ca9efd09c6723eb8d1_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#98;&#92;&#105;&#110;&#92;&#114;&#101;&#97;&#108;&#94;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"50\" style=\"vertical-align: -1px;\"\/> to a lower-dimensional sketched 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;\"\/> or vector <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-bd76151778055d405aee0532cc3a8f23_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#98;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"20\" style=\"vertical-align: 0px;\"\/>. The quality of a sketching matrix for 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 distortion <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-68eb29837031f4afbd699052143a2826_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"8\" style=\"vertical-align: 0px;\"\/>, defined to be the smallest number <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b7d1940a59903c3d1372ec01a488a98a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#62;&#32;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"41\" style=\"vertical-align: -2px;\"\/> such that <p class=\"ql-center-displayed-equation\" style=\"line-height: 19px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-06811a2d05bdccddd7b3c3079ed47729_l3.png\" height=\"19\" width=\"432\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#40;&#49;&#45;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#41;&#32;&#92;&#110;&#111;&#114;&#109;&#123;&#120;&#125;&#32;&#92;&#108;&#101;&#32;&#92;&#110;&#111;&#114;&#109;&#123;&#83;&#120;&#125;&#32;&#92;&#108;&#101;&#32;&#40;&#49;&#43;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#41;&#32;&#92;&#110;&#111;&#114;&#109;&#123;&#120;&#125;&#32;&#92;&#113;&#117;&#97;&#100;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#102;&#111;&#114;&#32;&#101;&#118;&#101;&#114;&#121;&#32;&#125;&#32;&#120;&#32;&#92;&#105;&#110;&#32;&#92;&#111;&#112;&#101;&#114;&#97;&#116;&#111;&#114;&#110;&#97;&#109;&#101;&#123;&#99;&#111;&#108;&#125;&#40;&#65;&#41;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>Here, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5829b36419ae593ec49dda84e77449bc_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#111;&#112;&#101;&#114;&#97;&#116;&#111;&#114;&#110;&#97;&#109;&#101;&#123;&#99;&#111;&#108;&#125;&#40;&#65;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"48\" style=\"vertical-align: -5px;\"\/> denotes the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Row_and_column_spaces\">column space<\/a> of the 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;\"\/>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"timing\">Timing<\/h3>\n\n\n\n<p>We begin with timing test. We will measure three different times for each embedding:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Construction.<\/strong> The time required to generate the 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;\"\/>.<\/li>\n\n\n\n<li><strong>Vector apply.<\/strong> The time to apply the sketch to a single vector.<\/li>\n\n\n\n<li><strong>Matrix apply.<\/strong> The time to apply the sketch to an <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c4ffe1f5245d090845f1f0167cad5d89_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#50;&#48;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"59\" style=\"vertical-align: 0px;\"\/> matrix.<\/li>\n<\/ol>\n\n\n\n<p>We will test with input dimension <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5ff92bd76ac697db34930bd25fdd0add_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;&#32;&#61;&#32;&#49;&#48;&#94;&#54;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"59\" style=\"vertical-align: 0px;\"\/> (one million) and output dimension <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-8d1006c4b3e5854d6d60b711ebc6c779_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#32;&#61;&#32;&#52;&#48;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"60\" style=\"vertical-align: 0px;\"\/>. For the SRTT, we use the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Discrete_cosine_transform\">discrete cosine transform<\/a> as our trigonometric transform. For the sparse sign embedding, we use a sparsity parameter <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e9be5aec527f5c2c5db883d80954afbc_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#56;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"42\" style=\"vertical-align: -4px;\"\/>.<\/p>\n\n\n\n<p>Here are the results (timings averaged over 20 trials):<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"423\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketching_compare-1024x423.png\" alt=\"\" class=\"wp-image-1671\" srcset=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketching_compare-1024x423.png 1024w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketching_compare-300x124.png 300w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketching_compare-768x317.png 768w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketching_compare-1536x634.png 1536w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketching_compare-2048x845.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>Our conclusions are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Sparse sign embeddings are definitively the fastest to apply, being 3\u201320\u00d7 faster than the SRTT and 74\u2013100\u00d7 faster than Gaussian embeddings.<\/li>\n\n\n\n<li>Sparse sign embeddings are modestly slower to construct than the SRTT, but much faster to construct than Gaussian embeddings.<\/li>\n<\/ul>\n\n\n\n<p>Overall, the conclusion is that sparse sign embeddings are the fastest sketching matrices by a wide margin: For an &#8220;end-to-end&#8221; workflow involving generating the sketching matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-f262f8ace3db2b4c1253def28833a14f_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#52;&#48;&#48;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#49;&#48;&#94;&#54;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"98\" style=\"vertical-align: -1px;\"\/> and applying it to a matrix <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1ad046f43826e623de61e5071f5bf5cb_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#92;&#105;&#110;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#49;&#48;&#94;&#54;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#50;&#48;&#48;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"100\" style=\"vertical-align: -1px;\"\/>, <strong>sparse sign embeddings are 14\u00d7 faster than SRTTs and 73\u00d7 faster than Gaussian embeddings.<\/strong><sup class=\"modern-footnotes-footnote \" data-mfn=\"2\" data-mfn-post-scope=\"000000000000057f0000000000000000_1668\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057f0000000000000000_1668-2\">2<\/a><\/sup><span id=\"mfn-content-000000000000057f0000000000000000_1668-2\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"2\">More timings are reported in <a href=\"https:\/\/arxiv.org\/abs\/2104.05877\">Table 1 of this paper<\/a>, which I credit for inspiring my enthusiasm for the sparse sign embedding l.<\/span>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"distortion\">Distortion<\/h3>\n\n\n\n<p>Runtime is only one measure of the quality of a sketching matrix; we also must care about the <em>distortion<\/em> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-68eb29837031f4afbd699052143a2826_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"8\" style=\"vertical-align: 0px;\"\/>. Fortunately, for practical purposes, Gaussian embeddings, SRTTs, and sparse sign embeddings all tend to have similar distortions. Therefore, we are free to use the sparse sign embeddings, as they as typically are the fastest.<\/p>\n\n\n\n<p>Consider the following test. We generate a sparse random test 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;\"\/> of size <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1a55278ecc061a49dac84a0a29899010_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#107;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"41\" style=\"vertical-align: 0px;\"\/> for <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-7d773f8f3d5d8d6148641a7a2461033d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;&#32;&#61;&#32;&#49;&#48;&#94;&#53;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"59\" style=\"vertical-align: 0px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-731ab5cc6f11bb750d5475d2a81e1761_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#107;&#32;&#61;&#32;&#53;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"51\" style=\"vertical-align: 0px;\"\/> using the MATLAB <em><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/sprand.html\">sprand<\/a><\/em> function; we set the sparsity level to 1%. We then compare the distortion of Gaussian embeddings, SRTTs, and sparse sign embeddings across a range of sketching dimensions <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1b031c8458e71f0e4df82ad61d36c0ca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"10\" style=\"vertical-align: 0px;\"\/> between 100 and 10,000. We report the distortion averaged over 100 trials. The theoretically predicted value <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-385b83cba2e4b8d81624be3a18b04f24_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#61;&#32;&#92;&#115;&#113;&#114;&#116;&#123;&#107;&#47;&#100;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"22\" width=\"78\" style=\"vertical-align: -6px;\"\/> (equivalently, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e44752fb454f374592388deb227d2a2f_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#61;&#107;&#47;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"67\" style=\"vertical-align: -5px;\"\/>) is shown as a dashed line.<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy-1024x768.png\" alt=\"\" class=\"wp-image-1672\" srcset=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy-1024x768.png 1024w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy-300x225.png 300w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy-768x576.png 768w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>To me, I find these results remarkable. All three embeddings exhibit essentially the same distortion parameter predicted by the Gaussian theory.<\/p>\n\n\n\n<p>It would be premature to declare success having only tested on one type of test 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;\"\/>. Consider the following four test matrices:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Sparse:<\/strong> The test matrix from above.<\/li>\n\n\n\n<li><strong>Dense:<\/strong> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e02306ea1d85764f5f0a2a7d5b54c014_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#92;&#105;&#110;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#49;&#48;&#94;&#54;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#53;&#48;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"93\" style=\"vertical-align: -1px;\"\/> is taken to be a matrix with independent standard Gaussian random values.<\/li>\n\n\n\n<li><strong>Khatri\u2013Rao:<\/strong> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-355f22ac175769c48c8227f875895dc9_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#92;&#105;&#110;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#53;&#48;&#94;&#51;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#53;&#48;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"93\" style=\"vertical-align: -1px;\"\/> is taken to be the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Khatri%E2%80%93Rao_product\">Khatri\u2013Rao product<\/a> of three <a href=\"https:\/\/nhigham.com\/2020\/04\/22\/what-is-a-random-orthogonal-matrix\/\">Haar random orthogonal matrices<\/a>.<\/li>\n\n\n\n<li><strong>Identity:<\/strong> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-2b6a7e5e56b6214d20f8f23a40202c76_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#32;&#61;&#32;&#92;&#116;&#119;&#111;&#98;&#121;&#111;&#110;&#101;&#123;&#73;&#125;&#123;&#48;&#125;&#32;&#92;&#105;&#110;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#49;&#48;&#94;&#54;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#53;&#48;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"42\" width=\"145\" style=\"vertical-align: -16px;\"\/> is taken to be the <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-55e6adb738d202ee9fbb2b1e3a5b09a2_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#53;&#48;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#53;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"57\" style=\"vertical-align: 0px;\"\/> identity matrix stacked onto a <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5b26e5cdabff214ddb54c921ff3f1f8b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#49;&#48;&#94;&#54;&#45;&#53;&#48;&#41;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#53;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"117\" style=\"vertical-align: -5px;\"\/> matrix of zeros.<\/li>\n<\/ul>\n\n\n\n<p>The performance of sparse sign embeddings (again with sparsity parameter <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e9be5aec527f5c2c5db883d80954afbc_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#56;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"42\" style=\"vertical-align: -4px;\"\/>) is shown below:<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy_2-1024x768.png\" alt=\"\" class=\"wp-image-1673\" srcset=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy_2-1024x768.png 1024w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy_2-300x225.png 300w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy_2-768x576.png 768w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sketch_accuracy_2.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>We see that for the first three test matrices, the performance closely follows the expected value <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-8b861062689fe3f5621b3df90378245d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#61;&#32;&#92;&#115;&#113;&#114;&#116;&#123;&#107;&#47;&#100;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"22\" width=\"77\" style=\"vertical-align: -6px;\"\/>. However, for the last test matrix &#8220;Identity&#8221;, we see the distortion begins to slightly exceed this predicted distortion for <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-88f13792c49f116ff3a772590721bb2c_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#47;&#107;&#92;&#103;&#101;&#32;&#50;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"70\" style=\"vertical-align: -5px;\"\/>.<\/p>\n\n\n\n<p>To improve sparse sign embeddings for higher values of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-35feb89221ec47ced3708605b218de42_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#47;&#107;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"27\" style=\"vertical-align: -5px;\"\/>, we can increase the value of the sparsity parameter <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9eff4ce0824e468ea783c595f12c30ef_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"9\" style=\"vertical-align: -4px;\"\/>. We recommend <p class=\"ql-center-displayed-equation\" style=\"line-height: 54px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5f1ebe7695d9918399b0f97b628fcce1_l3.png\" height=\"54\" width=\"183\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#92;&#109;&#97;&#120;&#32;&#92;&#108;&#101;&#102;&#116;&#40;&#32;&#56;&#32;&#44;&#32;&#92;&#108;&#101;&#102;&#116;&#92;&#108;&#99;&#101;&#105;&#108;&#32;&#50;&#92;&#115;&#113;&#114;&#116;&#123;&#92;&#102;&#114;&#97;&#99;&#123;&#100;&#125;&#123;&#107;&#125;&#125;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#92;&#114;&#99;&#101;&#105;&#108;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>With this higher sparsity level, the distortion closely tracks <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-385b83cba2e4b8d81624be3a18b04f24_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#61;&#32;&#92;&#115;&#113;&#114;&#116;&#123;&#107;&#47;&#100;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"22\" width=\"78\" style=\"vertical-align: -6px;\"\/> for all four test matrices:<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/12\/sketch_accuracy_3-1024x768.png\" alt=\"\" class=\"wp-image-1706\" srcset=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/12\/sketch_accuracy_3-1024x768.png 1024w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/12\/sketch_accuracy_3-300x225.png 300w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/12\/sketch_accuracy_3-768x576.png 768w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/12\/sketch_accuracy_3.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p>Implemented appropriately (see below), sparse sign embeddings can be faster than other sketching matrices by a wide margin. The parameter choice <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e9be5aec527f5c2c5db883d80954afbc_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#56;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"42\" style=\"vertical-align: -4px;\"\/> is enough to ensure the distortion closely tracks <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-385b83cba2e4b8d81624be3a18b04f24_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#61;&#32;&#92;&#115;&#113;&#114;&#116;&#123;&#107;&#47;&#100;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"22\" width=\"78\" style=\"vertical-align: -6px;\"\/> for most test matrices. For the toughest test matrices, a slightly larger sparsity parameter <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-a276a816fb44c5ce8c507d7f8d8da44b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#92;&#109;&#97;&#120;&#40;&#56;&#44;&#32;&#92;&#108;&#99;&#101;&#105;&#108;&#32;&#50;&#92;&#115;&#113;&#114;&#116;&#123;&#100;&#47;&#107;&#125;&#92;&#114;&#99;&#101;&#105;&#108;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"22\" width=\"166\" style=\"vertical-align: -6px;\"\/> can be necessary to achieve the optimal distortion.<\/p>\n\n\n\n<p>While these tests are far from comprehensive, they are consistent with the uniformly positive results for sparse sign embeddings reported in the literature. We believe that this evidence supports the argument that sparse sign embeddings are a sensible default sketching matrix for most purposes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"sparsesign\">Sparse Sign Embeddings: Theory and Practice<\/h2>\n\n\n\n<p>Given the highly appealing performance characteristics of sparse sign embeddings, it is worth saying a few more words about these embeddings and how they perform in both theory and practice.<\/p>\n\n\n\n<p>Recall that a sparse sign embedding is a random matrix of the form<p class=\"ql-center-displayed-equation\" style=\"line-height: 41px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-4871e53b2bb59ad11946f2d1eafc66f7_l3.png\" height=\"41\" width=\"177\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#83;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#49;&#125;&#123;&#92;&#115;&#113;&#114;&#116;&#123;&#92;&#122;&#101;&#116;&#97;&#125;&#125;&#32;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125;&#32;&#115;&#95;&#49;&#32;&#38;&#32;&#92;&#99;&#100;&#111;&#116;&#115;&#32;&#38;&#32;&#115;&#95;&#110;&#32;&#92;&#101;&#110;&#100;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>Each column <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-2a0fd890dba4d609496d0b299934972e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#115;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"13\" style=\"vertical-align: -3px;\"\/> is an independent and randomly generated to contain exactly <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9eff4ce0824e468ea783c595f12c30ef_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"9\" style=\"vertical-align: -4px;\"\/> nonzero entries in uniformly random positions. The value of each nonzero entry of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-2a0fd890dba4d609496d0b299934972e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#115;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"13\" style=\"vertical-align: -3px;\"\/> is chosen to be either <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c9ca90562e16fc4edd6d6a3c649ae81e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#43;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"22\" style=\"vertical-align: -2px;\"\/> or <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5bf4edce1009152f2284be30e87eaff0_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#45;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"21\" style=\"vertical-align: 0px;\"\/> with 50\/50 odds.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"parameterchoices\">Parameter Choices<\/h3>\n\n\n\n<p>The goal of sketching is to reduce vectors of length <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-75a5652acadcd645b180a972b75a9d09_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"11\" style=\"vertical-align: 0px;\"\/> to a smaller dimension <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1b031c8458e71f0e4df82ad61d36c0ca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"10\" style=\"vertical-align: 0px;\"\/>. For linear algebra applications, we typically want to preserve all vectors in the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Row_and_column_spaces\">column space<\/a> 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;\"\/> up to distortion <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b7d1940a59903c3d1372ec01a488a98a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#62;&#32;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"41\" style=\"vertical-align: -2px;\"\/>: <p class=\"ql-center-displayed-equation\" style=\"line-height: 19px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-41fd14292c1c85cd318dde801a75e1bd_l3.png\" height=\"19\" width=\"410\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#40;&#49;&#45;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#41;&#32;&#92;&#110;&#111;&#114;&#109;&#123;&#120;&#125;&#32;&#92;&#108;&#101;&#32;&#92;&#110;&#111;&#114;&#109;&#123;&#83;&#120;&#125;&#32;&#92;&#108;&#101;&#32;&#40;&#49;&#43;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#41;&#32;&#92;&#110;&#111;&#114;&#109;&#123;&#120;&#125;&#32;&#92;&#113;&#117;&#97;&#100;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#102;&#111;&#114;&#32;&#97;&#108;&#108;&#32;&#125;&#120;&#32;&#92;&#105;&#110;&#32;&#92;&#111;&#112;&#101;&#114;&#97;&#116;&#111;&#114;&#110;&#97;&#109;&#101;&#123;&#99;&#111;&#108;&#125;&#40;&#65;&#41;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>To use sparse sign embeddings, we must choose the parameters appropriately:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Given a dimension <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-f65286b751f121928913d4aa91d94ee9_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#107;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"9\" style=\"vertical-align: 0px;\"\/> and a target distortion <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-68eb29837031f4afbd699052143a2826_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"8\" style=\"vertical-align: 0px;\"\/>, how do we pick <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1b031c8458e71f0e4df82ad61d36c0ca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"10\" style=\"vertical-align: 0px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9eff4ce0824e468ea783c595f12c30ef_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"9\" style=\"vertical-align: -4px;\"\/>?<\/p>\n<\/blockquote>\n\n\n\n<p>Based on the experiments above (and other testing reported in the literature), we recommend the following parameter choices in practice:<p class=\"ql-center-displayed-equation\" style=\"line-height: 43px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-ed85cec8dadffec7c7a3b4e099d6637d_l3.png\" height=\"43\" width=\"248\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#100;&#32;&#61;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#107;&#125;&#123;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;&#125;&#32;&#92;&#113;&#117;&#97;&#100;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#97;&#110;&#100;&#125;&#32;&#92;&#113;&#117;&#97;&#100;&#32;&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#92;&#109;&#97;&#120;&#92;&#108;&#101;&#102;&#116;&#40;&#56;&#44;&#92;&#102;&#114;&#97;&#99;&#123;&#50;&#125;&#123;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>The parameter choice <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e9be5aec527f5c2c5db883d80954afbc_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#56;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"42\" style=\"vertical-align: -4px;\"\/> is advocated by <a href=\"https:\/\/arxiv.org\/abs\/1902.08651\">Tropp, Yurtever, Udell, and Cevher<\/a>; they mention experimenting with parameter values as small as <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b4d0fdeb8e47b9e2caa56a38c0d801e3_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"41\" style=\"vertical-align: -4px;\"\/>. The value <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-cf0901b99d6214cbde543a8a968e4347_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"41\" style=\"vertical-align: -4px;\"\/> has demonstrated deficiencies and should almost always be avoided (see below). The scaling <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-6774052ff5d917bba64006b63b9e31e0_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#32;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#107;&#47;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"67\" style=\"vertical-align: -5px;\"\/> is derived from the <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S8.SS5\">analysis of Gaussian embeddings<\/a>. As <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S9.SS7\">Martinsson and Tropp argue<\/a>, the analysis of Gaussian embeddings tends to be reasonably descriptive of other well-designed random embeddings.<\/p>\n\n\n\n<p>The best-known theoretical analysis, <a href=\"https:\/\/epubs.siam.org\/doi\/abs\/10.1137\/1.9781611974331.ch21\">due to Cohen<\/a>, suggests more cautious parameter setting for sparse sign embeddings: <p class=\"ql-center-displayed-equation\" style=\"line-height: 43px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-4fb6d0d60c85bc8a60d95bb0a19e63d6_l3.png\" height=\"43\" width=\"319\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#100;&#32;&#61;&#32;&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#40;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#107;&#32;&#92;&#108;&#111;&#103;&#32;&#107;&#125;&#123;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;&#125;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#32;&#92;&#113;&#117;&#97;&#100;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#97;&#110;&#100;&#125;&#32;&#92;&#113;&#117;&#97;&#100;&#32;&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#92;&#108;&#101;&#102;&#116;&#40;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#92;&#108;&#111;&#103;&#32;&#107;&#125;&#123;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#125;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>The main difference between Cohen&#8217;s analysis and the parameter recommendations above is the presence of the <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-cc3dafe76da1ba8878516231cf10d24d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#108;&#111;&#103;&#32;&#107;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"35\" style=\"vertical-align: -4px;\"\/> factor and the lack of explicit constants in the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Big_O_notation\">O-notation<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"implementation\">Implementation<\/h3>\n\n\n\n<p>For good performance, it is imperative to store <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;\"\/> using either a purpose-built data structure or a <a href=\"https:\/\/www.ethanepperly.com\/index.php\/2020\/07\/18\/big-ideas-in-applied-math-sparse-matrices\/\">sparse matrix format<\/a> (such as a <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/sparse-matrices.html\">MATLAB sparse matrix<\/a> or <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/sparse.html\">scipy sparse array<\/a>).<\/p>\n\n\n\n<p>If a sparse matrix library is unavailable, then either pursue a dedicated implementation or use a different type of embedding; sparse sign embeddings are just as slow as Gaussian embeddings if they are stored in an ordinary non-sparse matrix format!<\/p>\n\n\n\n<p>Even with a sparse matrix format, it can require care to generate and populate the random entries of the 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;\"\/>. Here, for instance, is a simple function for generating a sparse sign matrix in MATLAB:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function S = sparsesign_slow(d,n,zeta)\ncols = kron((1:n)',ones(zeta,1)); <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">% zeta nonzeros per column<\/mark>\nvals = 2*randi(2,n*zeta,1) - 3; <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">% uniform random +\/-1 values<\/mark>\nrows = zeros(n*zeta,1);\nfor i = 1:n\n   rows((i-1)*zeta+1:i*zeta) = randsample(d,zeta);\nend\nS = sparse(rows, cols, vals \/ sqrt(zeta), d, n);\nend<\/code><\/pre>\n\n\n\n<p>Here, we specify the rows, columns, and values of the nonzero entries before assembling them into a sparse matrix using the MATLAB <em><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/sparse.html\">sparse<\/a><\/em> command. Since there are exactly <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9eff4ce0824e468ea783c595f12c30ef_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"9\" style=\"vertical-align: -4px;\"\/> nonzeros per column, the column indices are easy to generate. The values are uniformly <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c4f25c6944afd04a461ab2384b1a799c_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#112;&#109;&#32;&#49;&#47;&#92;&#115;&#113;&#114;&#116;&#123;&#92;&#122;&#101;&#116;&#97;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"56\" style=\"vertical-align: -5px;\"\/> and can also be generated using a single line. The real challenge to generating sparse sign embeddings in MATLAB is the row indices, since each batch of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9eff4ce0824e468ea783c595f12c30ef_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"9\" style=\"vertical-align: -4px;\"\/> row indices much be chosen uniformly at random between <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-27e3598fd2d4f0491067f1afaced92e9_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"7\" style=\"vertical-align: 0px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1b031c8458e71f0e4df82ad61d36c0ca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"10\" style=\"vertical-align: 0px;\"\/> <em>without replacement<\/em>. This is accomplished in the above code by a for loop, generating row indices <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9eff4ce0824e468ea783c595f12c30ef_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"9\" style=\"vertical-align: -4px;\"\/> at a time using the slow <em><a href=\"https:\/\/www.mathworks.com\/help\/stats\/randsample.html\">randsample<\/a><\/em> function.<\/p>\n\n\n\n<p>As its name suggests, the <em>sparsesign_slow<\/em> is very slow. To generate a <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c5b88e815a193edd2eb426dcbabe9431_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#50;&#48;&#48;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#49;&#48;&#94;&#55;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"73\" style=\"vertical-align: 0px;\"\/> sparse sign embedding with sparsity <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e9be5aec527f5c2c5db883d80954afbc_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#56;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"42\" style=\"vertical-align: -4px;\"\/> requires 53 seconds!<\/p>\n\n\n\n<p>Fortunately, we can do (much) better. By rewriting the code in C and directly generating the sparse matrix in the <a href=\"https:\/\/www.numerical.rl.ac.uk\/spral\/doc\/latest\/Fortran\/csc_format.html\">CSC format<\/a> <a href=\"https:\/\/www.mathworks.com\/help\/pdf_doc\/otherdocs\/simax.pdf\">MATLAB uses<\/a>, generating this same 200 by 10 million sparse sign embedding takes just 0.4 seconds, <strong>a speedup of 130\u00d7 over the slow MATLAB code<\/strong>. A C implementation of the sparse sign embedding that can be used in MATLAB using the <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/call-mex-file-functions.html\">MEX interface<\/a> can be found in <a href=\"https:\/\/github.com\/eepperly\/Iterative-Sketching-Is-Stable\/blob\/main\/code\/sparsesign.c\">this file<\/a> in the <a href=\"https:\/\/github.com\/eepperly\/Iterative-Sketching-Is-Stable\">Github repo for my recent paper<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"othersketches\">Other Sketching Matrices<\/h2>\n\n\n\n<p>Let&#8217;s leave off the discussion by mentioning other types of sketching matrices not considered in the empirical comparison above.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"coordinatesampling\">Coordinate Sampling<\/h3>\n\n\n\n<p>Another family of sketching matrices that we haven&#8217;t talked about are <em>coordinate sampling<\/em> sketches. A coordinate sampling sketch consists of indices <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-aff58d2d45a089ffbd3a97f9593a6248_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;&#92;&#108;&#101;&#32;&#105;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#105;&#95;&#100;&#92;&#108;&#101;&#32;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"133\" style=\"vertical-align: -4px;\"\/> and weights <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-7bc861bf6d8e667390c879a6cf3d7006_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#119;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#119;&#95;&#100;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"115\" style=\"vertical-align: -4px;\"\/>. To apply <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;\"\/>, we sample the indices <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-252537df37f8ca79038d0721747d56f5_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#105;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#105;&#95;&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"67\" style=\"vertical-align: -4px;\"\/> and reweight them using the weights:<\/p>\n\n\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 22px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-712b97fc6f6efb9bf9a40dac2a652f5c_l3.png\" height=\"22\" width=\"313\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#98;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;&#94;&#110;&#32;&#92;&#108;&#111;&#110;&#103;&#109;&#97;&#112;&#115;&#116;&#111;&#32;&#83;&#98;&#32;&#61;&#32;&#40;&#119;&#95;&#49;&#32;&#98;&#95;&#123;&#105;&#95;&#49;&#125;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#119;&#95;&#100;&#98;&#95;&#123;&#105;&#95;&#100;&#125;&#41;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;&#94;&#100;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n\n\n\n<p>Coordinate sampling is very appealing: To apply <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;\"\/> to a matrix or vector requires no matrix multiplication of trigonometric transforms, just picking out some entries or rows and rescaling them.<\/p>\n\n\n\n<p>In order for coordinate sampling to be effective, we need to pick the right indices. Below, we compare two coordinate sampling sketching approaches, <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S9.SS6.SSS2\">uniform sampling<\/a> and <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S9.SS6.SSS3\">leverage score sampling<\/a> (both with replacement), to the sparse sign embedding with the suggested parameter setting <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-8335d7ef58c49228161568ee16a0da94_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#92;&#109;&#97;&#120;&#40;&#56;&#44;&#92;&#108;&#99;&#101;&#105;&#108;&#32;&#50;&#92;&#115;&#113;&#114;&#116;&#123;&#100;&#47;&#107;&#125;&#92;&#114;&#99;&#101;&#105;&#108;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"22\" width=\"166\" style=\"vertical-align: -6px;\"\/> for the hard &#8220;Identity&#8221; test matrix used above.<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sampling-1024x768.png\" alt=\"\" class=\"wp-image-1675\" srcset=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sampling-1024x768.png 1024w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sampling-300x225.png 300w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sampling-768x576.png 768w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/sampling.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>We see right away that the uniform sampling fails dramatically on this problem. That&#8217;s to be expected. All but 50 of 100,000 rows 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;\"\/> are zero, so picking rows uniformly at random will give nonsense with very high probability. Uniform sampling can work well for matrices <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;\"\/> which are <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S9.SS6.SSS1\">&#8220;incoherent&#8221;<\/a>, with all rows 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;\"\/> being of &#8220;similar importance&#8221;.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Conclusion (Uniform sampling).<\/strong> Uniform sampling is a risky method; it works excellently for some problems, but fails spectacularly for others. Use only with caution!<\/p>\n<\/blockquote>\n\n\n\n<p>The ridge leverage score sampling method is more interesting. Unlike all the other sketches we&#8217;ve discussed in this post, ridge leverage score sampling is <em>data-dependent<\/em>. First, it computes a <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2002.01387#S9.SS6.SSS1\">leverage score<\/a> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-314036f38fc615bf602031c004ec67e0_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#101;&#108;&#108;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"12\" style=\"vertical-align: -3px;\"\/> for each row 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;\"\/> and then samples rows with probabilities proportional to these scores. For high enough values of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1b031c8458e71f0e4df82ad61d36c0ca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"10\" style=\"vertical-align: 0px;\"\/>, ridge leverage score sampling performs slightly (but only slightly) worse than the characteristic <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-385b83cba2e4b8d81624be3a18b04f24_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#61;&#32;&#92;&#115;&#113;&#114;&#116;&#123;&#107;&#47;&#100;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"22\" width=\"78\" style=\"vertical-align: -6px;\"\/> scaling we expect for an oblivious subspace embedding.<\/p>\n\n\n\n<p>Ultimately, leverage score sampling has two disadvantages when compared with oblivious sketching matrices:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Higher distortion, higher variance.<\/strong> The distortion of a leverage score sketch is higher on average, and more variable, than an oblivious sketch, which achieve very consistent performance.<\/li>\n\n\n\n<li><strong>Computing the leverage scores.<\/strong> In order to implement this sketch, the leverage scores <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-314036f38fc615bf602031c004ec67e0_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#101;&#108;&#108;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"12\" style=\"vertical-align: -3px;\"\/> have to first be computed or estimated. This is a nontrivial algorithmic problem; the most direct way of computing the leverage scores requires a QR decomposition at <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-ebbc5e7bbff1376cf1e3f7b3220232a9_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#110;&#107;&#94;&#50;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"55\" style=\"vertical-align: -5px;\"\/> cost, much higher than other types of sketches.<\/li>\n<\/ul>\n\n\n\n<p>There are settings when coordinate sampling methods, such as leverage scores, are well-justified:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Structured matrices.<\/strong> For some matrices <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;\"\/>, the leverage scores might be very cheap to compute or approximate. In <a href=\"https:\/\/arxiv.org\/abs\/2006.16438\">such<\/a> <a href=\"https:\/\/arxiv.org\/abs\/2301.12584\">cases<\/a>, coordinate sampling can be faster than oblivious sketching.<\/li>\n\n\n\n<li><strong><a href=\"https:\/\/arxiv.org\/abs\/2111.04888\">&#8220;Active learning&#8221;.<\/a><\/strong> For some problems, each entry of the vector <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3ab6f6c64ce17f786a81f8cc8fdcec90_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#98;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"8\" style=\"vertical-align: 0px;\"\/> or row of the 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;\"\/> may be expensive to generate. In this case, coordinate sampling has the distinct advantage that computing <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-bd76151778055d405aee0532cc3a8f23_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#98;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"20\" style=\"vertical-align: 0px;\"\/> or <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;\"\/> only requires generating the entries of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3ab6f6c64ce17f786a81f8cc8fdcec90_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#98;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"8\" style=\"vertical-align: 0px;\"\/> or rows 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;\"\/> for the <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1b031c8458e71f0e4df82ad61d36c0ca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"10\" style=\"vertical-align: 0px;\"\/> randomly selected indices <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-252537df37f8ca79038d0721747d56f5_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#105;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#105;&#95;&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"67\" style=\"vertical-align: -4px;\"\/>.<\/li>\n<\/ul>\n\n\n\n<p>Ultimately, oblivious sketching and coordinate sampling both have their place as tools in the computational toolkit. For the reasons described above, I believe that oblivious sketching should usually be preferred to coordinate sampling in the absence of a special reason to prefer the latter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"tensorembeddings\">Tensor Random Embeddings<\/h3>\n\n\n\n<p>There are a number of sketching matrices with tensor structure; see <a href=\"https:\/\/ar5iv.labs.arxiv.org\/html\/2302.11474#Ch7\">here<\/a> for a survey. These types of sketching matrices are very well-suited to tensor computations. If tensor structure is present in your application, I would put these types of sketches at the top of my list for consideration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"countsketch\">CountSketch<\/h3>\n\n\n\n<p>The CountSketch sketching matrix is the <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-cf0901b99d6214cbde543a8a968e4347_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"41\" style=\"vertical-align: -4px;\"\/> case of the sparse sign embedding. CountSketch has serious deficiencies, and should only be used in practice with extreme care.<\/p>\n\n\n\n<p>Consider the &#8220;Identity&#8221; test matrix from above but with parameter <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c8c74e059e86010b112cda267190ede1_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#107;&#32;&#61;&#32;&#50;&#48;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"60\" style=\"vertical-align: 0px;\"\/>, and compare the distortion of CountSketch to the sparse sign embedding with parameters <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-a8756723c92cc2509f0aea97089f3348_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#61;&#50;&#44;&#52;&#44;&#56;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"75\" style=\"vertical-align: -4px;\"\/>:<\/p>\n\n\n<div class=\"wp-block-image is-resized\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/countsketchbad-1024x768.png\" alt=\"\" class=\"wp-image-1676\" srcset=\"https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/countsketchbad-1024x768.png 1024w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/countsketchbad-300x225.png 300w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/countsketchbad-768x576.png 768w, https:\/\/www.ethanepperly.com\/wp-content\/uploads\/2023\/11\/countsketchbad.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>We see that the distortion of the CountSketch remains persistently high at 100% until the sketching dimension <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1b031c8458e71f0e4df82ad61d36c0ca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"10\" style=\"vertical-align: 0px;\"\/> is taken <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5754a8a8671ffc63d1f62ce87612f27e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#62;&#52;&#51;&#48;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"54\" style=\"vertical-align: -2px;\"\/>, <strong>20\u00d7 higher<\/strong> than <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-f65286b751f121928913d4aa91d94ee9_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#107;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"9\" style=\"vertical-align: 0px;\"\/>.<\/p>\n\n\n\n<p>CountSketch is bad because it requires <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1b031c8458e71f0e4df82ad61d36c0ca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"10\" style=\"vertical-align: 0px;\"\/> to be proportional to <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-ddd209c73661c7b60a79aa30c832957b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#107;&#94;&#50;&#47;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"41\" style=\"vertical-align: -5px;\"\/> in order to achieve distortion <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-68eb29837031f4afbd699052143a2826_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"8\" style=\"vertical-align: 0px;\"\/>. For all of the other sketching matrices we&#8217;ve considered, we&#8217;ve only required <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1b031c8458e71f0e4df82ad61d36c0ca_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"10\" style=\"vertical-align: 0px;\"\/> to be proportional to <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-fede8887dee50801e0ce468b8c3f2125_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#107;&#47;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"34\" style=\"vertical-align: -5px;\"\/> (or perhaps <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-70e4ca45630b5aad3c221a671ea25b87_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#107;&#92;&#108;&#111;&#103;&#32;&#107;&#41;&#47;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"85\" style=\"vertical-align: -5px;\"\/>). This difference between <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-8377f356360e6bddb840c4b92dff48de_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#92;&#112;&#114;&#111;&#112;&#116;&#111;&#32;&#107;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"50\" style=\"vertical-align: 0px;\"\/> for CountSketch and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-4309d2d7a7b2089ee88791c7bb5a6c65_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#92;&#112;&#114;&#111;&#112;&#116;&#111;&#32;&#107;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"42\" style=\"vertical-align: 0px;\"\/> for other sketching matrices is a at the root of CountSketch&#8217;s woefully bad performance on some inputs.<sup class=\"modern-footnotes-footnote \" data-mfn=\"3\" data-mfn-post-scope=\"000000000000057f0000000000000000_1668\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057f0000000000000000_1668-3\">3<\/a><\/sup><span id=\"mfn-content-000000000000057f0000000000000000_1668-3\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"3\">Here, the symbol <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-54c5d915408193fb5d1d2f4a07cec2fe_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#112;&#114;&#111;&#112;&#116;&#111;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"13\" style=\"vertical-align: 0px;\"\/> is an informal symbol meaning &#8220;proportional to&#8221;.<\/span>\n\n\n\n<p>The fact that CountSketch requires <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-8377f356360e6bddb840c4b92dff48de_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#92;&#112;&#114;&#111;&#112;&#116;&#111;&#32;&#107;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"50\" style=\"vertical-align: 0px;\"\/> is simple to show. It&#8217;s basically a variant on the famous birthday problem. We include a discussion at the end of this post.<sup class=\"modern-footnotes-footnote \" data-mfn=\"4\" data-mfn-post-scope=\"000000000000057f0000000000000000_1668\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057f0000000000000000_1668-4\">4<\/a><\/sup><span id=\"mfn-content-000000000000057f0000000000000000_1668-4\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"4\">In fact, <em>any<\/em> oblivious sketching matrix with only 1 nonzero entry per column must have <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9b84236fe9ffeb08c5812f62389e8c34_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#92;&#103;&#116;&#114;&#115;&#105;&#109;&#32;&#107;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"50\" style=\"vertical-align: -4px;\"\/>. This is Theorem 16 in <a href=\"https:\/\/arxiv.org\/abs\/1211.0995\">the following paper<\/a>.<\/span>\n\n\n\n<p>There are ways of fixing the CountSketch. For instance, we can use a composite sketch <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-f297e79b9eae62315bb366db9182f06a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#32;&#61;&#32;&#83;&#95;&#50;&#32;&#92;&#99;&#100;&#111;&#116;&#32;&#83;&#95;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"84\" style=\"vertical-align: -3px;\"\/>, where <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-bda94e423e715e325be7d6fdb4979e22_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#95;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"17\" style=\"vertical-align: -3px;\"\/> is a CountSketch of size <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-fa15d8d2ba5b8fc31daab997ed43d882_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#107;&#94;&#50;&#47;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;&#32;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"75\" style=\"vertical-align: -5px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-687ae2bdc12ecb3fc8afab3915729bf3_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#95;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"18\" style=\"vertical-align: -3px;\"\/> is a Gaussian sketching matrix of size <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-7259045c2d46e8b9f44bd7cc1329642e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#107;&#47;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;&#32;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#107;&#94;&#50;&#47;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"98\" style=\"vertical-align: -5px;\"\/>.<sup class=\"modern-footnotes-footnote \" data-mfn=\"5\" data-mfn-post-scope=\"000000000000057f0000000000000000_1668\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057f0000000000000000_1668-5\">5<\/a><\/sup><span id=\"mfn-content-000000000000057f0000000000000000_1668-5\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"5\">This construction is from <a href=\"http:\/\/proceedings.mlr.press\/v48\/kapralov16.html\">this paper<\/a>.<\/span> For most applications, however, salvaging CountSketch doesn&#8217;t seem worth it; sparse sign embeddings with even <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b4d0fdeb8e47b9e2caa56a38c0d801e3_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#122;&#101;&#116;&#97;&#32;&#61;&#32;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"41\" style=\"vertical-align: -4px;\"\/> nonzeros per column are already way more effective and reliable than a plain CountSketch.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>By now, sketching is quite a big field, with dozens of different proposed constructions for sketching matrices. So which should you use? For most use cases, sparse sign embeddings are a good choice; they are fast to construct and apply and offer uniformly good distortion across a range of matrices.<\/p>\n\n\n<div class=\"su-spoiler su-spoiler-style-default su-spoiler-icon-plus su-spoiler-closed\" data-scroll-offset=\"0\" data-anchor-in-url=\"no\"><div class=\"su-spoiler-title\" tabindex=\"0\" role=\"button\"><span class=\"su-spoiler-icon\"><\/span>Bonus: CountSketch and the Birthday Problem<\/div><div class=\"su-spoiler-content su-u-clearfix su-u-trim\">The point of this bonus section is to prove the following (informal) theorem:<\/p>\n<blockquote>\n<p>Let <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;\"\/> be the &#8220;Identity&#8221; test matrix above. If <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-53c143a41b2d5d2357b8755aff34a28a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#83;&#92;&#105;&#110;&#92;&#114;&#101;&#97;&#108;&#94;&#123;&#100;&#92;&#116;&#105;&#109;&#101;&#115;&#32;&#110;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"73\" style=\"vertical-align: -1px;\"\/> is a CountSketch matrix with output dimension <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-56ef59a99e1edd6fb2bcf76bee84e32d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#92;&#108;&#108;&#32;&#107;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"54\" style=\"vertical-align: -1px;\"\/>, then the distortion of <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;\"\/> for <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5829b36419ae593ec49dda84e77449bc_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#111;&#112;&#101;&#114;&#97;&#116;&#111;&#114;&#110;&#97;&#109;&#101;&#123;&#99;&#111;&#108;&#125;&#40;&#65;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"48\" style=\"vertical-align: -5px;\"\/> is <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-43d411f32411e4be0dfaa3db7586c344_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#92;&#103;&#101;&#32;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"40\" style=\"vertical-align: -3px;\"\/> with high probability.<\/p>\n<\/blockquote>\n<p>Let&#8217;s see why. By the structure of the 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;\"\/>, <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;\"\/> has the form <p class=\"ql-center-displayed-equation\" style=\"line-height: 22px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-82c7ea0e5c52b6bd9bdb389f3d3f92d7_l3.png\" height=\"22\" width=\"149\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#83;&#65;&#32;&#61;&#32;&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125;&#32;&#115;&#95;&#49;&#32;&#38;&#32;&#92;&#99;&#100;&#111;&#116;&#115;&#32;&#38;&#32;&#115;&#95;&#107;&#32;&#92;&#101;&#110;&#100;&#123;&#98;&#109;&#97;&#116;&#114;&#105;&#120;&#125;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>where each vector <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-74a27f1e3a80e8bbf4df0d73e0c346df_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#115;&#95;&#105;&#92;&#105;&#110;&#92;&#114;&#101;&#97;&#108;&#94;&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"56\" style=\"vertical-align: -3px;\"\/> has a single <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c73136781a786bab430149909f8607df_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#112;&#109;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"22\" style=\"vertical-align: 0px;\"\/> in a uniformly random location <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-2698bbf8b6e247bc34bf34e030a406b9_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#92;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"22\" style=\"vertical-align: -4px;\"\/>.<\/p>\n<p>Suppose that the indices <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-6b1ed87cb0dfc90357b9214d62e3646b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#107;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"69\" style=\"vertical-align: -4px;\"\/> are <em>not<\/em>&nbsp;all different from each other, say <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-fbe2aeeeeacd33a555404a7e76950616_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#105;&#32;&#61;&#32;&#106;&#95;&#123;&#105;&#39;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"53\" style=\"vertical-align: -4px;\"\/>. Set <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b657a462d45c15731cbb6f856e58c46f_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#32;&#61;&#32;&#101;&#95;&#105;&#32;&#45;&#32;&#101;&#95;&#123;&#105;&#39;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"86\" style=\"vertical-align: -3px;\"\/>, where <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1075ca49a05d896a0fb08968ab8431b2_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#101;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"11\" width=\"13\" style=\"vertical-align: -3px;\"\/> is the standard basis vector with <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-27e3598fd2d4f0491067f1afaced92e9_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"7\" style=\"vertical-align: 0px;\"\/> in position <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-4015d3bcae440238eb2e7a73e66bae43_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"6\" style=\"vertical-align: 0px;\"\/> and zeros elsewhere. Then, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e0338d9a01aef2d898108e50c285704f_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#40;&#83;&#65;&#41;&#120;&#32;&#61;&#32;&#48;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"81\" style=\"vertical-align: -5px;\"\/> but <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5e0fad7d0297add9b3502d942e5bb649_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#110;&#111;&#114;&#109;&#123;&#120;&#125;&#32;&#61;&#32;&#92;&#115;&#113;&#114;&#116;&#123;&#50;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"21\" width=\"73\" style=\"vertical-align: -5px;\"\/>. Thus, for the distortion relation <p class=\"ql-center-displayed-equation\" style=\"line-height: 22px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b08feebb30829a0e73b02188eba6f901_l3.png\" height=\"22\" width=\"303\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#40;&#49;&#45;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#41;&#32;&#92;&#110;&#111;&#114;&#109;&#123;&#120;&#125;&#32;&#61;&#40;&#49;&#45;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#41;&#92;&#115;&#113;&#114;&#116;&#123;&#50;&#125;&#32;&#92;&#108;&#101;&#32;&#48;&#32;&#61;&#32;&#92;&#110;&#111;&#114;&#109;&#123;&#40;&#83;&#65;&#41;&#120;&#125;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>to hold, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-2e0651e2137cb8922b3ddbe753b3e297_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#92;&#103;&#101;&#32;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"40\" style=\"vertical-align: -3px;\"\/>. Thus, <p class=\"ql-center-displayed-equation\" style=\"line-height: 19px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-12fa7b716b97c7e9482f4f6327bd4728_l3.png\" height=\"19\" width=\"321\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#112;&#114;&#111;&#98;&#32;&#92;&#123;&#32;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#92;&#103;&#101;&#32;&#49;&#32;&#92;&#125;&#32;&#92;&#103;&#101;&#32;&#92;&#112;&#114;&#111;&#98;&#32;&#92;&#123;&#32;&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#107;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#32;&#97;&#114;&#101;&#32;&#110;&#111;&#116;&#32;&#100;&#105;&#115;&#116;&#105;&#110;&#99;&#116;&#125;&#32;&#92;&#125;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n<p>For a moment, let&#8217;s put aside our analysis of the CountSketch, and turn our attention to a famous puzzle, known as the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Birthday_problem\">birthday problem<\/a>:<\/p>\n<blockquote>\n<p>How many people have to be in a room before there&#8217;s at least a 50% chance that two people share the same birthday?<\/p>\n<\/blockquote>\n<p>The counterintuitive or &#8220;paradoxical&#8221; answer: 23. This is much smaller than many people&#8217;s intuition, as there are 365 possible birthdays and 23 is much smaller than 365.<\/p>\n<p>The reason for this surprising result is that, in a room of 23 people, there are <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c1a16f28ac59a19bcb2789a8eb7460e4_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#123;&#50;&#51;&#32;&#92;&#99;&#104;&#111;&#111;&#115;&#101;&#32;&#50;&#125;&#32;&#61;&#32;&#50;&#51;&#92;&#99;&#100;&#111;&#116;&#32;&#50;&#50;&#47;&#50;&#61;&#50;&#53;&#51;\" title=\"Rendered by QuickLaTeX.com\" height=\"24\" width=\"168\" style=\"vertical-align: -7px;\"\/> <em>pairs<\/em> of people. Each pair of people has a <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-082252112cf3b2daa392cf8f840d2376_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;&#47;&#51;&#54;&#53;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"43\" style=\"vertical-align: -5px;\"\/> chance of sharing a birthday, so the <em>expected number<\/em> of birthdays in a room of 23 people is <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-0b92a3f1ae7b9bc020205e178f5f9b22_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#50;&#53;&#51;&#47;&#51;&#54;&#53;&#32;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#48;&#46;&#54;&#57;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"118\" style=\"vertical-align: -5px;\"\/>. Since are 0.69 birthdays shared <em>on average<\/em> in a room of 23 people, it is perhaps less surprising that 23 is the critical number at which the chance of two people sharing a birthday exceeds 50%.<\/p>\n<p>Hopefully, the similarity between the birthday problem and CountSketch is becoming clear. Each <em>pair<\/em> of indices <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-db89a4a2a1a4b8e3c38fa43cf0db2e94_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"13\" style=\"vertical-align: -4px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-086036b8746e356f4a344c37046ce1d2_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#123;&#105;&#39;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"17\" style=\"vertical-align: -4px;\"\/> in CountSketch have a <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9636aa8e8b7707e739988afd7e563172_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;&#47;&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"27\" style=\"vertical-align: -5px;\"\/> chance of being the same. There are <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-67cb8db52fe4785601baa269c0f081b7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#123;&#107;&#92;&#99;&#104;&#111;&#111;&#115;&#101;&#32;&#50;&#125;&#32;&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#107;&#94;&#50;&#47;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"24\" width=\"80\" style=\"vertical-align: -7px;\"\/> pairs of indices, so the <em>expected number<\/em> of equal indices <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-fbe2aeeeeacd33a555404a7e76950616_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#105;&#32;&#61;&#32;&#106;&#95;&#123;&#105;&#39;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"53\" style=\"vertical-align: -4px;\"\/> is <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-7a45cd15a5ad9528ae92ecaa1206805f_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#107;&#94;&#50;&#47;&#50;&#100;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"64\" style=\"vertical-align: -5px;\"\/>. Thus, we should anticipate <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-d8771bcd5700b0e490767acd44d4bfc8_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#100;&#32;&#92;&#103;&#116;&#114;&#97;&#112;&#112;&#114;&#111;&#120;&#32;&#107;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"21\" width=\"50\" style=\"vertical-align: -6px;\"\/> is required to ensure that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-6b1ed87cb0dfc90357b9214d62e3646b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#107;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"69\" style=\"vertical-align: -4px;\"\/> are distinct with high probability.<\/p>\n<p>Let&#8217;s calculate things out a bit more precisely. First, realize that<p class=\"ql-center-displayed-equation\" style=\"line-height: 19px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-338a38501a565185b794f8ed03803c9a_l3.png\" height=\"19\" width=\"475\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#112;&#114;&#111;&#98;&#32;&#92;&#123;&#32;&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#107;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#32;&#97;&#114;&#101;&#32;&#110;&#111;&#116;&#32;&#100;&#105;&#115;&#116;&#105;&#110;&#99;&#116;&#125;&#32;&#92;&#125;&#32;&#61;&#32;&#49;&#32;&#45;&#32;&#92;&#112;&#114;&#111;&#98;&#32;&#92;&#123;&#32;&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#107;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#32;&#97;&#114;&#101;&#32;&#100;&#105;&#115;&#116;&#105;&#110;&#99;&#116;&#125;&#32;&#92;&#125;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>To compute the probability that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-6b1ed87cb0dfc90357b9214d62e3646b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#107;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"69\" style=\"vertical-align: -4px;\"\/> are distinct, imagine introducing each <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-db89a4a2a1a4b8e3c38fa43cf0db2e94_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"13\" style=\"vertical-align: -4px;\"\/> one at a time. Assuming that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e33635cd2652fa807453f39b84c03dfb_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#123;&#105;&#45;&#49;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"84\" style=\"vertical-align: -4px;\"\/> are all distinct, the probability <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-ed92aa124acc1563e3a02205ff21252e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"67\" style=\"vertical-align: -4px;\"\/> are distinct is just the probability that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-db89a4a2a1a4b8e3c38fa43cf0db2e94_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"13\" style=\"vertical-align: -4px;\"\/> does not take any of the <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-d043c3d14bf35e65fd691f4e1a9f2966_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#105;&#45;&#49;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"36\" style=\"vertical-align: 0px;\"\/> values <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-ed92aa124acc1563e3a02205ff21252e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#105;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"67\" style=\"vertical-align: -4px;\"\/>. This probability is <p class=\"ql-center-displayed-equation\" style=\"line-height: 36px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b474f00c44e53b7c3c398d56121e1ac3_l3.png\" height=\"36\" width=\"481\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#112;&#114;&#111;&#98;&#92;&#123;&#32;&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#105;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#32;&#97;&#114;&#101;&#32;&#100;&#105;&#115;&#116;&#105;&#110;&#99;&#116;&#125;&#32;&#92;&#109;&#105;&#100;&#32;&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#123;&#105;&#45;&#49;&#125;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#32;&#97;&#114;&#101;&#32;&#100;&#105;&#115;&#116;&#105;&#110;&#99;&#116;&#125;&#92;&#125;&#32;&#61;&#32;&#49;&#32;&#45;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#105;&#45;&#49;&#125;&#123;&#100;&#125;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>Thus, by the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Chain_rule_(probability)#Finitely_many_events\">chain rule for probability<\/a>,<p class=\"ql-center-displayed-equation\" style=\"line-height: 53px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-7dd28281f8dbed8b3a1452a21e7410c8_l3.png\" height=\"53\" width=\"345\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#112;&#114;&#111;&#98;&#32;&#92;&#123;&#32;&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#107;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#32;&#97;&#114;&#101;&#32;&#100;&#105;&#115;&#116;&#105;&#110;&#99;&#116;&#125;&#32;&#92;&#125;&#32;&#61;&#32;&#92;&#112;&#114;&#111;&#100;&#95;&#123;&#105;&#61;&#49;&#125;&#94;&#107;&#32;&#92;&#108;&#101;&#102;&#116;&#40;&#49;&#32;&#45;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#105;&#45;&#49;&#125;&#123;&#100;&#125;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>To bound this quantity, use the numeric inequality <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3592614ecbc76a2ac663c11037f8b4c7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#49;&#45;&#120;&#92;&#108;&#101;&#32;&#92;&#101;&#120;&#112;&#40;&#45;&#120;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"127\" style=\"vertical-align: -5px;\"\/> for every <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-5a4828ab3cc2dd7c7cdc912546df5cc4_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#120;&#32;&#92;&#105;&#110;&#32;&#92;&#114;&#101;&#97;&#108;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"45\" style=\"vertical-align: -1px;\"\/>, obtaining<p class=\"ql-center-displayed-equation\" style=\"line-height: 54px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-8d9d4c7d12af0fd89e53ca261c5df287_l3.png\" height=\"54\" width=\"642\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#80;&#125;&#32;&#92;&#123;&#32;&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#107;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#32;&#97;&#114;&#101;&#32;&#100;&#105;&#115;&#116;&#105;&#110;&#99;&#116;&#125;&#32;&#92;&#125;&#32;&#92;&#108;&#101;&#32;&#92;&#112;&#114;&#111;&#100;&#95;&#123;&#105;&#61;&#48;&#125;&#94;&#123;&#107;&#45;&#49;&#125;&#32;&#92;&#101;&#120;&#112;&#92;&#108;&#101;&#102;&#116;&#40;&#45;&#92;&#102;&#114;&#97;&#99;&#123;&#105;&#125;&#123;&#100;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#32;&#61;&#32;&#92;&#101;&#120;&#112;&#32;&#92;&#108;&#101;&#102;&#116;&#40;&#32;&#45;&#92;&#102;&#114;&#97;&#99;&#123;&#49;&#125;&#123;&#100;&#125;&#92;&#115;&#117;&#109;&#95;&#123;&#105;&#61;&#48;&#125;&#94;&#123;&#107;&#45;&#49;&#125;&#32;&#105;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#32;&#61;&#32;&#92;&#101;&#120;&#112;&#92;&#108;&#101;&#102;&#116;&#40;&#45;&#92;&#102;&#114;&#97;&#99;&#123;&#107;&#40;&#107;&#45;&#49;&#41;&#125;&#123;&#50;&#100;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>Thus, we conclude that <p class=\"ql-center-displayed-equation\" style=\"line-height: 43px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-144cfc73d778c4f9ed7442f5a6610e5e_l3.png\" height=\"43\" width=\"505\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#112;&#114;&#111;&#98;&#32;&#92;&#123;&#32;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#92;&#103;&#101;&#32;&#49;&#32;&#92;&#125;&#32;&#92;&#103;&#101;&#32;&#49;&#45;&#92;&#112;&#114;&#111;&#98;&#32;&#92;&#123;&#32;&#106;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#106;&#95;&#107;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#32;&#97;&#114;&#101;&#32;&#100;&#105;&#115;&#116;&#105;&#110;&#99;&#116;&#125;&#32;&#92;&#92;&#125;&#92;&#103;&#101;&#32;&#49;&#45;&#92;&#101;&#120;&#112;&#92;&#108;&#101;&#102;&#116;&#40;&#45;&#92;&#102;&#114;&#97;&#99;&#123;&#107;&#40;&#107;&#45;&#49;&#41;&#125;&#123;&#50;&#100;&#125;&#92;&#114;&#105;&#103;&#104;&#116;&#41;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>Solving this inequality, we conclude that<p class=\"ql-center-displayed-equation\" style=\"line-height: 38px;\"><span class=\"ql-right-eqno\"> &nbsp; <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e11567078a415b79b06a8e5e6f0b1600_l3.png\" height=\"38\" width=\"256\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#091;&#92;&#112;&#114;&#111;&#98;&#92;&#123;&#92;&#118;&#97;&#114;&#101;&#112;&#115;&#105;&#108;&#111;&#110;&#32;&#92;&#103;&#101;&#32;&#49;&#92;&#125;&#32;&#92;&#103;&#101;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#49;&#125;&#123;&#50;&#125;&#32;&#92;&#113;&#117;&#97;&#100;&#32;&#92;&#116;&#101;&#120;&#116;&#123;&#105;&#102;&#125;&#32;&#92;&#113;&#117;&#97;&#100;&#32;&#100;&#32;&#92;&#108;&#101;&#32;&#92;&#102;&#114;&#97;&#99;&#123;&#107;&#40;&#107;&#45;&#49;&#41;&#125;&#123;&#50;&#92;&#108;&#110;&#32;&#50;&#125;&#46;&#92;&#093;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p>This is a quantitative version of our informal theorem from earlier.<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>This is the second of a sequence of two posts on sketching, which I&#8217;m doing on the occasion of my new paper on the numerical stability of the iterative sketching method. For more on what sketching is and how it can be used to solve computational problems, I encourage you to check out the first<a class=\"more-link\" href=\"https:\/\/www.ethanepperly.com\/index.php\/2023\/11\/27\/which-sketch-should-i-use\/\">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,7,12],"tags":[],"class_list":["post-1668","post","type-post","status-publish","format-standard","hentry","category-expository","category-research","category-sketching"],"_links":{"self":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts\/1668","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=1668"}],"version-history":[{"count":20,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts\/1668\/revisions"}],"predecessor-version":[{"id":1800,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts\/1668\/revisions\/1800"}],"wp:attachment":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/media?parent=1668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/categories?post=1668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/tags?post=1668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}