<?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: Specifying nonlinear constraints for a genetic algorithm in SAS 9.2 in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65661#M409</link>
    <description>Using this strategy you can still vary all three parameters. I assume you can assign reasonable upper and lower bounds for each variable, and then generate a uniform distribution of solutions across those bounds. This fixup strategy then maps in a certian way the solutions that  fall outside the constraint to the constraint boundary.&lt;BR /&gt;
&lt;BR /&gt;
What is your actual objective function for this problem? Depending on your objective, you might also be able to transform variables to produce easier constraints.</description>
    <pubDate>Thu, 19 May 2011 18:03:21 GMT</pubDate>
    <dc:creator>Hutch_sas</dc:creator>
    <dc:date>2011-05-19T18:03:21Z</dc:date>
    <item>
      <title>Specifying nonlinear constraints for a genetic algorithm in SAS 9.2</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65657#M405</link>
      <description>I have been trying to setup a nonlinear constraint for a genetic algorithm in SAS 9.2 for some time now. &lt;BR /&gt;
The constraint is as follows;&lt;BR /&gt;
&lt;BR /&gt;
(-0.3) &amp;lt;= mort(x[1],.,x[2]/12,x[3]) / mort(coeff[1],.,coeff[2]/12,coeff[3]) &amp;lt;= -0.1&lt;BR /&gt;
Now, the nonlinear optimization calls like "&lt;I&gt;nlpqn&lt;/I&gt;" let me specify nonlinear constraints with the "&lt;I&gt;nlc&lt;/I&gt;" module. Do we have something similar for genetic algorithms?&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Rakesh

Message was edited by: Rakesh</description>
      <pubDate>Fri, 13 May 2011 12:36:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65657#M405</guid>
      <dc:creator>Rakesh</dc:creator>
      <dc:date>2011-05-13T12:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying nonlinear constraints for a genetic algorithm in SAS 9.2</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65658#M406</link>
      <description>My earlier post didn't print properly on the thread. This is what I was trying to say;&lt;BR /&gt;
&lt;BR /&gt;
I have been trying to setup a nonlinear constraint for a genetic algorithm in SAS 9.2 for some time now. &lt;BR /&gt;
The constraint is as follows;&lt;BR /&gt;
&lt;BR /&gt;
(-0.3) LT mort(x[1],.,x[2]/12,x[3]) / mort(coeff[1],.,coeff[2]/12,coeff[3]) LT -0.1&lt;BR /&gt;
&lt;BR /&gt;
where, LT stands for "Less than or Equal To"&lt;BR /&gt;
&lt;BR /&gt;
Now, the nonlinear optimization calls like "&lt;I&gt;nlpqn&lt;/I&gt;" let me specify nonlinear constraints with the "&lt;I&gt;nlc&lt;/I&gt;" module. Do we have something similar for genetic algorithms?</description>
      <pubDate>Fri, 13 May 2011 12:42:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65658#M406</guid>
      <dc:creator>Rakesh</dc:creator>
      <dc:date>2011-05-13T12:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying nonlinear constraints for a genetic algorithm in SAS 9.2</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65659#M407</link>
      <description>In general, with GA there are several different strategies for satisfying non-linear constraints. Probably the simplest way within IML for this particular problem is to simply "fix up" any solution that does not satisfy the non-linear constraint so that it does match the constraint. In this case, by the nature of the mort() function, the constraint violation function is linear in the first component x[1] ( the initial mortgage amount). That makes it easy to adjust your solution to reside on the nearest constraint boundary by modifying x[1] and leaving the other components unchanged. You can do that in the objective function with something like:&lt;BR /&gt;
