<?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: maximization in proc iml with global variable in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174186#M1726</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;here are an example set of values for m, d and gamma&lt;/P&gt;&lt;P&gt;M:30329&lt;/P&gt;&lt;P&gt;gamma: -2.337336246&lt;/P&gt;&lt;P&gt;d: 252.48226708&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 May 2014 16:07:56 GMT</pubDate>
    <dc:creator>akaz</dc:creator>
    <dc:date>2014-05-28T16:07:56Z</dc:date>
    <item>
      <title>maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174176#M1716</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi all,&lt;/P&gt;&lt;P&gt;i would like maximize a function that is similar to this: -(x-2*r)**2/2+3*r&amp;nbsp; for x with global variable r in proc iml and to be able to use the result in a further step in iml. &lt;/P&gt;&lt;P&gt;(the expected result would be 2r)&lt;/P&gt;&lt;P&gt;i started the code:&lt;/P&gt;&lt;P&gt;proc iml; &lt;/P&gt;&lt;P&gt;start f(x) global(r);&lt;/P&gt;&lt;P&gt;&amp;nbsp; f=-(x-2*r)**2/2+3*r;&lt;/P&gt;&lt;P&gt;&amp;nbsp; return(f);&lt;/P&gt;&lt;P&gt;finish f;&lt;/P&gt;&lt;P&gt;x0j={0.};&lt;/P&gt;&lt;P&gt;optnj={1 3};&lt;/P&gt;&lt;P&gt;call nlpcg(rc,xres,"f",x0j,optnj);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but i got the following error message:&lt;/P&gt;&lt;P&gt;98&amp;nbsp;&amp;nbsp; proc iml;&lt;/P&gt;&lt;P&gt;NOTE: IML Ready&lt;/P&gt;&lt;P&gt;99&amp;nbsp;&amp;nbsp; start f(x) global(r);&lt;/P&gt;&lt;P&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f=-(x-2*r)**2/2+3*r;&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(f);&lt;/P&gt;&lt;P&gt;102&amp;nbsp; finish f;&lt;/P&gt;&lt;P&gt;NOTE: Module F defined.&lt;/P&gt;&lt;P&gt;103&amp;nbsp; x0j={0.};&lt;/P&gt;&lt;P&gt;104&amp;nbsp; optnj={1 3};&lt;/P&gt;&lt;P&gt;105&amp;nbsp; call nlpcg(rc,xres,"f",x0j,optnj);&lt;/P&gt;&lt;P&gt;ERROR: (execution) Matrix has not been set to a value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is there a way to do the optimization and save the result as a module? Thanks for any help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anita&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 May 2014 15:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174176#M1716</guid>
      <dc:creator>akaz</dc:creator>
      <dc:date>2014-05-27T15:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174177#M1717</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You did not define r. The objective function uses r, so if it is not defined it will give you an error.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 May 2014 16:01:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174177#M1717</guid>
      <dc:creator>Hutch_sas</dc:creator>
      <dc:date>2014-05-27T16:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174178#M1718</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the answer! But my problem is that i cannot define r with a closed formula. I only know abt it that it should be between 0 and 1.&amp;nbsp; I will use the result of this maximization in a further step to define another function and will optimize that function for r, so at this step i cannot define r. Is there a way to have a result without specifying r? so the result would not be a value but a formula depending on r.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 08:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174178#M1718</guid>
      <dc:creator>akaz</dc:creator>
      <dc:date>2014-05-28T08:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174179#M1719</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Take the derivative of the expression. Set it equal to zero and solve for x.&amp;nbsp; That gives the optimal value as a formula that depends on r.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 09:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174179#M1719</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-05-28T09:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174180#M1720</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That would be great! Is there a way to calculate the derivatie in sas iml? I tried it with nlpfdd but i have the same problem as above.. Thanks for the help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 11:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174180#M1720</guid>
      <dc:creator>akaz</dc:creator>
      <dc:date>2014-05-28T11:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174181#M1721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could you give us or point us to a complete mathematical description of your problem? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 12:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174181#M1721</guid>
      <dc:creator>Hutch_sas</dc:creator>
      <dc:date>2014-05-28T12:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174182#M1722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SAS/IML is software for numerical computations; it does not perform symbolic algebra. You can use a program such as Mathematica or Maple for symbolic computations.&amp;nbsp; You might like to read the article &lt;A href="http://blogs.sas.com/content/iml/2011/10/14/hints-for-derivatives/" title="http://blogs.sas.com/content/iml/2011/10/14/hints-for-derivatives/"&gt; Optimizing? Two hints for specifying derivatives - The DO Loop&lt;/A&gt;, which also discusses using the free Wolfram Alpha software to compute symbolic derivatives.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In theory, derivatives are easy to compute, provided that the function is not too complicated and has an analytical expression.&lt;/P&gt;&lt;P&gt;Inverting the expression df/dx=0 is usually the hard part, since it is a root-finding problem. The NLP functions enable you to solve the problem without computing the derivatives or solving for roots.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree with Joe: say more about what you are trying to accomplish.&amp;nbsp; For example, are you trying to optimize the function for various values of r?&amp;nbsp; That is easy to accomplish by looping over the range of r.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 12:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174182#M1722</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-05-28T12:29:59Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174183#M1723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you for your help! i will try the do loop for the calculation. i was just wondering if there is a different way. You can find my problem below:&lt;IMG alt="optimization.jpg" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/6438_optimization.jpg" width="450" /&gt;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 12:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174183#M1723</guid>
      <dc:creator>akaz</dc:creator>
      <dc:date>2014-05-28T12:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174184#M1724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wow. That's a heck of a problem!&amp;nbsp; Here are some observations:&lt;/P&gt;&lt;P&gt;1) This is an optimization problem in R. The x variable gets integrated out. So the objective function is Psi(R).&amp;nbsp; That is the function to call from the NLP routines.&lt;/P&gt;&lt;P&gt;2) For each call to Psi, R is &lt;STRONG&gt;known&lt;/STRONG&gt;. It equals some value, so from within Psi you can find Theta. That might involve a separate computation that maximizes Chi(x) - x##2 / 2.&amp;nbsp; I've never tried to optimize a second function while I'm in the middle of optimizing the first function, but if necessary you can precompute Theta(R) on a grid of R values.&lt;/P&gt;&lt;P&gt;3) When you are computing Chi, use the &lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/67239/HTML/default/viewer.htm#n0xwiaolmajobwn1pc0rmukk88fr.htm"&gt;LOGCDF function&lt;/A&gt; to compute the first term and the &lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/67239/HTML/default/viewer.htm#p1xneyqyg9rrppn0zsxlwjla4cze.htm"&gt;LOGSDF function &lt;/A&gt;to compute the second term.&lt;/P&gt;&lt;P&gt;4) I do not know an easy way to integrate the integral inside the LOG function.&amp;nbsp; Does it have a name or do you know any more information about it?&amp;nbsp; To me, that looks like the hard part of this problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have written two blog posts that discuss optimizing a function that evaluates an integral:&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2014/03/05/optimizing-a-function-that-evaluates-an-integral/" title="http://blogs.sas.com/content/iml/2014/03/05/optimizing-a-function-that-evaluates-an-integral/"&gt; Optimizing a function that evaluates an integral - The DO Loop&lt;/A&gt; and&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2014/03/12/optimizing-a-function-of-an-integral/" title="http://blogs.sas.com/content/iml/2014/03/12/optimizing-a-function-of-an-integral/"&gt; Optimizing a function of an integral - The DO Loop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will think about this problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 14:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174184#M1724</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-05-28T14:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174185#M1725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you have values for m, D, and gamma?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 14:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174185#M1725</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-05-28T14:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174186#M1726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;here are an example set of values for m, d and gamma&lt;/P&gt;&lt;P&gt;M:30329&lt;/P&gt;&lt;P&gt;gamma: -2.337336246&lt;/P&gt;&lt;P&gt;d: 252.48226708&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 16:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174186#M1726</guid>
      <dc:creator>akaz</dc:creator>
      <dc:date>2014-05-28T16:07:56Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174187#M1727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks for the tip with the do loop, i could calculate maximum (i have to have a rather precise value as a result so i calculated it for 200 rs and selected the maximum based on that), but i have 300 sets of d,M and gamma, so if i calculate for all of them with the do loop it takes a lot of time and that is why it would be great to be able to do it otherwise. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 16:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174187#M1727</guid>
      <dc:creator>akaz</dc:creator>
      <dc:date>2014-05-28T16:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: maximization in proc iml with global variable</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174188#M1728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i calculated the integral with quad function and then used the log function for the result of the quad like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;proc nlp out=solve_x; &lt;/P&gt;&lt;P&gt;&amp;nbsp; max chi_comma; &lt;/P&gt;&lt;P&gt;&amp;nbsp; decvar x; &lt;/P&gt;&lt;P&gt;&amp;nbsp; p_hat=CDF('NORMAL',(&amp;amp;gamma.-x*&amp;amp;r.)/((1-(&amp;amp;r.**2))**0.5),0,1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; chi=&amp;amp;d.*log(p_hat)+(&amp;amp;m.-&amp;amp;d.)*log(1-p_hat);&lt;/P&gt;&lt;P&gt;&amp;nbsp; chi_comma=chi-(x**2)/2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set solve_x;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call symput("theta", chi_comma);&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %put max of chi_comma is &amp;amp;theta;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;proc iml; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; pi = constant("pi");&lt;/P&gt;&lt;P&gt;&amp;nbsp; start toint(x); &lt;/P&gt;&lt;P&gt;&amp;nbsp; p_hat=CDF('NORMAL',(&amp;amp;gamma.-x*&amp;amp;r.)/((1-(&amp;amp;r.**2))**0.5),0,1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; p=exp(&amp;amp;d.*log(p_hat)+(&amp;amp;m.-&amp;amp;d.)*log(1-p_hat)-&amp;amp;theta.-x**2/2);&lt;/P&gt;&lt;P&gt;&amp;nbsp; return(p); &lt;/P&gt;&lt;P&gt;&amp;nbsp; finish;&lt;/P&gt;&lt;P&gt;&amp;nbsp; interval = .M || .P; &lt;/P&gt;&lt;P&gt;&amp;nbsp; call quad(pm,"toint",interval); &lt;/P&gt;&lt;P&gt;&amp;nbsp; print pm[format=E21.14];&lt;/P&gt;&lt;P&gt;&amp;nbsp; psi=(log((1/((2*pi)**0.5))*pm)+&amp;amp;theta.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; print psi[format=E21.14];&lt;/P&gt;&lt;P&gt;&amp;nbsp; quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 May 2014 16:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/maximization-in-proc-iml-with-global-variable/m-p/174188#M1728</guid>
      <dc:creator>akaz</dc:creator>
      <dc:date>2014-05-28T16:25:09Z</dc:date>
    </item>
  </channel>
</rss>

