<?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 Hypergeometric Distributions using viRngHypergeometric in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Hypergeometric-Distributions-using-viRngHypergeometric/m-p/941035#M14510</link>
    <description>&lt;P&gt;Hi&lt;BR /&gt;I try to create a random generator creating a list of " 6&amp;nbsp;integer numbers" out of 49 (simple example&amp;nbsp;for a&amp;nbsp;first case). &lt;BR /&gt;I use for this test the&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;viRngHypergeometric&lt;/STRONG&gt; C method for the hypergeometric distribution.&lt;BR /&gt;The (test) purpose is to simulate the "classical &amp;nbsp;school example" of the Lotto / Lottery game 6-49 for&amp;nbsp;6 exact winning numbers out of 49 where 6 "winning numbers"&amp;nbsp;are extracted from the pool of 49 balls or numbers.&lt;/P&gt;
&lt;P&gt;I never get the expected 6 random unique numbers out of the MKL &amp;nbsp;stream.&lt;BR /&gt;What am I doing wrong or didn't understood ?&lt;/P&gt;
&lt;P&gt;The source code is close to the example file &amp;lt;viRngHypergeometric.c&amp;gt; in the MKL 11&amp;nbsp;installed libraries and described in the manual on Page 2711 &amp;amp; 2712 of the Intel® Math Kernel Library Reference Manual&lt;BR /&gt;Document Number: 630813-060US MKL 11.1&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------&lt;/P&gt;
&lt;P&gt;[&amp;nbsp;int N_Ues&amp;nbsp;= 1000;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Buffer for values to be generated&lt;BR /&gt;&amp;nbsp;int r[N_Ues];&lt;BR /&gt;&amp;nbsp;int max2Print &amp;nbsp;= N_Ues/100;&lt;BR /&gt;&amp;nbsp;VSLStreamStatePtr stream;&lt;BR /&gt;&amp;nbsp;int i, errcode;&lt;BR /&gt;&amp;nbsp;int l&amp;nbsp;&amp;nbsp;= 49;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Lot size&lt;BR /&gt;&amp;nbsp;int&amp;nbsp;ss&amp;nbsp;= 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Size of sampling without replacement&lt;BR /&gt;&amp;nbsp;int&amp;nbsp;m&amp;nbsp;= 6;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Number of marked elements&lt;BR /&gt;&amp;nbsp;int&amp;nbsp;&amp;nbsp;SEED= 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/***** Initialize *****/&lt;BR /&gt;&amp;nbsp;errcode = vslNewStream( &amp;amp;stream, VSL_BRNG_MCG31,&amp;nbsp; SEED );&lt;BR /&gt;&amp;nbsp;CheckVslError( errcode );&lt;BR /&gt;&amp;nbsp;/***** Call RNG *****/&lt;BR /&gt;&amp;nbsp;errcode = viRngHypergeometric( VSL_RNG_METHOD_HYPERGEOMETRIC_H2PE, stream, N_Ues, r, l, ss, m );&lt;BR /&gt;&amp;nbsp;CheckVslError( errcode );&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;/***** Printing results *****/&lt;BR /&gt;&amp;nbsp;printf("\nSample of viRngHypergeometric.\n");&lt;BR /&gt;&amp;nbsp;printf("------------------------------\n\n");&lt;BR /&gt;&amp;nbsp;printf("Parameters:\n");&lt;BR /&gt;&amp;nbsp;printf("&amp;nbsp;N_Ues=%d&amp;nbsp;&amp;nbsp; Number of random values to be generated\n",N_Ues);&lt;BR /&gt;&amp;nbsp;printf("&amp;nbsp;&amp;nbsp;&amp;nbsp; Lot size:\t\t\t\tl=%d\n",l);&lt;BR /&gt;&amp;nbsp;printf("&amp;nbsp;&amp;nbsp;&amp;nbsp; Size of sampling without replacement:\ts=%d\n",ss);&lt;BR /&gt;&amp;nbsp;printf("&amp;nbsp;&amp;nbsp;&amp;nbsp; Number of marked elements: \t\tm=%d\n\n",m);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;printf("viRngHypergeometric Results (first %d numbers out of %d):\n", max2Print, N_Ues);&lt;BR /&gt;&amp;nbsp;printf("---------------------------\n");&lt;BR /&gt;&amp;nbsp;for(i=0;i&amp;lt; max2Print;i++) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;printf("r[%d]=%d\n",i,r&lt;I&gt;);&lt;BR /&gt;&amp;nbsp;}&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;/***** Deinitialize *****/&lt;BR /&gt;&amp;nbsp;errcode = vslDeleteStream( &amp;amp;stream );&lt;BR /&gt;&amp;nbsp;CheckVslError( errcode );&lt;/P&gt;
&lt;P&gt;]&lt;/P&gt;</description>
    <pubDate>Fri, 27 Sep 2013 16:36:26 GMT</pubDate>
    <dc:creator>snoopy</dc:creator>
    <dc:date>2013-09-27T16:36:26Z</dc:date>
    <item>
      <title>Hypergeometric Distributions using viRngHypergeometric</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Hypergeometric-Distributions-using-viRngHypergeometric/m-p/941035#M14510</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;I try to create a random generator creating a list of " 6&amp;nbsp;integer numbers" out of 49 (simple example&amp;nbsp;for a&amp;nbsp;first case). &lt;BR /&gt;I use for this test the&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;viRngHypergeometric&lt;/STRONG&gt; C method for the hypergeometric distribution.&lt;BR /&gt;The (test) purpose is to simulate the "classical &amp;nbsp;school example" of the Lotto / Lottery game 6-49 for&amp;nbsp;6 exact winning numbers out of 49 where 6 "winning numbers"&amp;nbsp;are extracted from the pool of 49 balls or numbers.&lt;/P&gt;