&lt;BR /&gt;
start objective(x) global( coeff );&lt;BR /&gt;
/* assumes desired soution vector is in x, coeff is constant matrix */&lt;BR /&gt;
&lt;BR /&gt;
/* First, get the lower (lb) and upper (ub) bounds of the quantity &lt;BR /&gt;
   mort(x[1],.,x[2]/12,x[3]) &lt;BR /&gt;
*/&lt;BR /&gt;
&lt;BR /&gt;
const = mort(coeff[1],.,coeff[2]/12,coeff[3]); /* denominator */&lt;BR /&gt;
&lt;BR /&gt;
if const &amp;gt; 0 then do;&lt;BR /&gt;
ub = -0.1 * const;&lt;BR /&gt;
lb  = -0.3 *const;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
else do;&lt;BR /&gt;
ub = -0.3 * const;&lt;BR /&gt;
lb =  -0.1 * const;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
/* Now, fix up x[1] to make sure the constraint is satisfied */&lt;BR /&gt;
&lt;BR /&gt;
x0 = x[1];&lt;BR /&gt;
payment = mort(x0,.,x[2]/12,x[3]);&lt;BR /&gt;
&lt;BR /&gt;
if lb &amp;gt; payment then &lt;BR /&gt;
   x[1] = x0 * lb / payment; &lt;BR /&gt;
&lt;BR /&gt;
else if payment &amp;gt; ub then &lt;BR /&gt;
x[1] = x0 * ub / payment; &lt;BR /&gt;
&lt;BR /&gt;
/* now you have "fixed up" your solution to satisfy the constraint, go ahead and&lt;BR /&gt;
   compute the objective function */&lt;BR /&gt;
&lt;BR /&gt;
...</description>
      <pubDate>Fri, 13 May 2011 16:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65659#M407</guid>
      <dc:creator>Hutch_sas</dc:creator>
      <dc:date>2011-05-13T16:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying nonlinear constraints for a genetic algorithm in SAS 9.2</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65660#M408</link>
      <description>Thanks a lot Hutch. The answer was helpful. &lt;BR /&gt;
&lt;BR /&gt;
The problem I have is that I need to be able to vary all three parts of the mort() function to achieve this. So, whereas the function is linear in initial balance , it is not in the Interest Rate (x[2]) and the Amortization Term (x[3]). How do I change all three together, how do I distribute the bounds as weighting parameters amongst the three 'variables'?&lt;BR /&gt;
&lt;BR /&gt;
Do let me know if you have a solution. Your earlier answer did open a few door for me!</description>
      <pubDate>Tue, 17 May 2011 11:02:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65660#M408</guid>
      <dc:creator>Rakesh</dc:creator>
      <dc:date>2011-05-17T11:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying nonlinear constraints for a genetic algorithm in SAS 9.2</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65661#M409</link>
      <description>Using this strategy you can still vary all three parameters. I assume you can assign reasonable upper and lower bounds for each variable, and then generate a uniform distribution of solutions across those bounds. This fixup strategy then maps in a certian way the solutions that  fall outside the constraint to the constraint boundary.&lt;BR /&gt;
&lt;BR /&gt;
What is your actual objective function for this problem? Depending on your objective, you might also be able to transform variables to produce easier constraints.</description>
      <pubDate>Thu, 19 May 2011 18:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65661#M409</guid>
      <dc:creator>Hutch_sas</dc:creator>
      <dc:date>2011-05-19T18:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying nonlinear constraints for a genetic algorithm in SAS 9.2</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65662#M410</link>
      <description>Thanks Hutch.&lt;BR /&gt;
