<?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: PROC OPTMODEL help needed - optimising a linear equation with restrictions in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/722678#M3333</link>
    <description>&lt;P&gt;Many thanks Rob!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This was a great help. I've been a SAS user for 25+ years, but I've only just started using Proc OPTMODEL and there is the usual, rather steep, learning curve. It never ceases to amaze me the breadth and depth of modules within SAS...the more you know, the less you know, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best wishes and kind regards,&lt;/P&gt;&lt;P&gt;Jonathan&lt;/P&gt;</description>
    <pubDate>Mon, 01 Mar 2021 20:33:38 GMT</pubDate>
    <dc:creator>Jonathan_A5</dc:creator>
    <dc:date>2021-03-01T20:33:38Z</dc:date>
    <item>
      <title>PROC OPTMODEL help needed - optimising a linear equation with restrictions</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/721638#M3327</link>
      <description>&lt;DIV class="votecell post-layout--left"&gt;&lt;DIV class="js-voting-container grid jc-center fd-column ai-stretch gs4 fc-black-200"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="postcell post-layout--right"&gt;&lt;DIV class="s-prose js-post-body"&gt;&lt;P&gt;I'd really like to be able to solve the following problem:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Given observed data x(1)....x(n) and a known fixed 'target' T, solve for parameters a0, a1, &amp;amp; a2, which minimise:&lt;/P&gt;&lt;P&gt;{ T - sum[i=1 to n] exp(a0+a1*x(i)+a2*x(i)^2)*x(i)&amp;nbsp; }^2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with the restriction that the sum of the exp(a0+a1*x(i)+a2*x(i)^2)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;terms equals&lt;SPAN&gt;&amp;nbsp;n&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;i.e. the mean of&lt;SPAN&gt;&amp;nbsp;the exp(a0+a1*x(i)+a2*x(i)^2)&amp;nbsp;terms&amp;nbsp;&lt;/SPAN&gt;equals 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried PROC MODEL and PROC NLIN in SAS v9.4 but with no luck.&lt;/P&gt;&lt;P&gt;I'm now attempting to try with PROC OPTMODEL&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My OPTMODEL test code is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;* Create data with known parameters;&lt;BR /&gt;data d1;&lt;BR /&gt;do i = 1 to 100;&lt;BR /&gt;x=ranuni(4245);&lt;BR /&gt;w1=exp(1.0253056-3*x+0.4*x**2);* Weighting variable;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;proc means data=d1 n mean;var w1;run; * Mean weight of 1;&lt;BR /&gt;proc means data=d1 n mean;var x;run;&lt;BR /&gt;proc means data=d1 n mean;var x;weight w1;run; * Target (T)=0.2736;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc optmodel;&lt;BR /&gt;set OBS;&lt;BR /&gt;num x{OBS};&lt;BR /&gt;read data d1 into OBS = [i] x ;&lt;BR /&gt;var a0 init 1, a1 init -2, a2 init 0.5;&lt;BR /&gt;con restrict: sum {i in OBS} exp(a0 + a1*x[i] + a2*x[i]**2) = sum{i in OBS} 1;&lt;BR /&gt;min objective = (0.2736 - sum {i in OBS} (exp(a0 + a1*x[i] + a2*x[i]**2)*x[i]))**2;&lt;BR /&gt;solve with nlp / tech=ip ms seed=21 MSMAXSTARTS=5000 msbndrange=50;&lt;BR /&gt;print a0 a1 a2;&lt;BR /&gt;quit;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The model does not converge anywhere near the a0, a1 &amp;amp; a2 values used in the 'd1' data step, even when initiated at values very close to those actually used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong? I suspect it's the way the objective function is specified....but just a hunch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help gratefully received!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 24 Feb 2021 17:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/721638#M3327</guid>
      <dc:creator>Jonathan_A5</dc:creator>
      <dc:date>2021-02-24T17:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: PROC OPTMODEL help needed - optimising a linear equation with restrictions</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/721695#M3328</link>
      <description>&lt;P&gt;Your current objective is trying to force the mean and the sum to be equal.&amp;nbsp; You instead want to replace 0.2736 with 0.2736*card(OBS).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an alternative approach that avoids hard-coding the target and also avoids duplication of the exponential expression:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set OBS;
   num x{OBS};
   num w1{OBS};
   read data d1 into OBS = [i] x w1;
   num target = sum {i in OBS} w1[i]*x[i];
   num aInit {0..2} = [1, -2, 0.5];
   var a {j in 0..2} init aInit[j];
   impvar w {i in OBS} = exp(sum {j in 0..2} a[j]*x[i]^j);
   con restrict: sum {i in OBS} w[i] = card(OBS);
   min objective = (target - sum {i in OBS} w[i]*x[i])**2;
   solve with nlp / tech=ip ms seed=21 MSMAXSTARTS=5000 msbndrange=50;
   print aInit a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 21:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/721695#M3328</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2021-02-24T21:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC OPTMODEL help needed - optimising a linear equation with restrictions</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/722473#M3331</link>
      <description>&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your suggestion.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note that the w(i) in the problem are actually unknown - I just simulated them to see of the the model could converge on the three parameters (a1, s2, a3) that are used to calculate the w(i) in the dataset d1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only knowns in a 'real-life' situation will be the x(i) and the target.&lt;/P&gt;&lt;P&gt;The only restrictions are that the w(i) need to be positive (hence the use of the exponential function) and that the mean of the w(i) needs to be 1.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm guessing the above would impact upon your suggested code. Happy to hear your thoughts.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Jonathan&lt;/P&gt;</description>
      <pubDate>Sun, 28 Feb 2021 20:01:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/722473#M3331</guid>
      <dc:creator>Jonathan_A5</dc:creator>
      <dc:date>2021-02-28T20:01:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC OPTMODEL help needed - optimising a linear equation with restrictions</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/722509#M3332</link>
      <description>&lt;P&gt;Glad to help.&amp;nbsp; The only place I used the actual values of w1(i) was to compute the target as the weighted sum.&amp;nbsp; You could pass that single number in as an input instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   select sum(w1*x) into :target
   from d1;
quit;

proc optmodel;
   set OBS;
   num x{OBS};
   read data d1 into OBS = [i] x;
   num aInit {0..2} = [1, -2, 0.5];
   var a {j in 0..2} init aInit[j];
   impvar w {i in OBS} = exp(sum {j in 0..2} a[j]*x[i]^j);
   con restrict: sum {i in OBS} w[i] = card(OBS);
   min objective = (&amp;amp;target - sum {i in OBS} w[i]*x[i])**2;
   solve with nlp / tech=ip ms seed=21 MSMAXSTARTS=5000 msbndrange=50;
   print aInit a;
   print x w;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Feb 2021 23:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/722509#M3332</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2021-02-28T23:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC OPTMODEL help needed - optimising a linear equation with restrictions</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/722678#M3333</link>
      <description>&lt;P&gt;Many thanks Rob!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This was a great help. I've been a SAS user for 25+ years, but I've only just started using Proc OPTMODEL and there is the usual, rather steep, learning curve. It never ceases to amaze me the breadth and depth of modules within SAS...the more you know, the less you know, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;best wishes and kind regards,&lt;/P&gt;&lt;P&gt;Jonathan&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 20:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/PROC-OPTMODEL-help-needed-optimising-a-linear-equation-with/m-p/722678#M3333</guid>
      <dc:creator>Jonathan_A5</dc:creator>
      <dc:date>2021-03-01T20:33:38Z</dc:date>
    </item>
  </channel>
</rss>

