<?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 Quote:Alexander Kalinkin  in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/trnlsq-related-routines-for-nonlinear-fitting/m-p/1016317#M19509</link>
    <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Alexander Kalinkin (Intel) wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;It is look like you forget to implement case RCI_Request equal to 2 on which user need to calculate&amp;nbsp;Jacobian of function.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Alex&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Hi Alexander,&lt;/P&gt;

&lt;P&gt;Thanks for the reply. You are right. I forgot to implement it.&lt;/P&gt;</description>
    <pubDate>Mon, 19 May 2014 19:51:36 GMT</pubDate>
    <dc:creator>Cheng_C_</dc:creator>
    <dc:date>2014-05-19T19:51:36Z</dc:date>
    <item>
      <title>?trnlsq related routines for nonlinear fitting</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/trnlsq-related-routines-for-nonlinear-fitting/m-p/1016315#M19507</link>
      <description>&lt;P&gt;I want to solve a nonlinear least square fitting problem to estimate a and b.&amp;nbsp;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;g(x)=a(x^2)+bx.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;I have two vectors working as the training data. fx1={1.0, 2.0, 3.0, 4.0}; fx2={2.0, 4.0, 6.0, 8.0}. I defined my objective&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;function&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp;as f(x) = |g(fx1)-fx2|. It's obvious&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;that&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;&amp;nbsp;the optimal a and b, in this case, should be 0 and 2 respectively, to minimize the objective&amp;nbsp;&lt;/SPAN&gt;function.&lt;/P&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em; line-height: 1.5;"&gt;I used the MKL ?trnlsp related routines without boundary constraints to conduct the fitting. However, it didn't work. My code and the result are attached. It would be great if you guys can help to give some suggestions. Thanks.&lt;/SPAN&gt;&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;cstdlib&amp;gt;
#include &amp;lt;cmath&amp;gt;
#include &amp;lt;cstdio&amp;gt;
#include &amp;lt;complex&amp;gt;

#include "mkl_rci.h"
#include "mkl_types.h"
#include "mkl_service.h"

using namespace std;

float fx1[4] = {1.0, 2.0, 3.0, 4.0};
float fy1[4] = {2.0, 4.0, 6.0, 8.0};

int main(){

    extern void rss(MKL_INT *, MKL_INT *, float *, float *);
    
    MKL_INT n = 2, m = 4;
    float eps[6];
    float *x = NULL;
    MKL_INT iter1 = 1000, iter2 = 100;
    float rs = 1.0;
    MKL_INT RCI_Request;      // reverse communication interface variable
    MKL_INT successful;
    float *fvec = NULL;
    float *fjac = NULL;
    MKL_INT iter;
    MKL_INT st_cr;
    float r1, r2;
    _TRNSP_HANDLE_t handle;   // TR solver handle
    MKL_INT i;
    MKL_INT error;
    MKL_INT info[6];

    x = (float *) malloc (sizeof (float) * n);
    fvec = (float *) malloc (sizeof (float) * m);
    fjac = (float *) malloc (sizeof (float) * m * n);
    for (i = 0; i &amp;lt; 6; i++)
    {
        eps&lt;I&gt; = 0.00001;
    }
    x[0] = 1.0;
    x[1] = 0.0;

    for (i = 0; i &amp;lt; m; i++)
        fvec&lt;I&gt; = 0.0;
    for (i = 0; i &amp;lt; m * n; i++)
        fjac&lt;I&gt; = 0.0;
    strnlsp_init (&amp;amp;handle, &amp;amp;n, &amp;amp;m, x, eps, &amp;amp;iter1, &amp;amp;iter2, &amp;amp;rs);
    RCI_Request = 0;
    successful = 0;
    while (successful == 0)
    {
        strnlsp_solve (&amp;amp;handle, fvec, fjac, &amp;amp;RCI_Request);
        
        if (RCI_Request == -1 ||
            RCI_Request == -2 ||
            RCI_Request == -3 ||
            RCI_Request == -4 || RCI_Request == -5 || RCI_Request == -6)
            successful = 1;
        if (RCI_Request == 1)
        {
            rss (&amp;amp;m, &amp;amp;n, x, fvec);
        }
        cout &amp;lt;&amp;lt; "RCI_Request = " &amp;lt;&amp;lt; RCI_Request &amp;lt;&amp;lt; endl;
        cout &amp;lt;&amp;lt; "successful = " &amp;lt;&amp;lt; successful &amp;lt;&amp;lt; endl;
    }
    strnlsp_get (&amp;amp;handle, &amp;amp;iter, &amp;amp;st_cr, &amp;amp;r1, &amp;amp;r2);

    for(int i=0; i&amp;lt;n; i++){
        cout &amp;lt;&amp;lt; x&lt;I&gt; &amp;lt;&amp;lt; endl;
    }
    cout &amp;lt;&amp;lt; "iter = " &amp;lt;&amp;lt; iter &amp;lt;&amp;lt; endl;

    strnlsp_delete (&amp;amp;handle);
    free (fjac);
    free (fvec);
    free (x);
    MKL_Free_Buffers ();
    if (r2 &amp;lt; 0.00001)
    {
        printf ("Succeeded\n");
        return 0;
    }
    else
    {
        printf ("Failed\n");
        return 1;
    }
}