&lt;BR /&gt;
Below is the code for the objective function i'm trying to maximize; &lt;BR /&gt;
&lt;BR /&gt;
&lt;I&gt;proc iml;&lt;BR /&gt;
&lt;BR /&gt;
/* objective function, has minimum of 0 at x = xopt */&lt;BR /&gt;
start redefault(x) global(coeff);&lt;BR /&gt;
&lt;BR /&gt;
NewUPB=(1+coeff[14]-x[3]-x[4])*coeff[19];&lt;BR /&gt;
NewPIPmt=mort((1+coeff[14]-x[3]-x[4])*coeff[19],.,x[1]/12,x[2]-coeff[22]);&lt;BR /&gt;
OldPIPmt=mort(coeff[19],.,coeff[20]/12,coeff[21]-coeff[22]);&lt;BR /&gt;
CurrLTV=(1+coeff[14]-x[3]-x[4])*coeff[19]/coeff[18];&lt;BR /&gt;
LTVBasedOnOrigMV=(1+coeff[14]-x[3]-x[4])*coeff[19]/coeff[17];&lt;BR /&gt;
&lt;BR /&gt;
/*Upper and Lower Bounds for Chng in Pmt*/&lt;BR /&gt;
if OldPIPmt &amp;gt; 0 then do;&lt;BR /&gt;
ub = (1-0.1) * OldPIPmt;&lt;BR /&gt;
lb  = (1-0.3) * OldPIPmt;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
else do;&lt;BR /&gt;
ub = (1-0.3) * OldPIPmt;&lt;BR /&gt;
lb =  (1-0.1) * OldPIPmt;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
/*Fixup Variables - NOT BEING USED CURRENTLY*//*&lt;BR /&gt;
do while (lb&amp;gt;NewPIPmt);&lt;BR /&gt;
	x[1]=x[1]+.000125;&lt;BR /&gt;
	x[2]=x[2]-12;&lt;BR /&gt;
	/*x[3]=x[3]+.005;&lt;BR /&gt;
	x[4]=x[4]+.005;&lt;BR /&gt;
	NewPIPmt=mort((1+coeff[14]-x[3]-x[4])*coeff[19],.,x[1]/12,x[2]-coeff[22]);&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
do while (NewPIPmt &amp;gt; ub);&lt;BR /&gt;
	x[1]=x[1]-.000125;&lt;BR /&gt;
	NewPIPmt=mort((1+coeff[14]-x[3]-x[4])*coeff[19],.,x[1]/12,x[2]-coeff[22]);&lt;BR /&gt;
end;&lt;BR /&gt;
*/&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
RedefRt=1/(1+exp(-1*&lt;BR /&gt;
    (-5.2815+&lt;BR /&gt;
    1.8953*(NewPIPmt/OldPIPmt-1)+&lt;BR /&gt;
    1.6129*log(1+coeff[2])+&lt;BR /&gt;
    0.1531*coeff[3]+&lt;BR /&gt;
    0.3222*CurrLTV+&lt;BR /&gt;
    0.4368*LTVBasedOnOrigMV+&lt;BR /&gt;
    -2.7613*(coeff[4]- 1) +&lt;BR /&gt;
    0.00531*coeff[5]+&lt;BR /&gt;
    -0.6964*coeff[6]+&lt;BR /&gt;
    -0.2283*coeff[7]+&lt;BR /&gt;
    0.7078*coeff[8]+&lt;BR /&gt;
    0.1932*coeff[9]+&lt;BR /&gt;
    1.2001*coeff[10]+&lt;BR /&gt;
    0.3751*coeff[11]+&lt;BR /&gt;
    0.000808*coeff[12]+&lt;BR /&gt;
    -0.00297*coeff[13]+&lt;BR /&gt;
    0.9974*coeff[14]+&lt;BR /&gt;
    0.1633*coeff[15]+&lt;BR /&gt;
    -0.0949*coeff[16])));&lt;BR /&gt;
&lt;BR /&gt;
Proceeds = ((mort(.,NewPIPmt,x[1]/12,x[2]-coeff[22]-coeff[2])+(x[3]*coeff[19]))*(1-RedefRt) + coeff[23]*RedefRt);&lt;BR /&gt;
&lt;BR /&gt;
/* Penalize the children that don't conform to the constraints */&lt;BR /&gt;
if lb &amp;gt; NewPIPmt | coeff[20]&lt;X&gt; x[2] then &lt;BR /&gt;
	f=.5*Proceeds;&lt;BR /&gt;
else if NewPIPmt &amp;gt; ub | coeff[20]&lt;X&gt; x[2] then &lt;BR /&gt;
	f=.5*Proceeds;&lt;BR /&gt;