&lt;P&gt;I never get the expected 6 random unique numbers out of the MKL &amp;nbsp;stream.&lt;BR /&gt;What am I doing wrong or didn't understood ?&lt;/P&gt;
&lt;P&gt;The source code is close to the example file &amp;lt;viRngHypergeometric.c&amp;gt; in the MKL 11&amp;nbsp;installed libraries and described in the manual on Page 2711 &amp;amp; 2712 of the Intel® Math Kernel Library Reference Manual&lt;BR /&gt;Document Number: 630813-060US MKL 11.1&lt;/P&gt;
&lt;P&gt;-------------------------------------------------------&lt;/P&gt;
&lt;P&gt;[&amp;nbsp;int N_Ues&amp;nbsp;= 1000;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Buffer for values to be generated&lt;BR /&gt;&amp;nbsp;int r[N_Ues];&lt;BR /&gt;&amp;nbsp;int max2Print &amp;nbsp;= N_Ues/100;&lt;BR /&gt;&amp;nbsp;VSLStreamStatePtr stream;&lt;BR /&gt;&amp;nbsp;int i, errcode;&lt;BR /&gt;&amp;nbsp;int l&amp;nbsp;&amp;nbsp;= 49;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Lot size&lt;BR /&gt;&amp;nbsp;int&amp;nbsp;ss&amp;nbsp;= 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Size of sampling without replacement&lt;BR /&gt;&amp;nbsp;int&amp;nbsp;m&amp;nbsp;= 6;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Number of marked elements&lt;BR /&gt;&amp;nbsp;int&amp;nbsp;&amp;nbsp;SEED= 1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;/***** Initialize *****/&lt;BR /&gt;&amp;nbsp;errcode = vslNewStream( &amp;amp;stream, VSL_BRNG_MCG31,&amp;nbsp; SEED );&lt;BR /&gt;&amp;nbsp;CheckVslError( errcode );&lt;BR /&gt;&amp;nbsp;/***** Call RNG *****/&lt;BR /&gt;&amp;nbsp;errcode = viRngHypergeometric( VSL_RNG_METHOD_HYPERGEOMETRIC_H2PE, stream, N_Ues, r, l, ss, m );&lt;BR /&gt;&amp;nbsp;CheckVslError( errcode );&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;/***** Printing results *****/&lt;BR /&gt;&amp;nbsp;printf("\nSample of viRngHypergeometric.\n");&lt;BR /&gt;&amp;nbsp;printf("------------------------------\n\n");&lt;BR /&gt;&amp;nbsp;printf("Parameters:\n");&lt;BR /&gt;&amp;nbsp;printf("&amp;nbsp;N_Ues=%d&amp;nbsp;&amp;nbsp; Number of random values to be generated\n",N_Ues);&lt;BR /&gt;&amp;nbsp;printf("&amp;nbsp;&amp;nbsp;&amp;nbsp; Lot size:\t\t\t\tl=%d\n",l);&lt;BR /&gt;&amp;nbsp;printf("&amp;nbsp;&amp;nbsp;&amp;nbsp; Size of sampling without replacement:\ts=%d\n",ss);&lt;BR /&gt;&amp;nbsp;printf("&amp;nbsp;&amp;nbsp;&amp;nbsp; Number of marked elements: \t\tm=%d\n\n",m);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;printf("viRngHypergeometric Results (first %d numbers out of %d):\n", max2Print, N_Ues);&lt;BR /&gt;&amp;nbsp;printf("---------------------------\n");&lt;BR /&gt;&amp;nbsp;for(i=0;i&amp;lt; max2Print;i++) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;printf("r[%d]=%d\n",i,r&lt;I&gt;);&lt;BR /&gt;&amp;nbsp;}&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;/***** Deinitialize *****/&lt;BR /&gt;&amp;nbsp;errcode = vslDeleteStream( &amp;amp;stream );&lt;BR /&gt;&amp;nbsp;CheckVslError( errcode );&lt;/P&gt;
&lt;P&gt;]&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2013 16:36:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Hypergeometric-Distributions-using-viRngHypergeometric/m-p/941035#M14510</guid>
      <dc:creator>snoopy</dc:creator>
      <dc:date>2013-09-27T16:36:26Z</dc:date>
    </item>
    <item>
      <title>Hello,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Hypergeometric-Distributions-using-viRngHypergeometric/m-p/941036#M14511</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;For the parameters&amp;nbsp;specified above&amp;nbsp;(lot size l = 49, number of marked elements m = 6, and sampling size s = 1) Intel(R) MKL Hypergeometric RNG returns array consisting of 0s and 1s.&lt;/P&gt;
