<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help with LLS in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911268#M12173</link>
    <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/334681"&gt;Gennady Fedorov (Intel)&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt; Vikrant,&lt;BR /&gt;Could you check how this code will works with C++?&lt;BR /&gt;--Gennady&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
I am not sure, I understand your question. Please can you provide more info.&lt;BR /&gt;&lt;BR /&gt;Below is my code:&lt;BR /&gt;&lt;BR /&gt;Int32 SolveGELSS(Int32 inM, Int32 inN, array&lt;DOUBLE&gt;^A, array&lt;DOUBLE&gt;^ B)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;int m = inM;&lt;BR /&gt;int n = inN;&lt;BR /&gt;&lt;BR /&gt;int nrhs = 1;&lt;BR /&gt;int lda = m;&lt;BR /&gt;int ldb =   Math::Max(m,n);&lt;BR /&gt;double rcond = -1;&lt;BR /&gt;int lwork = 2;&lt;BR /&gt;int rank =0;&lt;BR /&gt;int i=0;&lt;BR /&gt;&lt;BR /&gt; double *a = new double[m*n];&lt;BR /&gt; this-&amp;gt;ConvertToColMajor(A, m,n,a);&lt;BR /&gt;&lt;BR /&gt; int info = 0;&lt;BR /&gt; double *work = new double[lwork];&lt;BR /&gt;&lt;BR /&gt; // Use ldb here, since it is max(m,n);&lt;BR /&gt; double *s = new double[ldb];&lt;BR /&gt;&lt;BR /&gt; // Copy b to local array&lt;BR /&gt; double *b = new double&lt;M&gt;;&lt;BR /&gt; for(i = 0; i &amp;lt; m; i++)&lt;BR /&gt; b&lt;I&gt; = B&lt;I&gt;;&lt;BR /&gt;&lt;BR /&gt; // Workspace query&lt;BR /&gt;&lt;BR /&gt; lwork = -1;&lt;BR /&gt; DGELSS(&amp;amp;m,&amp;amp;n, &amp;amp;nrhs, a,&amp;amp;lda, b, &amp;amp;ldb,s, &amp;amp;rcond, &amp;amp;rank, work, &amp;amp;lwork, &amp;amp;info);&lt;BR /&gt;&lt;BR /&gt; lwork = (int)work[0];&lt;BR /&gt; delete[]work;&lt;BR /&gt;&lt;BR /&gt; work = new double[lwork];&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; DGELSS(&amp;amp;m,&amp;amp;n, &amp;amp;nrhs, a,&amp;amp;lda, b, &amp;amp;ldb,s, &amp;amp;rcond, &amp;amp;rank, work, &amp;amp;lwork, &amp;amp;info);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; if(info == 0)&lt;BR /&gt; {&lt;BR /&gt; for(i = 0; i &amp;lt; m; i++)&lt;BR /&gt; B&lt;I&gt; = b&lt;I&gt;;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;// Memory clean up&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Many thanks.&lt;BR /&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/M&gt;&lt;/DOUBLE&gt;&lt;/DOUBLE&gt;</description>
    <pubDate>Fri, 16 Oct 2009 14:07:09 GMT</pubDate>
    <dc:creator>vikrantca</dc:creator>
    <dc:date>2009-10-16T14:07:09Z</dc:date>
    <item>
      <title>Help with LLS</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911266#M12171</link>
      <description>Problem: DGELSS does not seem to work with large datasets.&lt;BR /&gt;&lt;BR /&gt;I am using the following: MKL 10.2 with VS 2008, Managed C++.&lt;BR /&gt;&lt;BR /&gt;The call from C++ to MKL is fine - tested it with small datasets (upto 100 rows and 5 columns) and verified the results (LLS coefficients) with Matlab and Excel Regression.&lt;BR /&gt;&lt;BR /&gt;Attached is the dataset that I am having trouble with. It has 16383 rows and I get very strange coefficients from MKL.&lt;BR /&gt;The first 5 columns are the coefficient matrix and the last column is the y value. I am basically trying to fit the following equation: y = a+b*x + c*x^2 + d*x^3 + e*x^4.&lt;BR /&gt;&lt;BR /&gt;I get drastically different coefficients when I use Excel Data Analysis Toolpak  Regression feature.&lt;BR /&gt;&lt;BR /&gt;Any guidance is greatly appreciated. Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 14 Oct 2009 16:58:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911266#M12171</guid>
      <dc:creator>vikrantca</dc:creator>
      <dc:date>2009-10-14T16:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LLS</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911267#M12172</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/81650"&gt;vikrantca&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;Problem: DGELSS does not seem to work with large datasets.&lt;BR /&gt;&lt;BR /&gt;I am using the following: MKL 10.2 with VS 2008, Managed C++.&lt;BR /&gt;&lt;BR /&gt;The call from C++ to MKL is fine - tested it with small datasets (upto 100 rows and 5 columns) and verified the results (LLS coefficients) with Matlab and Excel Regression.&lt;BR /&gt;&lt;BR /&gt;Attached is the dataset that I am having trouble with. It has 16383 rows and I get very strange coefficients from MKL.&lt;BR /&gt;The first 5 columns are the coefficient matrix and the last column is the y value. I am basically trying to fit the following equation: y = a+b*x + c*x^2 + d*x^3 + e*x^4.&lt;BR /&gt;&lt;BR /&gt;I get drastically different coefficients when I use Excel Data Analysis Toolpak  Regression feature.&lt;BR /&gt;&lt;BR /&gt;Any guidance is greatly appreciated. Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