else f=Proceeds;&lt;BR /&gt;
&lt;BR /&gt;
return(f);&lt;BR /&gt;
finish redefault;&lt;/X&gt;&lt;/X&gt;&lt;/I&gt;&lt;BR /&gt;
&lt;BR /&gt;
Now, the non-linear constraint is that &lt;I&gt;(NewPIPmt/OldPIPmt-1)&lt;/I&gt; should be between -0.3 and -0.1, by varying the x[] parts of &lt;I&gt;NewPIPmt&lt;/I&gt;.</description>
      <pubDate>Mon, 23 May 2011 07:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65662#M410</guid>
      <dc:creator>Rakesh</dc:creator>
      <dc:date>2011-05-23T07:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying nonlinear constraints for a genetic algorithm in SAS 9.2</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65663#M411</link>
      <description>I don't have complete knowledge of your model, but could you use the ratio:&lt;BR /&gt;
&lt;BR /&gt;
NewPIPmt/OldPIPmt &lt;BR /&gt;
&lt;BR /&gt;
as one of your input parameters, instead of what you now have as x[4]? Since your x[4] only appears in the computation of of NewUPB, which would be computed directly from the mort() function, it would then go away and you could use x[4] for the new payment ratio parameter. Mathematically you could then just specify the correct bounds on that ratio directly and eliminate the  non-linear constraint. Your objective might look something like this:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
/* objective function, has minimum of 0 at x = xopt */&lt;BR /&gt;
start redefault(x) global(coeff);&lt;BR /&gt;
OldPIPmt=mort(coeff[19],.,coeff[20]/12,coeff[21]-coeff[22]);&lt;BR /&gt;
/* let x[4] = NewPIPmt/OldPIPmt */&lt;BR /&gt;
NewPIPmt = x[4] * OldPIPmt;&lt;BR /&gt;
/* solve for new principal */&lt;BR /&gt;
NewUPB = mort( ., NewPIPmt, x[1]/12,x[2]-coeff[22]);&lt;BR /&gt;
CurrLTV = NewUPB/coeff[18];&lt;BR /&gt;
LTVBasedOnOrigMV = NewUPB/coeff[17];&lt;BR /&gt;
&lt;BR /&gt;
RedefRt=1/(1+exp(-1*&lt;BR /&gt;
(-5.2815+&lt;BR /&gt;
1.8953*(NewPIPmt/OldPIPmt-1)+&lt;BR /&gt;
1.6129*log(1+coeff[2])+&lt;BR /&gt;
0.1531*coeff[3]+&lt;BR /&gt;
0.3222*CurrLTV+&lt;BR /&gt;
0.4368*LTVBasedOnOrigMV+&lt;BR /&gt;
-2.7613*(coeff[4]- 1) +&lt;BR /&gt;
0.00531*coeff[5]+&lt;BR /&gt;
-0.6964*coeff[6]+&lt;BR /&gt;
-0.2283*coeff[7]+&lt;BR /&gt;
0.7078*coeff[8]+&lt;BR /&gt;
0.1932*coeff[9]+&lt;BR /&gt;
1.2001*coeff[10]+&lt;BR /&gt;
0.3751*coeff[11]+&lt;BR /&gt;
0.000808*coeff[12]+&lt;BR /&gt;
-0.00297*coeff[13]+&lt;BR /&gt;
0.9974*coeff[14]+&lt;BR /&gt;
0.1633*coeff[15]+&lt;BR /&gt;
-0.0949*coeff[16])));&lt;BR /&gt;
&lt;BR /&gt;
Proceeds = ((mort(.,NewPIPmt,x[1]/12,x[2]-coeff[22]-coeff[2])+(x[3]*coeff[19]))*(1-RedefRt) + coeff[23]*RedefRt);&lt;BR /&gt;
&lt;BR /&gt;
return(Proceeds);&lt;BR /&gt;
finish;</description>
      <pubDate>Wed, 25 May 2011 19:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Specifying-nonlinear-constraints-for-a-genetic-algorithm-in-SAS/m-p/65663#M411</guid>
      <dc:creator>Hutch_sas</dc:creator>
      <dc:date>2011-05-25T19:25:11Z</dc:date>
    </item>
  </channel>
</rss>

