<?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: Minimizing the standard deviation between the sum of different variables in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimizing-the-standard-deviation-between-the-sum-of-different/m-p/474331#M2293</link>
    <description>&lt;P&gt;Thanks for your help. However, I think something is still wrong, the point is that the length of the variable is not the same every year so if&amp;nbsp;I use&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;a&lt;/STRONG&gt;&amp;nbsp;as the smallest data value and &lt;STRONG&gt;b&lt;/STRONG&gt; as the largest data value,&lt;/SPAN&gt; the&amp;nbsp;variation won't be 0. Anyways,&amp;nbsp;I am now&amp;nbsp;minimizing the coefficient of variation to avoid trivial solutions but I wanted to constrain that the mean is different to 0 and that &lt;STRONG&gt;b&lt;/STRONG&gt; is greater than &lt;STRONG&gt;a&lt;/STRONG&gt; but I get this response "The problem contains strict inequality or predicate constraints that reference non-integer variables".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I tried to approximately address the values of &lt;STRONG&gt;a&lt;/STRONG&gt; and &lt;STRONG&gt;b&lt;/STRONG&gt; as shown in the script (&lt;STRONG&gt;a&lt;/STRONG&gt; GT 3 and &lt;STRONG&gt;b&lt;/STRONG&gt; GT 16, in this case) but the response is just showing me the same values with some decimals according to&amp;nbsp;0 iterations.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set YEARS = 2013..2016;
   set DAYS;
   num temp{DAYS, YEARS};
   read data temp into DAYS=[Log] {y in YEARS} &amp;lt;temp[Log,y]=col('y'||y)&amp;gt;;
   var a&amp;gt;=3,b&amp;gt;=16;
   impvar CU{p in DAYS, y in YEARS} = (if a &amp;lt;= temp[p,y] &amp;lt;= b then 1 else 0);
   impvar S{y in YEARS} = sum{p in DAYS} CU[p,y];
   impvar mean = (sum{y in YEARS} S[y])/card(YEARS);
   minimize Coefv = (sqrt(sum{y in YEARS}((S[y]-mean)**2)/card(YEARS)))/mean;
   solve;
   /* display solution */
   print a b;
   print S mean coefv;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 29 Jun 2018 02:43:00 GMT</pubDate>
    <dc:creator>hacamargoa</dc:creator>
    <dc:date>2018-06-29T02:43:00Z</dc:date>
    <item>
      <title>Minimizing the standard deviation between the sum of different variables</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimizing-the-standard-deviation-between-the-sum-of-different/m-p/473600#M2287</link>
      <description>&lt;P&gt;Hello, I am starting to work with proc optmodel and have a recurrent problem easy for solver but I want to do it in SAS. I have the daily temperatures during one month for 4 years and I need to create new binary variables CU1--CU4 (one for each year) defined as 1 if the temperature is in a specific range. However, I need to find the limits of that range that minimize the standard deviation between the four sum of CUs, I was trying something that probably is totally wrong because I do not know how to define the limits of the range and also if I have to put some constrains or impvar.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp; 
input Log y2013 y2014 y2015 y2016; 
cards; 
1 28.2 28.3 18.2 27.8 
2 29.6 29.7 19.9 29.2 . . . 

