{"id":1430,"date":"2021-03-16T14:56:00","date_gmt":"2021-03-16T14:56:00","guid":{"rendered":"https:\/\/nag.com\/?post_type=insights&#038;p=867"},"modified":"2023-07-05T12:00:45","modified_gmt":"2023-07-05T12:00:45","slug":"the-right-tool-for-the-job-dense-v-sparse","status":"publish","type":"insights","link":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/","title":{"rendered":"The Right Tool for the Job: Dense v Sparse"},"content":{"rendered":"<div class=\"container content-area-default \">\n    <div class=\"row justify-content--center\">\n        <div class=\"col-12 col-md-10 col-lg-8 col-xl-6\">\n            <p>Finding the most suitable solver for your problem can be challenging, but don\u2019t worry! It\u2019s not like finding a needle in a haystack as the decision trees in\u00a0<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/clhtml\/e04\/e04intro.html#dtree\" target=\"_blank\" rel=\"noopener\">Section 5 of <span class=\"nag-n-override\" style=\"margin-left: 0 !important;\"><i>n<\/i><\/span>AG Optimization E04 Chapter Introduction<\/a>\u00a0offer invaluable help. The decision tree will take you through a series of questions that will guide you to the correct solver, starting with<\/p>\n<p><b>Is the problem sparse\/large-scale?<\/b><\/p>\n<p>In this blog, we will demonstrate two types of optimization problem to show the importance of this question and provide guidance on how to answer it.<\/p>\n<h3>What is sparsity?<\/h3>\n<p>We call a matrix sparse if its entries are mostly zero. The data representation for a sparse problem has the form of a sparse matrix which usually defines the linear constraint matrix or Jacobian matrix of the nonlinear constraints. A large-scale problem usually has a fairly large number of variables and constraints, yet only a small number of the constraints involve all variables, and most constraints depend on only small subsets of the variables. Thus, the problem is sparse. Figure 1 depicts the sparsity pattern of a sparse matrix of dimension <b>\\(n=3948\\)<\/b> we can see it is fairly sparse as the <strong>\\(density = nnz \/ n2 = 0.756\\%\\) <\/strong>is below <strong>\\(1\\%\\).<\/strong><\/p>\n<p><strong><span class=\"cmbx-10\">Capturing and passing the sparse structure of a problem, if it exists, to the right solver is essential as<\/span>\u00a0<span class=\"cmbx-10\">the specialized solver takes advantage of the sparse structure of the matrix and avoids wasting<\/span>\u00a0<span class=\"cmbx-10\">computation and memory on the zeros<\/span><\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-845 size-full\" src=\"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/sppattern.png\" alt=\"\" width=\"780\" height=\"600\" \/><\/p>\n<h3>Impact of sparsity on Cholesky factorization<\/h3>\n<p>To highlight the importance of exploiting the sparsity of a problem, let\u2019s see an example of\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Cholesky_decomposition\" target=\"_blank\" rel=\"noopener\">Cholesky factorization<\/a>\u00a0which is widely used in numerical algorithms such as Interior Point Method (IPM) in convex optimization. All large-scale optimization solvers in the world exploit the sparsity pattern very carefully during matrix factorization to achieve both numerical stability and efficiency.<\/p>\n<p>The Cholesky factorization of a real symmetric positive definite matrix <strong>\\(M\\)<\/strong> is to find a factor \\(L\\) such that <strong><span style=\"color: #232331; font-family: Nunito Sans, Helvetica Neue, Helvetica, Arial, sans-serif;\"><span style=\"letter-spacing: normal; white-space: nowrap;\">\\(M = LL^T\\)<\/span><\/span><\/strong>, where <strong>\\(L\\)<\/strong> is a lower triangular matrix. We have selected 9 positive definite matrices in the Matrix Market [1] that arise from disciplines such as structural engineering and structural mechanics. As shown in Table 1, all of the matrices are fairly sparse with density of less than <strong>\\(1.5\\%\\).<\/strong><\/p>\n<table style=\"border-collapse: collapse; width: 100%; height: 270px;\">\n<tbody>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">Prob. ID<\/td>\n<td style=\"width: 20%; height: 27px;\">Matrix<\/td>\n<td style=\"width: 20%; height: 27px;\"><strong>\\(n\\)<\/strong><\/td>\n<td style=\"width: 20%; height: 27px;\"><strong>\\(nnz\\)<\/strong><\/td>\n<td style=\"width: 20%; height: 27px;\">Density(%)<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">1<\/td>\n<td id=\"TBL-2-2-2\" class=\"td11\" style=\"width: 20%; height: 27px;\">bcsstk15<\/td>\n<td style=\"width: 20%; height: 27px;\">3948<\/td>\n<td style=\"width: 20%; height: 27px;\">117816<\/td>\n<td style=\"width: 20%; height: 27px;\">0.756<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">2<\/td>\n<td style=\"width: 20%; height: 27px;\">bcsstk16<\/td>\n<td style=\"width: 20%; height: 27px;\">4884<\/td>\n<td style=\"width: 20%; height: 27px;\">290378<\/td>\n<td style=\"width: 20%; height: 27px;\">1.217<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">3<\/td>\n<td id=\"TBL-2-4-2\" class=\"td11\" style=\"width: 20%; height: 27px;\">s1rmt3m1<\/td>\n<td style=\"width: 20%; height: 27px;\">5489<\/td>\n<td style=\"width: 20%; height: 27px;\">217651<\/td>\n<td id=\"TBL-2-4-5\" class=\"td11\" style=\"width: 20%;\">0.722<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">4<\/td>\n<td id=\"TBL-2-5-2\" class=\"td11\" style=\"width: 20%; height: 27px;\">s2rmt3m1<\/td>\n<td style=\"width: 20%; height: 27px;\">5489<\/td>\n<td style=\"width: 20%; height: 27px;\">217681<\/td>\n<td id=\"TBL-2-5-5\" class=\"td11\" style=\"width: 20%;\">0.722<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">5<\/td>\n<td style=\"width: 20%; height: 27px;\">s1rmq4m1<\/td>\n<td style=\"width: 20%; height: 27px;\">5489<\/td>\n<td id=\"TBL-2-6-4\" class=\"td11\" style=\"width: 20%;\">262411<\/td>\n<td id=\"TBL-2-6-5\" class=\"td11\" style=\"width: 20%;\">0.871<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">6<\/td>\n<td style=\"width: 20%; height: 27px;\">s3rmq4m1<\/td>\n<td style=\"width: 20%; height: 27px;\">5489<\/td>\n<td id=\"TBL-2-7-4\" class=\"td11\" style=\"width: 20%;\">262943<\/td>\n<td id=\"TBL-2-7-5\" class=\"td11\" style=\"width: 20%;\">0.873<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">7<\/td>\n<td style=\"width: 20%; height: 27px;\">s2rmq4m1<\/td>\n<td style=\"width: 20%; height: 27px;\">5489<\/td>\n<td style=\"width: 20%; height: 27px;\">263351<\/td>\n<td id=\"TBL-2-8-5\" class=\"td11\" style=\"width: 20%;\">0.874<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">8<\/td>\n<td style=\"width: 20%; height: 27px;\">bcsstk17<\/td>\n<td style=\"width: 20%; height: 27px;\">10974<\/td>\n<td id=\"TBL-2-9-4\" class=\"td11\" style=\"width: 20%;\">428650<\/td>\n<td id=\"TBL-2-9-1\" class=\"td11\" style=\"width: 20%;\">0.356<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">9<\/td>\n<td style=\"width: 20%; height: 27px;\">bcsstk18<\/td>\n<td style=\"width: 20%; height: 27px;\">11948<\/td>\n<td style=\"width: 20%; height: 27px;\">149090<\/td>\n<td style=\"width: 20%; height: 27px;\">0.104<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"para-sm\"><strong>Table\u00a01<\/strong>:\u00a0<span class=\"content\">Statistics on 9 sparse matrices used to test dense and sparse Cholesky factorization. <strong>\\(n\\)<\/strong> number of variables, <strong>\\(nnz\\) <\/strong><\/span><span style=\"font-size: 1.6rem; letter-spacing: 0.03em; word-spacing: normal; white-space: nowrap;\">number of nonzeros, density:= <\/span><strong style=\"font-size: 1.6rem; letter-spacing: 0.03em; word-spacing: normal; white-space: nowrap;\">\\(nnz \/ n^2)\\)<\/strong><span style=\"font-size: 1.6rem; letter-spacing: 0.03em; word-spacing: normal; white-space: nowrap;\">\u00a0<\/span><\/p>\n<p>As discussed before, storing only nonzero entries will reduce memory requirements and exploiting the sparsity pattern will reduce the computational cost greatly. To illustrate this point, we have tested both sparse and dense Cholesky routines on the selected dataset and the result is shown in Figure 2. As we can see, overall the sparse Cholesky is faster than the dense one for all test cases. The reason is not hard to imagine as<strong>\u00a0<span class=\"cmbx-10\">the dense algorithm is<\/span>\u00a0<span class=\"cmbx-10\">linked to the dimension of the matrix, whereas the sparse algorithm is mainly connected to<\/span>\u00a0<span class=\"cmbx-10\">the number of nonzeros<\/span><\/strong>. A huge loss in performance from the dense algorithm appears for problem 8 and <span id=\"MathJax-Element-25-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; display: inline; font-style: normal; font-weight: 400; line-height: normal; font-size: 16px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: 0px; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; color: #232331; font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;inline&quot;&gt;&lt;mn&gt;9&lt;\/mn&gt;&lt;\/math&gt;\"><span id=\"MathJax-Span-124\" class=\"math\"><span id=\"MathJax-Span-125\" class=\"mrow\"><span id=\"MathJax-Span-126\" class=\"mn\">9 <\/span><\/span><\/span><\/span>due to the big jump in problem size, yet from its sparse counterpart, there is uniformly good performance as the density remains pretty low across all test cases.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-899 size-full\" src=\"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/chol_plot_bar.png\" alt=\"sparse and dense factorization\" width=\"819\" height=\"603\" \/><\/p>\n<p class=\"para-sm\"><strong>Figure\u00a02<\/strong>:\u00a0<span class=\"content\">Computational time comparison between sparse and dense Cholesky<\/span><\/p>\n<p>To further illustrate how sparsity affects the performance of an algorithm, we randomly generated symmetric positive definite matrices of size 1000, 3000 and 5000. For matrices of a certain size, the density varies from 10% to 100%. Then both sparse and dense Cholesky were called to factorize the matrices and the computational time comparison can be found in Figure\u00a03. Unsurprisingly, for matrices of the same size, the time for dense Cholesky doesn\u2019t vary too much even as the density increases. However, sparse Cholesky uses more and more time as the matrix gets denser, and at some point, it will require more computational time than the dense algorithm.\u00a0<strong>For matrices with relatively high density (such as 20% and above), the tradeoff is no longer viable and the dense counterpart becomes a better choice<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-906 size-full\" src=\"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/chol_den.png\" alt=\"Comparison of factorization methods on matrices\" width=\"1347\" height=\"566\" \/><\/p>\n<p class=\"para-sm\"><strong>Figure\u00a03:\u00a0<\/strong><span class=\"content\">Comparison of factorization methods on matrices of size 1000, 3000, 5000: various density<\/span><\/p>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n<div style=\"height:69px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"container content-area-default \">\n    <div class=\"row justify-content--center\">\n        <div class=\"col-12 col-md-10 col-lg-8 col-xl-6\">\n            <h3>Example in Linear Programming (LP)<\/h3>\n<p>A general LP problem has a standard form:<\/p>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n<math class=\"equation\" xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"block\">\n  <mtable class=\"array\" columnlines=\"none\" equalcolumns=\"false\" equalrows=\"false\" style=\"text-align:axis;\">\n    <mtr>\n      <mtd class=\"array\" columnalign=\"left\">\n        <munder>\n          <mrow>\n            <mstyle class=\"mbox\">\n              <mtext>minimize<\/mtext>\n            <\/mstyle>\n          <\/mrow>\n          <mrow>\n            <mi>x<\/mi>\n            <mo class=\"MathClass-rel\">&#x2208;<\/mo>\n            <msup>\n              <mrow>\n                <mi>&#x211C;<\/mi>\n              <\/mrow>\n              <mrow>\n                <mi>n<\/mi>\n              <\/mrow>\n            <\/msup>\n          <\/mrow>\n        <\/munder>\n      <\/mtd>\n      <mtd class=\"array\" columnalign=\"left\">\n        <msup>\n          <mrow>\n            <mi>c<\/mi>\n          <\/mrow>\n          <mrow>\n            <mi>T<\/mi>\n          <\/mrow>\n        <\/msup>\n        <mi>x<\/mi>\n      <\/mtd>\n    <\/mtr>\n    <mtr class=\"vspace\" style=\"font-size:2.58334pt\">\n      <mtd \/>\n      <mtd \/>\n    <\/mtr>\n    <mtr>\n      <mtd class=\"array\" columnalign=\"left\">\n        <mstyle class=\"mbox\">\n          <mtext>subject&#xA0;to<\/mtext>\n        <\/mstyle>\n      <\/mtd>\n      <mtd class=\"array\" columnalign=\"left\">\n        <mi>A<\/mi>\n        <mi>x<\/mi>\n        <mo class=\"MathClass-rel\">=<\/mo>\n        <mi>b<\/mi>\n        <mo class=\"MathClass-punc\">,<\/mo>\n      <\/mtd>\n    <\/mtr>\n    <mtr class=\"vspace\" style=\"font-size:2.58334pt\">\n      <mtd \/>\n      <mtd \/>\n    <\/mtr>\n    <mtr>\n      <mtd class=\"array\" columnalign=\"left\" \/>\n      <mtd class=\"array\" columnalign=\"left\">\n        <mi>x<\/mi>\n        <mo class=\"MathClass-rel\">&#x2265;<\/mo>\n        <mn>0<\/mn>\n        <mo class=\"MathClass-punc\">.<\/mo>\n      <\/mtd>\n    <\/mtr>\n  <\/mtable>\n<\/math>\n\n\n<div class=\"container content-area-default \">\n    <div class=\"row justify-content--center\">\n        <div class=\"col-12 col-md-10 col-lg-8 col-xl-6\">\n            <p>Here we used two active-set methods\u00a0<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/clhtml\/e04\/e04mfc.html\" target=\"_blank\" rel=\"noopener\"><span class=\"cmtt-10\">lp<\/span><span class=\"cmtt-10\">_solve<\/span><\/a>\u00a0(<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/flhtml\/e04\/e04mff.html\" target=\"_blank\" rel=\"noopener\"><span class=\"cmtt-10\">e04mf<\/span><\/a>) (dense solver) and\u00a0<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/clhtml\/e04\/e04nqc.html\" target=\"_blank\" rel=\"noopener\"><span class=\"cmtt-10\">qpconvex2<\/span><span class=\"cmtt-10\">_sparse<\/span><span class=\"cmtt-10\">_solve<\/span><\/a>\u00a0(<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/flhtml\/e04\/e04nqf.html\" target=\"_blank\" rel=\"noopener\"><span class=\"cmtt-10\">e04nq<\/span><\/a>) (sparse solver) from the\u00a0<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/\" target=\"_blank\" rel=\"noopener\"><span class=\"nag-n-override\" style=\"margin-left: 0 !important;\"><i>n<\/i><\/span>AG Library<\/a> to solve the above model and the results are shown in Table 2.\u00a0Both test cases have a density less than\u00a0<span id=\"MathJax-Element-29-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; display: inline; font-style: normal; font-weight: 400; line-height: normal; font-size: 16px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: 0px; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; color: #232331; font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;inline&quot;&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;mo class=&quot;MathClass-punc&quot;&gt;.&lt;\/mo&gt;&lt;mn&gt;0&lt;\/mn&gt;&lt;mi&gt;%&lt;\/mi&gt;&lt;\/math&gt;\"><span id=\"MathJax-Span-192\" class=\"math\"><span id=\"MathJax-Span-193\" class=\"mrow\"><span id=\"MathJax-Span-194\" class=\"mn\">1<\/span><span id=\"MathJax-Span-195\" class=\"mo MathClass-punc\">.<\/span><span id=\"MathJax-Span-196\" class=\"mn\">0<\/span><span id=\"MathJax-Span-197\" class=\"mi\">%<\/span><\/span><\/span><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"inline\"><mn>\u00a0<\/mn><mi><br \/><\/mi><\/math><\/span><\/span>and <a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/flhtml\/e04\/e04nqf.html\" target=\"_blank\" rel=\"noopener\"><span class=\"cmtt-10\">e04nq<\/span><\/a>\u00a0spent less than 1 second for each case while the dense solver was significantly slower. Therefore,\u00a0<strong><span class=\"cmbx-10\">passing a<\/span>\u00a0<span class=\"cmbx-10\">sparse problem to a dense solver will completely kill your performance<\/span><\/strong>.<\/p>\n<table style=\"border-collapse: collapse; width: 100%; height: 108px;\">\n<tbody>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">Problem<\/td>\n<td style=\"width: 20%; text-align: center; height: 27px;\">n\u00a0 \u00a0 m<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">nnz\u00a0 Density<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">e04mf<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">e04nq<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">\u00a0<\/td>\n<td style=\"width: 20%; height: 27px;\">\u00a0<\/td>\n<td style=\"width: 20%; height: 27px;\">\u00a0<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">Iter\u00a0 \u00a0Time<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">Iter\u00a0 \u00a0 Time<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">25fv47<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">1571\u00a0 821<\/td>\n<td style=\"width: 20%; height: 27px;\">11127\u00a0 \u00a00.86%<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">8030\u00a0 36.9s<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">6923\u00a0 0.46s<\/td>\n<\/tr>\n<tr style=\"height: 27px;\">\n<td style=\"width: 20%; height: 27px;\">bnl2<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">3489\u00a0 \u00a02324<\/td>\n<td style=\"width: 20%; height: 27px;\">16124\u00a0 \u00a00.2%<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">7568. 229.1s<\/td>\n<td style=\"width: 20%; height: 27px; text-align: center;\">4560\u00a0 0.58s<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n<div class=\"container content-area-default \">\n    <div class=\"row justify-content--center\">\n        <div class=\"col-12 col-md-10 col-lg-8 col-xl-6\">\n            <h3>Be prepared for the surprise from dedicated solvers<\/h3>\n<p>Recently, a\u00a0<a href=\"https:\/\/www.nag.com\/numeric\/nl\/nagdoc_latest\/\" target=\"_blank\" rel=\"noopener\"><span class=\"nag-n-override\" style=\"margin-left: 0 !important;\"><i>n<\/i><\/span>AG Library<\/a>\u00a0user contacted our\u00a0<a href=\"https:\/\/www.nag.com\/content\/nag-technical-support-service#contact\" target=\"_blank\" rel=\"noopener\">Technical Support team<\/a> with the following <strong>\\(1_{1}\\)<\/strong>\u00a0<span id=\"MathJax-Element-30-Frame\" class=\"MathJax\" style=\"box-sizing: border-box; display: inline; font-style: normal; font-weight: 400; line-height: normal; font-size: 16px; text-indent: 0px; text-align: left; text-transform: none; letter-spacing: normal; word-spacing: 0px; overflow-wrap: normal; white-space: nowrap; float: none; direction: ltr; max-width: none; max-height: none; min-width: 0px; min-height: 0px; border: 0px; padding: 0px; margin: 0px; color: #232331; font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-variant-ligatures: normal; font-variant-caps: normal; orphans: 2; widows: 2; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; position: relative;\" tabindex=\"0\" role=\"presentation\" data-mathml=\"&lt;math xmlns=&quot;http:\/\/www.w3.org\/1998\/Math\/MathML&quot; display=&quot;inline&quot;&gt;&lt;msub&gt;&lt;mrow&gt;&lt;mi&gt;l&lt;\/mi&gt;&lt;\/mrow&gt;&lt;mrow&gt;&lt;mn&gt;1&lt;\/mn&gt;&lt;\/mrow&gt;&lt;\/msub&gt;&lt;\/math&gt;\"><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"inline\"><msub><mrow><mn><br \/><\/mn><\/mrow><\/msub><\/math><\/span><\/span>linear fitting problem<\/p>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n<math class=\"equation\" xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"block\">\n  <mtable class=\"array\" columnlines=\"none\" equalcolumns=\"false\" equalrows=\"false\" style=\"text-align:axis;\">\n    <mtr>\n      <mtd class=\"array\" columnalign=\"left\">\n        <munder>\n          <mrow>\n            <mstyle class=\"mbox\">\n              <mtext>minimize<\/mtext>\n            <\/mstyle>\n          <\/mrow>\n          <mrow>\n            <mi>x<\/mi>\n            <mo class=\"MathClass-rel\">&#x2208;<\/mo>\n            <msup>\n              <mrow>\n                <mi>&#x211C;<\/mi>\n              <\/mrow>\n              <mrow>\n                <mi>n<\/mi>\n              <\/mrow>\n            <\/msup>\n          <\/mrow>\n        <\/munder>\n      <\/mtd>\n      <mtd class=\"array\" columnalign=\"left\">\n        <mo class=\"MathClass-rel\">&#x2225;<\/mo>\n        <mi>A<\/mi>\n        <mi>x<\/mi>\n        <mo class=\"MathClass-bin\">&#8211;<\/mo>\n        <mi>b<\/mi>\n        <msub>\n          <mrow>\n            <mo class=\"MathClass-rel\">&#x2225;<\/mo>\n          <\/mrow>\n          <mrow>\n            <mn>1<\/mn>\n          <\/mrow>\n        <\/msub>\n      <\/mtd>\n    <\/mtr>\n  <\/mtable>\n<\/math>\n\n\n<div class=\"container content-area-default \">\n    <div class=\"row justify-content--center\">\n        <div class=\"col-12 col-md-10 col-lg-8 col-xl-6\">\n            <p>where matrix <strong>\\(A\\)<\/strong> is tall and slim, e.g., of dimension 1000 x 21 and full dense matrix. At first glance, it might appear to be a dense problem as there are no zeros in the problem data <strong>\\(A\\) <\/strong>and<strong> \\(b\\). <\/strong>The<strong> \\(1_{1}\\) <\/strong>norm minimization can be reformulated to Linear Programming, so the user performed the transformation and used active-set methods <a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/clhtml\/e04\/e04mfc.html\" target=\"_blank\" rel=\"noopener\">lp_solve<\/a> (<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/flhtml\/e04\/e04mff.html\" target=\"_blank\" rel=\"noopener\">e04mf<\/a>) (dense solver). However, the solver was not as fast as he expected and the user sought our advice.<\/p>\n<p>This type of misunderstanding and confusion is not unusual and care needs to be taken. In order to decide whether the problem is sparse or dense, we need to consider the data of the problem model that the solver solves, not the original data. For instance, problem 2 can be reformulated into LP problem<\/p>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n<math class=\"equation\" xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"block\">\n  <mtable class=\"array\" columnlines=\"none\" equalcolumns=\"false\" equalrows=\"false\" style=\"text-align:axis;\">\n    <mtr>\n      <mtd class=\"array\" columnalign=\"left\">\n        <munder>\n          <mrow>\n            <mstyle class=\"mbox\">\n              <mtext>minimize<\/mtext>\n            <\/mstyle>\n          <\/mrow>\n          <mrow>\n            <mi>x<\/mi>\n            <mo class=\"MathClass-rel\">&#x2208;<\/mo>\n            <msup>\n              <mrow>\n                <mi>&#x211C;<\/mi>\n              <\/mrow>\n              <mrow>\n                <mi>n<\/mi>\n              <\/mrow>\n            <\/msup>\n            <mo class=\"MathClass-punc\">,<\/mo>\n            <mi>y<\/mi>\n            <mo class=\"MathClass-rel\">&#x2208;<\/mo>\n            <msup>\n              <mrow>\n                <mi>&#x211C;<\/mi>\n              <\/mrow>\n              <mrow>\n                <mi>m<\/mi>\n              <\/mrow>\n            <\/msup>\n          <\/mrow>\n        <\/munder>\n      <\/mtd>\n      <mtd class=\"array\" columnalign=\"left\">\n        <munder class=\"msub\">\n          <mrow>\n            <mo mathsize=\"big\">&#x2211;<\/mo>\n          <\/mrow>\n          <mrow>\n            <mi>i<\/mi>\n          <\/mrow>\n        <\/munder>\n        <msub>\n          <mrow>\n            <mi>y<\/mi>\n          <\/mrow>\n          <mrow>\n            <mi>i<\/mi>\n          <\/mrow>\n        <\/msub>\n      <\/mtd>\n    <\/mtr>\n    <mtr class=\"vspace\" style=\"font-size:2.58334pt\">\n      <mtd \/>\n      <mtd \/>\n    <\/mtr>\n    <mtr>\n      <mtd class=\"array\" columnalign=\"left\">\n        <mstyle class=\"mbox\">\n          <mtext>subject&#xA0;to<\/mtext>\n        <\/mstyle>\n      <\/mtd>\n      <mtd class=\"array\" columnalign=\"left\">\n        <mo class=\"MathClass-bin\">&#8211;<\/mo>\n        <mi>y<\/mi>\n        <mo class=\"MathClass-rel\">&#x2264;<\/mo>\n        <mi>A<\/mi>\n        <mi>x<\/mi>\n        <mo class=\"MathClass-bin\">&#8211;<\/mo>\n        <mi>b<\/mi>\n        <mo class=\"MathClass-rel\">&#x2264;<\/mo>\n        <mi>y<\/mi>\n        <mo class=\"MathClass-punc\">,<\/mo>\n      <\/mtd>\n    <\/mtr>\n    <mtr class=\"vspace\" style=\"font-size:2.58334pt\">\n      <mtd \/>\n      <mtd \/>\n    <\/mtr>\n    <mtr>\n      <mtd class=\"array\" columnalign=\"left\" \/>\n      <mtd class=\"array\" columnalign=\"left\">\n        <mi>y<\/mi>\n        <mo class=\"MathClass-rel\">&#x2265;<\/mo>\n        <mn>0<\/mn>\n        <mo class=\"MathClass-punc\">.<\/mo>\n      <\/mtd>\n    <\/mtr>\n  <\/mtable>\n<\/math>\n\n\n<div class=\"container content-area-default \">\n    <div class=\"row justify-content--center\">\n        <div class=\"col-12 col-md-10 col-lg-8 col-xl-6\">\n            <p>Taking a closer look at the inequality constraints<\/p>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\" display=\"block\">\n  <mo class=\"MathClass-bin\">&#8211;<\/mo>\n  <mi>y<\/mi>\n  <mo class=\"MathClass-rel\">&#x2264;<\/mo>\n  <mi>A<\/mi>\n  <mi>x<\/mi>\n  <mo class=\"MathClass-bin\">&#8211;<\/mo>\n  <mi>b<\/mi>\n  <mo class=\"MathClass-rel\">&#x2264;<\/mo>\n  <mi>y<\/mi>\n  <mspace class=\"quad\" width=\"1em\" \/>\n  <mo class=\"MathClass-rel\">&#x21D4;<\/mo>\n  <mspace class=\"quad\" width=\"1em\" \/>\n  <mfenced close=\")\" open=\"(\" separators=\"\">\n    <mrow>\n      <mtable class=\"array\" columnlines=\"none none none none none none none none none\" equalcolumns=\"false\" equalrows=\"false\" style=\"text-align:axis;\">\n        <mtr>\n          <mtd class=\"array\" columnalign=\"center\">\n            <mi>A<\/mi>\n          <\/mtd>\n          <mtd class=\"array\" columnalign=\"center\">\n            <mo class=\"MathClass-bin\">&#8211;<\/mo>\n            <mi>I<\/mi>\n          <\/mtd>\n        <\/mtr>\n        <mtr>\n          <mtd class=\"array\" columnalign=\"center\">\n            <mo class=\"MathClass-bin\">&#8211;<\/mo>\n            <mi>A<\/mi>\n          <\/mtd>\n          <mtd class=\"array\" columnalign=\"center\">\n            <mo class=\"MathClass-bin\">&#8211;<\/mo>\n            <mi>I<\/mi>\n          <\/mtd>\n        <\/mtr>\n      <\/mtable>\n    <\/mrow>\n  <\/mfenced>\n  <mfenced close=\")\" open=\"(\" separators=\"\">\n    <mrow>\n      <mtable class=\"array\" columnlines=\"none none none none none none none none none\" equalcolumns=\"false\" equalrows=\"false\" style=\"text-align:axis;\">\n        <mtr>\n          <mtd class=\"array\" columnalign=\"center\">\n            <mi>x<\/mi>\n          <\/mtd>\n        <\/mtr>\n        <mtr>\n          <mtd class=\"array\" columnalign=\"center\">\n            <mi>y<\/mi>\n          <\/mtd>\n        <\/mtr>\n      <\/mtable>\n    <\/mrow>\n  <\/mfenced>\n  <mo class=\"MathClass-rel\">&#x2264;<\/mo>\n  <mfenced close=\")\" open=\"(\" separators=\"\">\n    <mrow>\n      <mtable class=\"array\" columnlines=\"none none none none none none none none none\" equalcolumns=\"false\" equalrows=\"false\" style=\"text-align:axis;\">\n        <mtr>\n          <mtd class=\"array\" columnalign=\"center\">\n            <mi>b<\/mi>\n          <\/mtd>\n        <\/mtr>\n        <mtr>\n          <mtd class=\"array\" columnalign=\"center\">\n            <mo class=\"MathClass-bin\">&#8211;<\/mo>\n            <mi>b<\/mi>\n          <\/mtd>\n        <\/mtr>\n      <\/mtable>\n    <\/mrow>\n  <\/mfenced>\n  <mo class=\"MathClass-punc\">,<\/mo>\n<\/math>\n\n\n<div class=\"container content-area-default \">\n    <div class=\"row justify-content--center\">\n        <div class=\"col-12 col-md-10 col-lg-8 col-xl-6\">\n            <p style=\"text-align: left;\">where <strong>\\(I\\)\u00a0<\/strong>is the identity matrix of dimension <strong>\\(m\\)<\/strong>, we can see the number of variables has increased by <strong>\\(m\\) <\/strong>and many zero entries have been introduced to the model. Thus, a sparse LP solver should be chosen for this particular model. We tested it with a matrix <strong>\\(A\\)\u00a0<\/strong>of dimension 1000 x 21 using the active-set method solver <a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/clhtml\/e04\/e04mfc.html\" target=\"_blank\" rel=\"noopener\">lp_solve<\/a> (<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/flhtml\/e04\/e04mff.html\" target=\"_blank\" rel=\"noopener\">e04mf<\/a>) and sparse Interior Point Method solver <a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/clhtml\/e04\/e04mtc.html\" target=\"_blank\" rel=\"noopener\">handle_solve_lp_ipm<\/a> (<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/flhtml\/e04\/e04mtf.html\" target=\"_blank\" rel=\"noopener\">e04mt<\/a>) from the <a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/\" target=\"_blank\" rel=\"noopener\"><span class=\"nag-n-override\" style=\"margin-left: 0 !important;\"><i>n<\/i><\/span>AG Library<\/a>. As we can see in Table 3, the sparse LP solver again shows great performance compared to the dense solver.<\/p>\n<table style=\"border-collapse: collapse; width: 100%;\">\n<tbody>\n<tr>\n<td style=\"width: 25%;\">Solver<\/td>\n<td style=\"width: 25%;\">e04mf<\/td>\n<td style=\"width: 25%;\">e04mt<\/td>\n<td style=\"width: 25%;\">e02ga<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 25%;\">Time<\/td>\n<td style=\"width: 25%;\">49.7s<\/td>\n<td style=\"width: 25%;\"><strong><span style=\"color: #ff7d21;\">0.18s<\/span><\/strong><\/td>\n<td style=\"width: 25%;\"><strong><span style=\"color: #ff7d21;\">0.007s<\/span><\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"para-sm\"><strong>Table\u00a03<\/strong>: Three solvers for <strong>\\(1_{1}\\)<\/strong> linear fitting problem<\/p>\n<p>Clearly, the sparse solver is the reason for the improved computation time. However, the dedicated solver <a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/clhtml\/e02\/e02gac.html\" target=\"_blank\" rel=\"noopener\">glin_l1sol<\/a> (<a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/flhtml\/e02\/e02gaf.html\" target=\"_blank\" rel=\"noopener\">e02ga<\/a>) for problem (2) did an even better job than the sparse LP solver, since it exploits thoroughly the known problem structure.\u00a0<strong><span class=\"cmbx-10\">Overall the dedicated solver delivered a 7100x speedup over the original attempt. <\/span><\/strong><span class=\"cmbx-10\">Therefore, it is always recommended to try a dedicated solver first for a particular problem. Dedicated solvers are slightly out of the scope of this blog, please see\u00a0<\/span><span class=\"cmbx-10\"><a href=\"https:\/\/support.nag.com\/numeric\/nl\/nagdoc_latest\/\" target=\"_blank\" rel=\"noopener\"><span class=\"nag-n-override\" style=\"margin-left: 0 !important;\"><i>n<\/i><\/span>AG Library documentation<\/a>\u00a0for the full content of <span class=\"nag-n-override\" style=\"margin-left: 0 !important;\"><i>n<\/i><\/span>AG offerings in dedicated solvers.<\/span><\/p>\n<h3>Things to remember<\/h3>\n<p>Sparsity is a great feature and should be considered carefully.<\/p>\n<ul>\n<li>Choose a sparse solver if there is an underlying sparse structure in your problem. Otherwise, you will significantly harm your performance.<\/li>\n<li>It\u2019s important to\u00a0<strong>analyse the data structure<\/strong>\u00a0that the solver sees instead of original data if reformulation is involved.<\/li>\n<li>Don\u2019t forget to\u00a0<strong>search for a dedicated solver first<\/strong>!<\/li>\n<\/ul>\n<p>To see all the previous blogs, please go\u00a0<a href=\"https:\/\/support.nag.com\/content\/nag-blog\">here<\/a>. You can also find various examples through our\u00a0<a href=\"https:\/\/github.com\/numericalalgorithmsgroup\/NAGPythonExamples\/tree\/master\/local_optimization\" target=\"_blank\" rel=\"noopener\">GitHub Local optimisation<\/a>\u00a0page. See you in the next blog.<\/p>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n<div class=\"gbc-title-banner tac tac-lg tac-xl\" style='border-radius: 0px; '>\n    <div class=\"container\" style='border-radius: 0px; '>\n        <div class=\"row justify-content--center\" >\n            <div class=\"col-12\"  >\n                <div class=\"wrap pv-4 \" style=\"0pxbackground-color: \">\n                                <div class=\"col-12 col-md-10 col-lg-8 col-xl-6  banner-content\"  >\n    \n                    \n                    <div class=\"mt-1 mb-1 content\"><\/div>\n\n                    \n                    <a href='https:\/\/nag.com\/mathematical-optimization\/' style='background-color: #ff7d21ff; color: #ffffffff; border-radius: 30px; font-weight: 600; ' class='btn mr-1  ' >Mathematical Optimization Solutions <i class='fas fa-angle-right'><\/i><\/a>                <\/div>\n                <\/div>\n            <\/div>\n        <\/div>\n    <\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-buttons has-custom-font-size has-medium-font-size is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-16018d1d wp-block-buttons-is-layout-flex\" id=\"mathematicaloptimization\"><\/div>\n\n\n<div class=\"container content-area-default \">\n    <div class=\"row justify-content--center\">\n        <div class=\"col-12 col-md-10 col-lg-8 col-xl-6\">\n            <h3>References<\/h3>\n<div class=\"bs-region bs-region--main\">\n<div class=\"field field--name-field-paragraph field--type-entity-reference-revisions field--label-hidden field--items\">\n<div class=\"paragraph--color--blue paragraph--alignment--left paragraph paragraph--type--text paragraph--view-mode--default\">\n<div class=\"field field--name-field-paragraph-text field--type-text-long field--label-hidden field--item\">\n<p>[1] Ronald F Boisvert, Roldan Pozo, Karin Remington, Richard F Barrett, and Jack J Dongarra. Matrix market: a web resource for test matrix collections. In Quality of Numerical Software, pages 125\u2013137. Springer, 1997.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"section-wrapper bs-region bs-region--bottom\">\n<div class=\"field field--name-field-author field--type-entity-reference field--label-above\">\u00a0<\/div>\n<\/div>\n        <\/div>\n    <\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Finding the most suitable solver for your problem can be challenging, but don\u2019t worry! In this blog, we will demonstrate two types of optimization problem to show the importance of this question, and provide guidance on how to answer it.<\/p>\n","protected":false},"author":7,"featured_media":868,"parent":0,"menu_order":0,"template":"","meta":{"content-type":"","footnotes":""},"post-tag":[21],"class_list":["post-1430","insights","type-insights","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The Right Tool for the Job: Dense v Sparse - nAG<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The Right Tool for the Job: Dense v Sparse - nAG\" \/>\n<meta property=\"og:description\" content=\"Finding the most suitable solver for your problem can be challenging, but don\u2019t worry! In this blog, we will demonstrate two types of optimization problem to show the importance of this question, and provide guidance on how to answer it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/\" \/>\n<meta property=\"og:site_name\" content=\"nAG\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-05T12:00:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/optimization-corner2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2117\" \/>\n\t<meta property=\"og:image:height\" content=\"1237\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@NAGTalk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/\",\"url\":\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/\",\"name\":\"The Right Tool for the Job: Dense v Sparse - nAG\",\"isPartOf\":{\"@id\":\"https:\/\/nag.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/optimization-corner2.png\",\"datePublished\":\"2021-03-16T14:56:00+00:00\",\"dateModified\":\"2023-07-05T12:00:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#primaryimage\",\"url\":\"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/optimization-corner2.png\",\"contentUrl\":\"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/optimization-corner2.png\",\"width\":2117,\"height\":1237},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/nag.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Insights\",\"item\":\"https:\/\/nag.com\/insights\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"The Right Tool for the Job: Dense v Sparse\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/nag.com\/#website\",\"url\":\"https:\/\/nag.com\/\",\"name\":\"NAG\",\"description\":\"Robust, trusted numerical software and computational expertise.\",\"publisher\":{\"@id\":\"https:\/\/nag.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/nag.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/nag.com\/#organization\",\"name\":\"Numerical Algorithms Group\",\"alternateName\":\"NAG\",\"url\":\"https:\/\/nag.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/nag.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/nag.com\/wp-content\/uploads\/2023\/11\/NAG-Logo.png\",\"contentUrl\":\"https:\/\/nag.com\/wp-content\/uploads\/2023\/11\/NAG-Logo.png\",\"width\":1244,\"height\":397,\"caption\":\"Numerical Algorithms Group\"},\"image\":{\"@id\":\"https:\/\/nag.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/NAGTalk\",\"https:\/\/www.linkedin.com\/company\/nag\/\",\"https:\/\/www.youtube.com\/user\/NumericalAlgorithms\",\"https:\/\/github.com\/numericalalgorithmsgroup\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The Right Tool for the Job: Dense v Sparse - nAG","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/","og_locale":"en_US","og_type":"article","og_title":"The Right Tool for the Job: Dense v Sparse - nAG","og_description":"Finding the most suitable solver for your problem can be challenging, but don\u2019t worry! In this blog, we will demonstrate two types of optimization problem to show the importance of this question, and provide guidance on how to answer it.","og_url":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/","og_site_name":"nAG","article_modified_time":"2023-07-05T12:00:45+00:00","og_image":[{"width":2117,"height":1237,"url":"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/optimization-corner2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@NAGTalk","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/","url":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/","name":"The Right Tool for the Job: Dense v Sparse - nAG","isPartOf":{"@id":"https:\/\/nag.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#primaryimage"},"image":{"@id":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#primaryimage"},"thumbnailUrl":"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/optimization-corner2.png","datePublished":"2021-03-16T14:56:00+00:00","dateModified":"2023-07-05T12:00:45+00:00","breadcrumb":{"@id":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#primaryimage","url":"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/optimization-corner2.png","contentUrl":"https:\/\/nag.com\/wp-content\/uploads\/2023\/05\/optimization-corner2.png","width":2117,"height":1237},{"@type":"BreadcrumbList","@id":"https:\/\/nag.com\/insights\/the-right-tool-for-the-job-dense-v-sparse\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nag.com\/"},{"@type":"ListItem","position":2,"name":"Insights","item":"https:\/\/nag.com\/insights\/"},{"@type":"ListItem","position":3,"name":"The Right Tool for the Job: Dense v Sparse"}]},{"@type":"WebSite","@id":"https:\/\/nag.com\/#website","url":"https:\/\/nag.com\/","name":"NAG","description":"Robust, trusted numerical software and computational expertise.","publisher":{"@id":"https:\/\/nag.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nag.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/nag.com\/#organization","name":"Numerical Algorithms Group","alternateName":"NAG","url":"https:\/\/nag.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nag.com\/#\/schema\/logo\/image\/","url":"https:\/\/nag.com\/wp-content\/uploads\/2023\/11\/NAG-Logo.png","contentUrl":"https:\/\/nag.com\/wp-content\/uploads\/2023\/11\/NAG-Logo.png","width":1244,"height":397,"caption":"Numerical Algorithms Group"},"image":{"@id":"https:\/\/nag.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/NAGTalk","https:\/\/www.linkedin.com\/company\/nag\/","https:\/\/www.youtube.com\/user\/NumericalAlgorithms","https:\/\/github.com\/numericalalgorithmsgroup"]}]}},"_links":{"self":[{"href":"https:\/\/nag.com\/wp-json\/wp\/v2\/insights\/1430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nag.com\/wp-json\/wp\/v2\/insights"}],"about":[{"href":"https:\/\/nag.com\/wp-json\/wp\/v2\/types\/insights"}],"author":[{"embeddable":true,"href":"https:\/\/nag.com\/wp-json\/wp\/v2\/users\/7"}],"version-history":[{"count":6,"href":"https:\/\/nag.com\/wp-json\/wp\/v2\/insights\/1430\/revisions"}],"predecessor-version":[{"id":3043,"href":"https:\/\/nag.com\/wp-json\/wp\/v2\/insights\/1430\/revisions\/3043"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nag.com\/wp-json\/wp\/v2\/media\/868"}],"wp:attachment":[{"href":"https:\/\/nag.com\/wp-json\/wp\/v2\/media?parent=1430"}],"wp:term":[{"taxonomy":"post-tag","embeddable":true,"href":"https:\/\/nag.com\/wp-json\/wp\/v2\/post-tag?post=1430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}