<?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 QUAD Function in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/QUAD-Function/m-p/168940#M1652</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am running a large number of simulations. Below is a snippet of my code. The following code works but is not efficient as a result of the do loop. Can the QUAD function be vectorized for better efficiency?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Raphael&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Incomplete Gamma Function */&lt;/P&gt;&lt;P&gt;start IGF(a,b);&lt;/P&gt;&lt;P&gt;&amp;nbsp; return( b#gamma(a)#CDF('GAMMA', 1, a, 1/b) );&lt;/P&gt;&lt;P&gt;finish IGF;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Derivative of the Incomplete Gamma Function w.r.t. aa */&lt;/P&gt;&lt;P&gt;start DIGF(x) global(aa,bb);&lt;/P&gt;&lt;P&gt;&amp;nbsp; return( log(x)#x##(aa - 1/2)#exp(-x#bb/2) );&lt;/P&gt;&lt;P&gt;finish DIGF;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;nu = 3;&lt;/P&gt;&lt;P&gt;seed = 123456;&lt;/P&gt;&lt;P&gt;c = j(15000, 1, seed);&lt;/P&gt;&lt;P&gt;w = 2*uniform(c);&lt;/P&gt;&lt;P&gt;evalnum = J(nrow(w),1); /* pre-allocate matrix */&lt;/P&gt;&lt;P&gt;limits = {0 1};&lt;/P&gt;&lt;P&gt;do k = 1 to nrow(w);&lt;/P&gt;&lt;P&gt;&amp;nbsp; aa = nu; bb = w&lt;K&gt;;&lt;/K&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call quad(result, "DIGF", limits);&lt;/P&gt;&lt;P&gt;&amp;nbsp; evalnum&lt;K&gt; = result;&lt;/K&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;evalden = IGF(nu + 1/2,w/2);&lt;/P&gt;&lt;P&gt;r = evalnum/evalden;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Dec 2013 14:49:00 GMT</pubDate>
    <dc:creator>R_Fraser</dc:creator>
    <dc:date>2013-12-10T14:49:00Z</dc:date>
    <item>
      <title>QUAD Function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/QUAD-Function/m-p/168940#M1652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am running a large number of simulations. Below is a snippet of my code. The following code works but is not efficient as a result of the do loop. Can the QUAD function be vectorized for better efficiency?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Raphael&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Incomplete Gamma Function */&lt;/P&gt;&lt;P&gt;start IGF(a,b);&lt;/P&gt;&lt;P&gt;&amp;nbsp; return( b#gamma(a)#CDF('GAMMA', 1, a, 1/b) );&lt;/P&gt;&lt;P&gt;finish IGF;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Derivative of the Incomplete Gamma Function w.r.t. aa */&lt;/P&gt;&lt;P&gt;start DIGF(x) global(aa,bb);&lt;/P&gt;&lt;P&gt;&amp;nbsp; return( log(x)#x##(aa - 1/2)#exp(-x#bb/2) );&lt;/P&gt;&lt;P&gt;finish DIGF;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;nu = 3;&lt;/P&gt;&lt;P&gt;seed = 123456;&lt;/P&gt;&lt;P&gt;c = j(15000, 1, seed);&lt;/P&gt;&lt;P&gt;w = 2*uniform(c);&lt;/P&gt;&lt;P&gt;evalnum = J(nrow(w),1); /* pre-allocate matrix */&lt;/P&gt;&lt;P&gt;limits = {0 1};&lt;/P&gt;&lt;P&gt;do k = 1 to nrow(w);&lt;/P&gt;&lt;P&gt;&amp;nbsp; aa = nu; bb = w&lt;K&gt;;&lt;/K&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; call quad(result, "DIGF", limits);&lt;/P&gt;&lt;P&gt;&amp;nbsp; evalnum&lt;K&gt; = result;&lt;/K&gt;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;evalden = IGF(nu + 1/2,w/2);&lt;/P&gt;&lt;P&gt;r = evalnum/evalden;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Dec 2013 14:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/QUAD-Function/m-p/168940#M1652</guid>
      <dc:creator>R_Fraser</dc:creator>
      <dc:date>2013-12-10T14:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: QUAD Function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/QUAD-Function/m-p/168941#M1653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The answer to your question is no. The integral is a scalar quantity. As you change the parameters, the shape of the function changes and therefore the integration algorithm is different for each parameter. I suspect that the work required to set up each integral is small compared to the work to compute the integral, so I wouldn't expect much gain if QUAD were vectorized (maybe less than 10%?).&amp;nbsp; So I don't think that the DO loop is costing you much time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A question about your code: Your comment says "Derivative of the incomplete gamma fnc w.r.t. a"&lt;/P&gt;&lt;P&gt;Are you sure that formula is correct? I don't see where the 2s come from. That is, I wonder why (d/da)(IGF) would generate the terms x##(aa-1/2)#exp(-x#bb/2), rather than x##(a-1)#exp(-t##bb).&amp;nbsp;&amp;nbsp; But I admit that I don't understand what you are attempting.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Dec 2013 15:53:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/QUAD-Function/m-p/168941#M1653</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2013-12-10T15:53:52Z</dc:date>
    </item>
    <item>
      <title>Re: QUAD Function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/QUAD-Function/m-p/168942#M1654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you. The incomplete gamma function I am using is \int_{0}^{1} u^{(a + 1/2) - 1} \exp(-u*b) du and not the usual&amp;nbsp; \int_{0}^{x} u^{a - 1} \exp(-u) du.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Dec 2013 17:15:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/QUAD-Function/m-p/168942#M1654</guid>
      <dc:creator>R_Fraser</dc:creator>
      <dc:date>2013-12-10T17:15:03Z</dc:date>
    </item>
    <item>
      <title>Re: QUAD Function</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/QUAD-Function/m-p/168943#M1655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or rather &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;\int_{0}^{1} u^{(a + 1/2) - 1} \exp(-u*b/2) du&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Dec 2013 20:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/QUAD-Function/m-p/168943#M1655</guid>
      <dc:creator>R_Fraser</dc:creator>
      <dc:date>2013-12-10T20:13:34Z</dc:date>
    </item>
  </channel>
</rss>