Vikrant,&lt;BR /&gt;Could you check how this code will works with C++?&lt;BR /&gt;--Gennady&lt;BR /&gt;</description>
      <pubDate>Fri, 16 Oct 2009 13:28:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911267#M12172</guid>
      <dc:creator>Gennady_F_Intel</dc:creator>
      <dc:date>2009-10-16T13:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LLS</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911268#M12173</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/334681"&gt;Gennady Fedorov (Intel)&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt; Vikrant,&lt;BR /&gt;Could you check how this code will works with C++?&lt;BR /&gt;--Gennady&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
I am not sure, I understand your question. Please can you provide more info.&lt;BR /&gt;&lt;BR /&gt;Below is my code:&lt;BR /&gt;&lt;BR /&gt;Int32 SolveGELSS(Int32 inM, Int32 inN, array&lt;DOUBLE&gt;^A, array&lt;DOUBLE&gt;^ B)&lt;BR /&gt;{&lt;BR /&gt;&lt;BR /&gt;int m = inM;&lt;BR /&gt;int n = inN;&lt;BR /&gt;&lt;BR /&gt;int nrhs = 1;&lt;BR /&gt;int lda = m;&lt;BR /&gt;int ldb =   Math::Max(m,n);&lt;BR /&gt;double rcond = -1;&lt;BR /&gt;int lwork = 2;&lt;BR /&gt;int rank =0;&lt;BR /&gt;int i=0;&lt;BR /&gt;&lt;BR /&gt; double *a = new double[m*n];&lt;BR /&gt; this-&amp;gt;ConvertToColMajor(A, m,n,a);&lt;BR /&gt;&lt;BR /&gt; int info = 0;&lt;BR /&gt; double *work = new double[lwork];&lt;BR /&gt;&lt;BR /&gt; // Use ldb here, since it is max(m,n);&lt;BR /&gt; double *s = new double[ldb];&lt;BR /&gt;&lt;BR /&gt; // Copy b to local array&lt;BR /&gt; double *b = new double&lt;M&gt;;&lt;BR /&gt; for(i = 0; i &amp;lt; m; i++)&lt;BR /&gt; b&lt;I&gt; = B&lt;I&gt;;&lt;BR /&gt;&lt;BR /&gt; // Workspace query&lt;BR /&gt;&lt;BR /&gt; lwork = -1;&lt;BR /&gt; DGELSS(&amp;amp;m,&amp;amp;n, &amp;amp;nrhs, a,&amp;amp;lda, b, &amp;amp;ldb,s, &amp;amp;rcond, &amp;amp;rank, work, &amp;amp;lwork, &amp;amp;info);&lt;BR /&gt;&lt;BR /&gt; lwork = (int)work[0];&lt;BR /&gt; delete[]work;&lt;BR /&gt;&lt;BR /&gt; work = new double[lwork];&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; DGELSS(&amp;amp;m,&amp;amp;n, &amp;amp;nrhs, a,&amp;amp;lda, b, &amp;amp;ldb,s, &amp;amp;rcond, &amp;amp;rank, work, &amp;amp;lwork, &amp;amp;info);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt; if(info == 0)&lt;BR /&gt; {&lt;BR /&gt; for(i = 0; i &amp;lt; m; i++)&lt;BR /&gt; B&lt;I&gt; = b&lt;I&gt;;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;// Memory clean up&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Many thanks.&lt;BR /&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/M&gt;&lt;/DOUBLE&gt;&lt;/DOUBLE&gt;</description>
      <pubDate>Fri, 16 Oct 2009 14:07:09 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911268#M12173</guid>
      <dc:creator>vikrantca</dc:creator>
      <dc:date>2009-10-16T14:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LLS</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911269#M12174</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
&lt;BR /&gt;You're right, coefficients seem to be bogus, I get somewhat like&lt;BR /&gt;&lt;BR /&gt;-2.492143e-17 6.400757e-18 -8.539396e-19 -6.115223e-18 2.546998e-17&lt;BR /&gt;&lt;BR /&gt;This can be explained by tooimbalanced matrix: the values are different in order by more than machineprecision (~1.0e-16). The algorithm becomes highly unstable. But it can be easily worked around. I would recommend you balancing the matrix before applying DGELSS - for instance, in this case:&lt;BR /&gt;&lt;BR /&gt;for( i = 0; i &amp;lt; M; i++ ) A[1]&lt;I&gt; *= 1.0e-6;&lt;BR /&gt;for( i = 0; i &amp;lt; M; i++ ) A[2]&lt;I&gt; *= 1.0e-11;&lt;BR /&gt;for( i = 0; i &amp;lt; M; i++ ) A[3]&lt;I&gt; *= 1.0e-16;&lt;BR /&gt;for( i = 0; i &amp;lt; M; i++ ) A[4]&lt;I&gt; *= 1.0e-21;&lt;BR /&gt;for( i = 0; i &amp;lt; M; i++ ) B&lt;I&gt; *= 1.0e-6;&lt;BR /&gt;&lt;BR /&gt;Then you would get results,which seem to be correct (after back scaling):&lt;BR /&gt;&lt;BR /&gt;-4.103898e+04 4.109750e-02 -4.553319e-07 4.735998e-12 -1.904054e-18&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Michael.&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;</description>
      <pubDate>Fri, 23 Oct 2009 17:17:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911269#M12174</guid>
      <dc:creator>Michael_C_Intel4</dc:creator>
      <dc:date>2009-10-23T17:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LLS</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911270#M12175</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Works nicely. Many thanks Michael.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Oct 2009 15:44:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911270#M12175</guid>
      <dc:creator>vikrantca</dc:creator>
      <dc:date>2009-10-26T15:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LLS</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911271#M12176</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/81650"&gt;vikrantca&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;
&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="width: 100%; margin-top: 5px;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Works nicely. Many thanks Michael.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
One naive question - On output from GELSS, the rows of matrix B (from n+1 to m) will also need to be inverse-scaled to get the correct residuals, right? &lt;BR /&gt;&lt;BR /&gt;Many thanks.&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Oct 2009 20:48:29 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911271#M12176</guid>
      <dc:creator>vikrantca</dc:creator>
      <dc:date>2009-10-28T20:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LLS</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911272#M12177</link>
      <description>&lt;DIV style="margin:0px;"&gt;
&lt;DIV id="quote_reply" style="margin-top: 5px; width: 100%;"&gt;
&lt;DIV style="margin-left:2px;margin-right:2px;"&gt;Quoting - &lt;A href="https://community.intel.com/en-us/profile/81650"&gt;vikrantca&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color:#E5E5E5; padding:5px;border: 1px; border-style: inset;margin-left:2px;margin-right:2px;"&gt;&lt;EM&gt;
&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
One naive question - On output from GELSS, the rows of matrix B (from n+1 to m) will also need to be inverse-scaled to get the correct residuals, right? &lt;BR /&gt;&lt;BR /&gt;Many thanks.&lt;BR /&gt;&lt;/EM&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;BR /&gt;Yes, it should be scaled back. Here's the theory:&lt;/P&gt;
&lt;P&gt;- initial system of equations is: A*x = b, you need solution to minimize r = || A*x - b || and residual r.&lt;/P&gt;
&lt;P&gt;- you solve the system A*cA*x' = b*cb instead, where cA: n-by-n, cA = diag( cA1, ..., cAn );cb: 1-by-1 scalar&lt;/P&gt;
&lt;P&gt;- the solution of the modifed system: x' = inv( cA )*x*cb, that is x = inv( cb )*x'*cA&lt;/P&gt;
&lt;P&gt;- by substituting solution x' into modified system's residualwe get r' = || A*cA*x' - b*cb || = || A*x*cb - b*cb || = || A*x - b || * cb = r*cb, that is r = r'*inv( cb ), so&lt;/P&gt;
&lt;P&gt;you collect sum-of-squares from DGELSS (that is,of modified system - r'), than scale it back with the coefficient you scaled b vector with.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2009 09:21:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911272#M12177</guid>
      <dc:creator>Michael_C_Intel4</dc:creator>
      <dc:date>2009-10-29T09:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Help with LLS</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911273#M12178</link>
      <description>&lt;DIV style="margin:0px;"&gt;&lt;/DIV&gt;
To be more precise, you need to scale back not r', but r'^2 (square of r'), so apparently it should be scaled by inv( cb )^2, that is r^2 = r'^2 * inv( cb )^2&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Oct 2009 09:40:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-LLS/m-p/911273#M12178</guid>
      <dc:creator>Michael_C_Intel4</dc:creator>
      <dc:date>2009-10-29T09:40:50Z</dc:date>
    </item>
  </channel>
</rss>