&lt;P&gt;If X is number of successes, then P{X=0}=~0.87755, P{X=1}=~0.12244, and P{X=0}+P{X=1}=1, that is the whole mass of the distribution is concentrated in those two points, 0 and 1.&lt;/P&gt;
&lt;P&gt;If you calculate ratio of 1s in the array r and compare it vs m / l you will find that the numbers are close. Using your example I get 0.123 and ~0.1224, correspondingly. This is expected as for s = 1 X has binomial distribution with parameter p = m / l.&lt;/P&gt;
&lt;P&gt;Does it answer your question?&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Andrey&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2013 06:56:37 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Hypergeometric-Distributions-using-viRngHypergeometric/m-p/941036#M14511</guid>
      <dc:creator>Andrey_N_Intel</dc:creator>
      <dc:date>2013-09-30T06:56:37Z</dc:date>
    </item>
    <item>
      <title>Hi Andrey,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Hypergeometric-Distributions-using-viRngHypergeometric/m-p/941037#M14512</link>
      <description>&lt;P&gt;Hi Andrey,&lt;/P&gt;
&lt;P&gt;Thanks fo rthe response. In fact I did an error in the previous post.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;EM&gt;int&amp;nbsp;ss&amp;nbsp;= 1;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Size of sampling without replacemen&lt;/EM&gt;&lt;/STRONG&gt;t&lt;/P&gt;
&lt;P&gt;The Sampling should be 6 as I would line to get a stream of 6 unique random integer out of 49.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;int&amp;nbsp;ss&amp;nbsp;= 6;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Size of sampling without replacement&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;E.g. I am expecting the 6 random integers to be (example only ) : 3,2,35,1,9,49.So each integer belongs to the range [1,49]. and is uniqueIf the stream extracted is bigger than 49 then I would expect at least the 6 first integer values to be unique as e.g. &lt;BR /&gt;{3,2,35,1,9,49} , {1,7,3,12,18,40}, etc... &lt;BR /&gt;&lt;BR /&gt;The next 6 values may contain values extrated in previous draws.In fact it should simulate multiple "Lotto 6-49" samples (as in UK &amp;amp; Germany) random values&lt;BR /&gt;&amp;nbsp;Sorry for the error using the sample &amp;lt;1&amp;gt; instead of &amp;lt;6&amp;gt;Thanks for a response.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2013 15:31:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Hypergeometric-Distributions-using-viRngHypergeometric/m-p/941037#M14512</guid>
      <dc:creator>snoopy</dc:creator>
      <dc:date>2013-09-30T15:31:38Z</dc:date>
    </item>
    <item>
      <title>Hello,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Hypergeometric-Distributions-using-viRngHypergeometric/m-p/941038#M14513</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Hypergeometric distribution&amp;nbsp;describes the probability of k successes in s draws. In other words, with hypergeometric RNG you would get the number&amp;nbsp;of successes, not the actual indices of lucky lottery balls.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At first glance, the approach below might work for your simulation - I assume it is not the only one.&lt;/P&gt;
