<?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 Hi, in Intel® Distribution for Python*</title>
    <link>https://community.intel.com/t5/Intel-Distribution-for-Python/How-to-generate-the-same-random-sequence-with-random-and-random/m-p/1147162#M1060</link>
    <description>&lt;P style="font-size: 13.008px;"&gt;Hi,&lt;/P&gt;

&lt;P style="font-size: 13.008px;"&gt;The class instance rg implements MT19937 algorithm which generates a pseudo-random sequence of 32-bit unsigned integers. All samplers within that class use this sequence to generate random samples from their distribution.&amp;nbsp;&lt;/P&gt;

&lt;P style="font-size: 13.008px;"&gt;The class instance ri also uses MT19937, implemented in MKL. If identically initialized both would generate the same stream of unsigned integers.&amp;nbsp;&lt;/P&gt;

&lt;P style="font-size: 13.008px;"&gt;The paper by Matsumoto, where the algorithm had been proposed, gave two initialization algorithms, one which takes a single seed (implemented in numpy.random.seed, but absent in MKL and hence in numpy.random_intel.seed), and one which takes a vector of numbers implemented in both numpy.random and in numpy.random_intel.&lt;/P&gt;

&lt;PRE class="brush:python;"&gt;In [1]: import numpy as np, numpy.random as vrng, numpy.random_intel as irng

In [2]: rg = vrng.RandomState([1234, 5678])

In [3]: ri = irng.RandomState([1234, 5678])

In [4]: rg.randint(0,2**32, size=10, dtype=np.uint32)
Out[4]: 
array([1880837566, 2718258354, 4147529071, 3731544169, 4197473601,
       1173020486, 1638125687, 3756842864,  909180233, 3754665251], dtype=uint32)

In [5]: ri.randint(0,2**32, size=10, dtype=np.uint32)
Out[5]: 
array([1880837566, 2718258354, 4147529071, 3731544169, 4197473601,
       1173020486, 1638125687, 3756842864,  909180233, 3754665251], dtype=uint32)
&lt;/PRE&gt;

&lt;P&gt;Initialization with the single integer seed in numpy.random_intel just interprets it as running the vector algorithm with length one vector containing that seed value:&lt;/P&gt;

&lt;PRE class="brush:python;"&gt;In [6]: ri = irng.RandomState([1234])

In [7]: ri.randint(0,2**32, size=10, dtype=np.uint32)
Out[7]: 
array([4150886329, 3342196574, 1892932127,  501869158,   32175636,
        389311301, 3912611952, 4048155970, 4034129617, 3466048957], dtype=uint32)

In [8]: ri = irng.RandomState(1234)

In [9]: ri.randint(0,2**32, size=10, dtype=np.uint32)
Out[9]: 
array([4150886329, 3342196574, 1892932127,  501869158,   32175636,
        389311301, 3912611952, 4048155970, 4034129617, 3466048957], dtype=uint32)
&lt;/PRE&gt;

&lt;P&gt;Even having the same underlying &lt;SPAN style="font-size: 13.008px;"&gt;pseudo-random&amp;nbsp;&lt;/SPAN&gt;sequence of uint32, numpy.random and numpy.random_intel use different algorithms to generate sequences of floating point numbers, even doubles:&lt;/P&gt;

&lt;PRE class="brush:python;"&gt;In [13]: rg = vrng.RandomState([1234, 5678])

In [14]: ri = irng.RandomState([1234, 5678])

In [15]: rg.rand(10)
Out[15]: 
array([ 0.43791662,  0.96567187,  0.97730048,  0.38140586,  0.21168502,
        0.36981215,  0.75081243,  0.99305566,  0.24318839,  0.09435813])

In [16]: ri.rand(10)
Out[16]: 
array([ 0.43791662,  0.63289384,  0.96567186,  0.86881783,  0.97730048,
        0.27311511,  0.38140586,  0.87470814,  0.21168502,  0.87420113])
&lt;/PRE&gt;

