<?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: SAS minimization problem - Proc Optmodel / proc IML in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856265#M42335</link>
    <description>I'm using 9.4. And yes, it's a markov transition matrix.</description>
    <pubDate>Mon, 30 Jan 2023 15:21:41 GMT</pubDate>
    <dc:creator>Giraffe123</dc:creator>
    <dc:date>2023-01-30T15:21:41Z</dc:date>
    <item>
      <title>SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856204#M42327</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following problem which I need to solve with either PROC OPTMODEL or PROC IML. Unfortunately I'm not advanced in either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a transition matrix = {0.1,0.4,0,5,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0.6,0,4,0,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 , 0, 1};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have periods = 12.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then my problem statement is: Matrix_nperiod = transition_matrix**n_period,&lt;/P&gt;&lt;P&gt;and I have the error: abs(Matrix_nperiod -&amp;nbsp;transition_matrix) which I would like to minimize. I have tried the following code to no avail: ( I haven't tried proc iml yet)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc optmodel;&lt;/P&gt;&lt;P&gt;num transition_matrix {1..3,1..3} = [0.1,0.4,0,5,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.6,0,4,0,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 , 0, 1];&lt;/P&gt;&lt;P&gt;num n_period = 12;&lt;/P&gt;&lt;P&gt;impvar&amp;nbsp;Matrix_nperiod = transition_matrix**n_period;&lt;/P&gt;&lt;P&gt;min error =Matrix_nperiod -&amp;nbsp;transition_matrix;&lt;/P&gt;&lt;P&gt;solve;&lt;/P&gt;&lt;P&gt;print error;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can somebody please help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards,&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 10:11:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856204#M42327</guid>
      <dc:creator>Giraffe123</dc:creator>
      <dc:date>2023-01-30T10:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856214#M42328</link>
      <description>&lt;P&gt;I think the best choice is PROC IML.&lt;/P&gt;
&lt;P&gt;Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/1636"&gt;@RobPratt&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 11:16:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856214#M42328</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-01-30T11:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856217#M42329</link>
      <description>&lt;P&gt;I don't understand your problem. You say you want to minimize&amp;nbsp;&lt;SPAN&gt;abs(Matrix_nperiod -&amp;nbsp;transition_matrix), but what&lt;/SPAN&gt;&amp;nbsp;is the parameter in this problem. That is, what parameter are you allowed to change in order to find the optimal value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, can you clarify the loss function? Do you mean the SUM of the difference between elements in the two matrices?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your program, you set n_period = 12, and then compute&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Matrix_nperiod = transition_matrix**n_period;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But Matrix_nperiod is a (known) constant, so the difference is a constant.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Maybe you want to vary the number of periods? If so, the answer is n_period=1, because then&amp;nbsp;Matrix_nperiod = transition_matrix, and the difference is exactly 0.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 11:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856217#M42329</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-01-30T11:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856222#M42330</link>
      <description>&lt;P&gt;Sorry let me make a correction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So actually you have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Matrix_nperiod&amp;nbsp;= One_period_matrix **n_period&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and you error = abs(Matrix_nperiod -&amp;nbsp;transition_matrix).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So the objective function is actually:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;sum (error) in other words:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;sum ((One_period_matrix **n_period) - transition_matrix)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In other words,&amp;nbsp;One_period_matrix is your parameter&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sorry for the confusion &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 12:26:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856222#M42330</guid>
      <dc:creator>Giraffe123</dc:creator>
      <dc:date>2023-01-30T12:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856247#M42332</link>
      <description>&lt;P&gt;If I understand you correctly, you want to find a 3x3 matrix, A, such that A^12 is as close as possible to a given matrix, B? In other words, you seek the 12th-root of B?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What properties must A obey? Is it also a Markov transition matrix?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure you want the matrix that is closest according to sum(abs(diff))? Another choice is to use the L2 norm (Fobenius norm for matrices), which is sum(diff_{ij}^2).&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 14:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856247#M42332</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-01-30T14:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856262#M42334</link>
      <description>&lt;P&gt;Regarding your access to PROC IML, are you running SAS 9.4 or SAS Viya?&amp;nbsp; I ask because the SAS Viya version of SAS IML has some additional features that we could use to solve this problem.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 15:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856262#M42334</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-01-30T15:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856265#M42335</link>
      <description>I'm using 9.4. And yes, it's a markov transition matrix.</description>
      <pubDate>Mon, 30 Jan 2023 15:21:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856265#M42335</guid>
      <dc:creator>Giraffe123</dc:creator>
      <dc:date>2023-01-30T15:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856268#M42336</link>
      <description>&lt;P&gt;Here's a PROC IML solution. I replaced your loss function with a quadratic loss function because some nonlinear optimization methods perform better when the objective function is differentiable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