&lt;P&gt;1. Define (at random or&amp;nbsp;in deterministic way)&amp;nbsp;which 6 among 49 marbles are lucky.&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp; Simulate&amp;nbsp;random extraction of 6 marbles from a lot of 49 marbles, unique integer numbers w/o replacement using the function UniformBits and, say, MT19937 BRNG as described in the pseudo-code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; a. Generate first number:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; viRngUniformBits( method, stream, 1, &amp;amp;r );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ball[1] = ( r % 49 )&amp;nbsp; +&amp;nbsp; 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;b. Generate the rest numbers by making sure that the numbers are unique&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for j = 2...6 {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; is_unique = false;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ( is_unique&amp;nbsp;!= true&amp;nbsp;) {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; viRngUniformBits( method, stream, 1, &amp;amp;r );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ball_idx = ( r % 49 )&amp;nbsp; +&amp;nbsp; 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; is_unique&amp;nbsp;= isIdxUnique( ball_idx, j, ball ); // the function that checks that balls_idx differs from the previous indices&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ball&lt;J&gt; = ball_idx;&lt;/J&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;3. It makes sense to confirm that number of successes in the those samples follows hypergeometric distribution (I did not do this but assume it does)&lt;/P&gt;
&lt;P&gt;4. The scheme&amp;nbsp;above just gives the idea about the approach and is not optimal from perspective of performance. It&amp;nbsp;admits optimization when, for example, you do multiple drawings of size 6.&lt;/P&gt;
&lt;P&gt;Another approach might rely on use of Hypergeometric RNG. The generator returns number k of&amp;nbsp;lucky marbles. So, you would need to choose any combination of k from the predefined 6 lucky marrbles, and s-k - from the rest&amp;nbsp;using the scheme above or similar.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Andrey&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2013 06:19:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Hypergeometric-Distributions-using-viRngHypergeometric/m-p/941038#M14513</guid>
      <dc:creator>Andrey_N_Intel</dc:creator>
      <dc:date>2013-10-01T06:19:28Z</dc:date>
    </item>
  </channel>
</rss>