&lt;P&gt;In Monte-Carlo-type computations this should not matter, as the value obtained by the algorithms should be interpreted as a realization of&amp;nbsp; a random variable, and repeating the computation with a different seed is expected to produce a different value, another sample from the same distribution.&lt;/P&gt;</description>
    <pubDate>Fri, 27 Oct 2017 12:16:42 GMT</pubDate>
    <dc:creator>Oleksandr_P_Intel</dc:creator>
    <dc:date>2017-10-27T12:16:42Z</dc:date>
    <item>
      <title>How to generate the same random sequence with random and random_intel</title>
      <link>https://community.intel.com/t5/Intel-Distribution-for-Python/How-to-generate-the-same-random-sequence-with-random-and-random/m-p/1147161#M1059</link>
      <description>&lt;P&gt;Currently&lt;/P&gt;

&lt;PRE class="brush:python;"&gt;rg = numpy.random.mtrand.RandomState(1234)

ri = numpy.random_intel.RandomState(1234)&lt;/PRE&gt;

&lt;P&gt;However these two instance generate different sequences.&lt;/P&gt;

&lt;P&gt;rg.get_state() returns tuple while ri.get_state() returns bytes.&lt;/P&gt;

&lt;P&gt;how could I set rg's state to ri?&lt;/P&gt;

&lt;P&gt;Could they generate the same random sequences?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 07:47:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Distribution-for-Python/How-to-generate-the-same-random-sequence-with-random-and-random/m-p/1147161#M1059</guid>
      <dc:creator>Gang_Z_</dc:creator>
      <dc:date>2017-10-26T07:47:25Z</dc:date>
    </item>
    <item>
      <title>Hi,</title>
      <link>https://community.intel.com/t5/Intel-Distribution-for-Python/How-to-generate-the-same-random-sequence-with-random-and-random/m-p/1147162#M1060</link>
      <description>&lt;P style="font-size: 13.008px;"&gt;Hi,&lt;/P&gt;

&lt;P style="font-size: 13.008px;"&gt;The class instance rg implements MT19937 algorithm which generates a pseudo-random sequence of 32-bit unsigned integers. All samplers within that class use this sequence to generate random samples from their distribution.&amp;nbsp;&lt;/P&gt;

&lt;P style="font-size: 13.008px;"&gt;The class instance ri also uses MT19937, implemented in MKL. If identically initialized both would generate the same stream of unsigned integers.&amp;nbsp;&lt;/P&gt;

&lt;P style="font-size: 13.008px;"&gt;The paper by Matsumoto, where the algorithm had been proposed, gave two initialization algorithms, one which takes a single seed (implemented in numpy.random.seed, but absent in MKL and hence in numpy.random_intel.seed), and one which takes a vector of numbers implemented in both numpy.random and in numpy.random_intel.&lt;/P&gt;

&lt;PRE class="brush:python;"&gt;In [1]: import numpy as np, numpy.random as vrng, numpy.random_intel as irng

In [2]: rg = vrng.RandomState([1234, 5678])

In [3]: ri = irng.RandomState([1234, 5678])

In [4]: rg.randint(0,2**32, size=10, dtype=np.uint32)
Out[4]: 
array([1880837566, 2718258354, 4147529071, 3731544169, 4197473601,
       1173020486, 1638125687, 3756842864,  909180233, 3754665251], dtype=uint32)

In [5]: ri.randint(0,2**32, size=10, dtype=np.uint32)
Out[5]: 
array([1880837566, 2718258354, 4147529071, 3731544169, 4197473601,
       1173020486, 1638125687, 3756842864,  909180233, 3754665251], dtype=uint32)
&lt;/PRE&gt;

&lt;P&gt;Initialization with the single integer seed in numpy.random_intel just interprets it as running the vector algorithm with length one vector containing that seed value:&lt;/P&gt;

&lt;PRE class="brush:python;"&gt;In [6]: ri = irng.RandomState([1234])

In [7]: ri.randint(0,2**32, size=10, dtype=np.uint32)
Out[7]: 
array([4150886329, 3342196574, 1892932127,  501869158,   32175636,
        389311301, 3912611952, 4048155970, 4034129617, 3466048957], dtype=uint32)