start ObjFun(parms) global(periods, target);
   A = shape(parms, 3, 3);
   B = A**periods;
   error = sum(ssq(B - target));
   return error;
finish;

/* define the target matrix. We want to find transition matrix A
   such that A**12 is as close as possible to the target matrix. */
Target = {0.1 0.4 0.5,
          0.6 0.4   0,
          0     0   1};
periods = 12;

/* define linear and boundary constraints */
con = {  0 0 0  0 0 0  0 0 0 . .,  /* lower bound is 0 for all parameters */
         1 1 1  1 1 1  1 1 1 . .,  /* upper bound is 1 for all parameters */
         1 1 1  . . .  . . . 0 1,  /* sum of 1st row = 1 */
         . . .  1 1 1  . . . 0 1,  /* sum of 2nd row = 1 */
         . . .  . . .  1 1 1 0 1}; /* sum of 3rd row = 1 */

x = I(3);  /* start with the identity matrix */
x0 = rowvec(x);
opt = {0 2};
call nlpnra(rc, xres, "ObjFun", x0, opt) BLC=con;

A = shape(xres, 3, 3);
B = A**periods;
SSE = sum(ssq(B - target));
print A[L="Best Estimate"], B[L="Estimate**12"], SSE;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I should mention that this problem might not have a unique solution, and it could have local optima. In other words, if you use a different initial guess, you might obtain a different value for the local solution.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Jan 2023 15:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856268#M42336</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-01-30T15:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856405#M42339</link>
      <description>&lt;P&gt;Here's a way to minimize the quadratic loss with PROC OPTMODEL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set ROWS = 1..3;
   set COLS = ROWS;
   num target {ROWS, COLS} = 
      [0.1 0.4 0.5,
       0.6 0.4   0,
       0     0   1];
   num numPeriods = 12;
   set PERIODS = 1..numPeriods;

   var X {i in ROWS, j in COLS} &amp;gt;= 0 &amp;lt;= 1;
   impvar XPower {i in ROWS, j in COLS, p in PERIODS} = 
      (if p = 1 then X[i,j] else sum {k in COLS} XPower[i,k,p-1] * XPower[k,j,p-1]);
   min SSE = sum {i in ROWS, j in COLS} (XPower[i,j,numPeriods] - target[i,j])^2;
   con RowSum {i in ROWS}:
      sum {j in COLS} X[i,j] = 1;

   solve with nlp / ms algorithm=as;
   print X;
   print {i in ROWS, j in COLS} XPower[i,j,numPeriods];
   print target;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;suggested might be the case, the problem has several local minima.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2023 02:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/856405#M42339</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2023-01-31T02:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: SAS minimization problem - Proc Optmodel / proc IML</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/858509#M42432</link>
      <description>&lt;P&gt;I wrote an article about this problem that has additional details:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2023/02/13/pth-root-markov-transition.html" target="_self"&gt;"Estimate the pth root of a Markov transition matrix"&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 14:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/SAS-minimization-problem-Proc-Optmodel-proc-IML/m-p/858509#M42432</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-02-13T14:22:19Z</dc:date>
    </item>
  </channel>
</rss>