/* nonlinear system equations without constraints */
/* routine for extendet powell function calculation
   m     in:     dimension of function value
   n     in:     number of function variables
   x     in:     vector for function calculating
   f     out:    function value f(x) */
void rss(MKL_INT * m, MKL_INT * n, float *x, float *f){

    double temp;
    for(int j=0; j&amp;lt;(*m); j++){
        temp = x[0]*fx1&lt;J&gt;*fx1&lt;J&gt; + x[1]*fx1&lt;J&gt;;
        f&lt;J&gt; = abs(temp - fy1&lt;J&gt;);
        cout &amp;lt;&amp;lt; "f = " &amp;lt;&amp;lt; f&lt;J&gt; &amp;lt;&amp;lt; endl;
    }

    return;
}
&lt;/J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;PRE class="brush:bash;"&gt;f = 1
f = 0
f = 3
f = 8
RCI_Request = 1
successful = 0
RCI_Request = 2
successful = 0
RCI_Request = -4
successful = 1
1
0
iter = 0
Failed&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 May 2014 19:00:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/trnlsq-related-routines-for-nonlinear-fitting/m-p/1016315#M19507</guid>
      <dc:creator>Cheng_C_</dc:creator>
      <dc:date>2014-05-15T19:00:19Z</dc:date>
    </item>
    <item>
      <title>Hi,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/trnlsq-related-routines-for-nonlinear-fitting/m-p/1016316#M19508</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;It is look like you forget to implement case RCI_Request equal to 2 on which user need to calculate&amp;nbsp;Jacobian of function.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Alex&lt;/P&gt;</description>
      <pubDate>Mon, 19 May 2014 14:31:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/trnlsq-related-routines-for-nonlinear-fitting/m-p/1016316#M19508</guid>
      <dc:creator>Alexander_K_Intel2</dc:creator>
      <dc:date>2014-05-19T14:31:40Z</dc:date>
    </item>
    <item>
      <title>Quote:Alexander Kalinkin</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/trnlsq-related-routines-for-nonlinear-fitting/m-p/1016317#M19509</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Alexander Kalinkin (Intel) wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;It is look like you forget to implement case RCI_Request equal to 2 on which user need to calculate&amp;nbsp;Jacobian of function.&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Alex&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Hi Alexander,&lt;/P&gt;

&lt;P&gt;Thanks for the reply. You are right. I forgot to implement it.&lt;/P&gt;</description>
      <pubDate>Mon, 19 May 2014 19:51:36 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/trnlsq-related-routines-for-nonlinear-fitting/m-p/1016317#M19509</guid>
      <dc:creator>Cheng_C_</dc:creator>
      <dc:date>2014-05-19T19:51:36Z</dc:date>
    </item>
  </channel>
</rss>