In [8]: ri = irng.RandomState(1234)

In [9]: ri.randint(0,2**32, size=10, dtype=np.uint32)
Out[9]: 
array([4150886329, 3342196574, 1892932127,  501869158,   32175636,
        389311301, 3912611952, 4048155970, 4034129617, 3466048957], dtype=uint32)
&lt;/PRE&gt;

&lt;P&gt;Even having the same underlying &lt;SPAN style="font-size: 13.008px;"&gt;pseudo-random&amp;nbsp;&lt;/SPAN&gt;sequence of uint32, numpy.random and numpy.random_intel use different algorithms to generate sequences of floating point numbers, even doubles:&lt;/P&gt;

&lt;PRE class="brush:python;"&gt;In [13]: rg = vrng.RandomState([1234, 5678])

In [14]: ri = irng.RandomState([1234, 5678])

In [15]: rg.rand(10)
Out[15]: 
array([ 0.43791662,  0.96567187,  0.97730048,  0.38140586,  0.21168502,
        0.36981215,  0.75081243,  0.99305566,  0.24318839,  0.09435813])

In [16]: ri.rand(10)
Out[16]: 
array([ 0.43791662,  0.63289384,  0.96567186,  0.86881783,  0.97730048,
        0.27311511,  0.38140586,  0.87470814,  0.21168502,  0.87420113])
&lt;/PRE&gt;

&lt;P&gt;In Monte-Carlo-type computations this should not matter, as the value obtained by the algorithms should be interpreted as a realization of&amp;nbsp; a random variable, and repeating the computation with a different seed is expected to produce a different value, another sample from the same distribution.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2017 12:16:42 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Distribution-for-Python/How-to-generate-the-same-random-sequence-with-random-and-random/m-p/1147162#M1060</guid>
      <dc:creator>Oleksandr_P_Intel</dc:creator>
      <dc:date>2017-10-27T12:16:42Z</dc:date>
    </item>
    <item>
      <title>@Oleksandr P.</title>
      <link>https://community.intel.com/t5/Intel-Distribution-for-Python/How-to-generate-the-same-random-sequence-with-random-and-random/m-p/1147163#M1061</link>
      <description>&lt;P&gt;@&lt;A href="https://software.intel.com/en-us/user/1362272" style="outline: 0px; font-size: 12px; background-color: rgb(238, 238, 238);"&gt;Oleksandr P.&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks for your clean and detailed explanation. I summarize it&amp;nbsp;&lt;/P&gt;

&lt;OL&gt;
	&lt;LI&gt;Intel doesn't implement single seed(convert it to vector with one value), the result will be different from numpy&lt;/LI&gt;
	&lt;LI&gt;The same vector seed, Intel will be consistent with numpy for integer random sequences&lt;/LI&gt;
	&lt;LI&gt;Float/Double&amp;nbsp;&lt;SPAN style="font-size: 13.008px;"&gt;random sequences generation algorithm for Intel and Numpy are different, so the results are different, either.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;&lt;SPAN style="font-size: 1em;"&gt;In my project randn call will generate different float/double sequences. The application scenario is in risk computation(&lt;/SPAN&gt;&lt;SPAN style="font-size: 12px;"&gt;Monte-Carlo method&lt;/SPAN&gt;&lt;SPAN style="font-size: 1em;"&gt;). Beyond my expectation the different random matrix with &lt;/SPAN&gt;&lt;SPAN style="color: rgb(51, 51, 51); font-family: arial; font-size: 13px;"&gt;random normal distribution, the results are different...&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;I think It really helps. Thank you again.&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 06:31:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Distribution-for-Python/How-to-generate-the-same-random-sequence-with-random-and-random/m-p/1147163#M1061</guid>
      <dc:creator>Gang_Z_</dc:creator>
      <dc:date>2017-10-30T06:31:25Z</dc:date>
    </item>
  </channel>
</rss>