proc optmodel; 
set temp; 
num y2013{temp}; 
num y2014{temp}; 
num y2015{temp}; 
num y2016{temp}; 
var a,b; 
impvar CU1{p in temp}=if a&amp;lt;= y2013[p] &amp;lt;= b then 1 else 0; 
impvar CU2{p in temp}=if a&amp;lt;= y2014[p] &amp;lt;= b then 1 else 0;
impvar CU3{p in temp}=if a&amp;lt;= y2015[p] &amp;lt;= b then 1 else 0; 
impvar CU4{p in temp}=if a&amp;lt;= y2016[p] &amp;lt;= b then 1 else 0; 
impvar S1=sum{p in temp} CU1[p]; impvar S2=sum{p in temp} CU2[p]; impvar S3=sum{p in temp} CU3[p]; impvar S4=sum{p in temp} CU4[p]; 
min SSE=sqrt(.25 * ((S1-(S1+S2+S3+S4)/4)**2+(S2-(S1+S2+S3+S4)/4)**2+(S3-(S1+S2+S3+S4)/4)**2+(S4-(S1+S2+S3+S4)/4)**2)); 
solve; 
print a b; 
quit; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jun 2018 02:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimizing-the-standard-deviation-between-the-sum-of-different/m-p/473600#M2287</guid>
      <dc:creator>hacamargoa</dc:creator>
      <dc:date>2018-06-29T02:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Minimizing the standard deviation between the sum of different variables</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimizing-the-standard-deviation-between-the-sum-of-different/m-p/473904#M2289</link>
      <description>&lt;P&gt;Here is a more compact way to write your code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set YEARS = 2013..2016;
   set DAYS;
   num temp{DAYS, YEARS};
   read data temp into DAYS=[Log] {y in YEARS} &amp;lt;temp[Log,y]=col('y'||y)&amp;gt;;
   var a,b;
   impvar CU{p in DAYS, y in YEARS} = (if a &amp;lt;= temp[p,y] &amp;lt;= b then 1 else 0); /* even shorter: (a &amp;lt;= temp[p,y] &amp;lt;= b) */
   impvar S{y in YEARS} = sum{p in DAYS} CU[p,y];
   impvar mean = (sum{y in YEARS} S[y])/card(YEARS);
   min SSE = sum{y in YEARS}(S[y]-mean)**2;
   solve;
   /* display solution */
   print a b;
   print CU S SSE;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the optimal objective value is trivially 0.&amp;nbsp; For example, if you take a to be the smallest data value and b to be the largest data value, then CU[p,y] is always 1, S[y] is always card(DAYS), and SSE = 0.&amp;nbsp; Another optimal solution is to take a = b = an arbitrary value that does not appear in your data, say -999.&amp;nbsp; In that case, CU[p,y] = 0, S[y] = 0, and again SSE = 0.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jun 2018 20:40:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimizing-the-standard-deviation-between-the-sum-of-different/m-p/473904#M2289</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-06-27T20:40:39Z</dc:date>
    </item>
    <item>
      <title>Re: Minimizing the standard deviation between the sum of different variables</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimizing-the-standard-deviation-between-the-sum-of-different/m-p/474331#M2293</link>
      <description>&lt;P&gt;Thanks for your help. However, I think something is still wrong, the point is that the length of the variable is not the same every year so if&amp;nbsp;I use&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;a&lt;/STRONG&gt;&amp;nbsp;as the smallest data value and &lt;STRONG&gt;b&lt;/STRONG&gt; as the largest data value,&lt;/SPAN&gt; the&amp;nbsp;variation won't be 0. Anyways,&amp;nbsp;I am now&amp;nbsp;minimizing the coefficient of variation to avoid trivial solutions but I wanted to constrain that the mean is different to 0 and that &lt;STRONG&gt;b&lt;/STRONG&gt; is greater than &lt;STRONG&gt;a&lt;/STRONG&gt; but I get this response "The problem contains strict inequality or predicate constraints that reference non-integer variables".&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I tried to approximately address the values of &lt;STRONG&gt;a&lt;/STRONG&gt; and &lt;STRONG&gt;b&lt;/STRONG&gt; as shown in the script (&lt;STRONG&gt;a&lt;/STRONG&gt; GT 3 and &lt;STRONG&gt;b&lt;/STRONG&gt; GT 16, in this case) but the response is just showing me the same values with some decimals according to&amp;nbsp;0 iterations.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set YEARS = 2013..2016;
   set DAYS;
   num temp{DAYS, YEARS};
   read data temp into DAYS=[Log] {y in YEARS} &amp;lt;temp[Log,y]=col('y'||y)&amp;gt;;
   var a&amp;gt;=3,b&amp;gt;=16;
   impvar CU{p in DAYS, y in YEARS} = (if a &amp;lt;= temp[p,y] &amp;lt;= b then 1 else 0);
   impvar S{y in YEARS} = sum{p in DAYS} CU[p,y];
   impvar mean = (sum{y in YEARS} S[y])/card(YEARS);
   minimize Coefv = (sqrt(sum{y in YEARS}((S[y]-mean)**2)/card(YEARS)))/mean;
   solve;
   /* display solution */
   print a b;
   print S mean coefv;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jun 2018 02:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimizing-the-standard-deviation-between-the-sum-of-different/m-p/474331#M2293</guid>
      <dc:creator>hacamargoa</dc:creator>
      <dc:date>2018-06-29T02:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Minimizing the standard deviation between the sum of different variables</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Minimizing-the-standard-deviation-between-the-sum-of-different/m-p/474537#M2297</link>
      <description>&lt;P&gt;You cannot use strict inequalities with the NLP solver.&amp;nbsp; But you could do this instead to force a positive mean:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   con PositiveMean: mean &amp;gt;= 1e-6;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Similarly, you can force A &amp;lt; B like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   con A_LT_B: A + 1e-6 &amp;lt;= B;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With or without these constraints, your new objective does not avoid all trivial solutions.&amp;nbsp; For example, the following code yields an optimal solution with mean = 2 and objective value = 0:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optmodel;
   set YEARS = 2013..2016;
   set DAYS;
   num temp{DAYS, YEARS};
   read data temp into DAYS=[Log] {y in YEARS} &amp;lt;temp[Log,y]=col('y'||y)&amp;gt;;
   var a,b;
   impvar CU{p in DAYS, y in YEARS} = (if a &amp;lt;= temp[p,y] &amp;lt;= b then 1 else 0);
   impvar S{y in YEARS} = sum{p in DAYS} CU[p,y];
   impvar mean = (sum{y in YEARS} S[y])/card(YEARS);
   minimize CoefvSquared = (sum{y in YEARS}((S[y]-mean)**2)/card(YEARS))/mean^2;
   a = min {p in DAYS, y in YEARS} temp[p,y];
   b = max {p in DAYS, y in YEARS} temp[p,y];
   solve;
   /* display solution */
   print a b;
   print S mean CoefvSquared;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that I squared the objective to avoid the SQRT function, which is nondifferentiable at 0.&amp;nbsp; Also, the a and b values supplied as a starting solution are computed as min and max, respectively,&amp;nbsp;across all observations.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 18:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Minimizing-the-standard-deviation-between-the-sum-of-different/m-p/474537#M2297</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2018-06-29T18:03:58Z</dc:date>
    </item>
  </channel>
</rss>

