<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>pseudorandom Archives - CenterSpace</title>
	<atom:link href="https://www.centerspace.net/tag/pseudorandom/feed" rel="self" type="application/rss+xml" />
	<link>https://www.centerspace.net/tag/pseudorandom</link>
	<description>.NET numerical class libraries</description>
	<lastBuildDate>Tue, 01 Mar 2016 21:44:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>
<site xmlns="com-wordpress:feed-additions:1">104092929</site>	<item>
		<title>Quasirandom Points</title>
		<link>https://www.centerspace.net/quasirandom-points</link>
					<comments>https://www.centerspace.net/quasirandom-points#respond</comments>
		
		<dc:creator><![CDATA[Ken Baldwin]]></dc:creator>
		<pubDate>Wed, 09 Feb 2011 16:05:44 +0000</pubDate>
				<category><![CDATA[NMath]]></category>
		<category><![CDATA[NMath Tutorial]]></category>
		<category><![CDATA[.net quasirandom]]></category>
		<category><![CDATA[c# quasi random]]></category>
		<category><![CDATA[c# quasirandom]]></category>
		<category><![CDATA[pseudorandom]]></category>
		<category><![CDATA[quasi-random numbers]]></category>
		<category><![CDATA[quasirandom numbers]]></category>
		<category><![CDATA[vb.net quasirandom]]></category>
		<guid isPermaLink="false">http://www.centerspace.net/blog/?p=3192</guid>

					<description><![CDATA[<p><img class="excerpt" title="Quasirandom Points" src="https://www.centerspace.net/blog/wp-content/uploads/2011/02/quasirandom2.png" alt="Quasirandom Points" /><br />
A quasirandom sequence is a set of n-tuples that fills n-space more uniformly than uncorrelated random points. NMath provides both Sobol and Niederreiter quasirandom number generators for .NET applications.</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/quasirandom-points">Quasirandom Points</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>A <a href="https://en.wikipedia.org/wiki/Low-discrepancy_sequence">quasirandom</a> sequence is a set of n-tuples that fills n-space more uniformly than uncorrelated random points. NMath provides both Sobol and Niederreiter quasirandom number generators for .NET applications.</p>
<p>For example, this C# code creates a Niederreiter quasirandom number generator object to generate quasirandom vectors of length 2:</p>
<pre lang="csharp">int dim = 2;
NiederreiterQuasiRandomGenerator nqrg =
  new NiederreiterQuasiRandomGenerator(dim);</pre>
<p>You can use an NMath quasirandom generator to fill a matrix or array. The points are the columns of the matrix, so the number of rows in the given matrix must be equal to the dimension of the quasirandom number generator. Here we create and fill a 2 x 500 matrix with quasirandom numbers from a uniform (0,1) distribution.</p>
<pre lang="csharp">int n = 500;
DoubleMatrix A = new DoubleMatrix(dim, n);
nqrg.Fill(A);</pre>
<p>We can plot the points to see the distribution.</p>
<p style="text-align: center;"><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/02/quasirandom2.png"><img decoding="async" class="size-full wp-image-3196 aligncenter" title="Quasirandom Points" src="https://www.centerspace.net/blog/wp-content/uploads/2011/02/quasirandom2.png" alt="Quasirandom Points" width="387" height="400" srcset="https://www.centerspace.net/wp-content/uploads/2011/02/quasirandom2.png 387w, https://www.centerspace.net/wp-content/uploads/2011/02/quasirandom2-290x300.png 290w" sizes="(max-width: 387px) 100vw, 387px" /></a></p>
<p>Let&#8217;s compare the results above with the distribution from a standard pseudorandom generator.</p>
<pre lang="csharp">int seed = 0x345;
RandomNumberStream stream = new RandomNumberStream( seed, RandomNumberStream.BasicRandGenType.MersenneTwister );
DoubleRandomUniformDistribution unifDist = new DoubleRandomUniformDistribution();
DoubleMatrix B = new DoubleMatrix( dim, n, stream, unifDist );</pre>
<p>Plotting the results shows that the pseudorandom points are much less uniformly distributed. Regions of higher and lower density are clearly evident.</p>
<p><a href="https://www.centerspace.net/blog/wp-content/uploads/2011/02/pseudorandom.png"><img decoding="async" loading="lazy" class="aligncenter size-full wp-image-3214" title="pseudorandom" src="https://www.centerspace.net/blog/wp-content/uploads/2011/02/pseudorandom.png" alt="" width="400" height="392" srcset="https://www.centerspace.net/wp-content/uploads/2011/02/pseudorandom.png 400w, https://www.centerspace.net/wp-content/uploads/2011/02/pseudorandom-300x294.png 300w" sizes="(max-width: 400px) 100vw, 400px" /></a></p>
<p>Quasirandom numbers have many applications, especially in Monte Carlo simulations. For instance, a classic use of the Monte Carlo method is for the evaluation of definite integrals. Let&#8217;s use an NMath Sobol generator to approximate the integral of a function F over a 6-dimensional unit cube. The function is defined by</p>
<p>F(x) = 1*cos(1*x1) * 2*cos(2*x2) * 3*cos(3*x3) *&#8230;* 6*cos(6*x6)</p>
<p>where x = (x1, x2,&#8230;, x6) is a point in 6-dimensional space.</p>
<p>This is the implementation of the function F:</p>
<pre lang="csharp">static double F( DoubleVector x )
{
  double y = 1;
  for ( int i = 1; i &lt;= x.Length; i++ )
  {
    y *= i * Math.Cos( i * x[i - 1] );
  }
  return y;
}</pre>
<p>In the following C# code we provide our own primitive polynomials for initializing the quasirandom generator. Primitive polynomials have coefficients in {0, 1} and are specified by BitArray&#8217;s containing the polynomial coefficients with the leading coefficient at index 0. We can supply either dim polynomials, or dim &#8211; 1 polynomials. If we specify dim &#8211; 1 polynomials, the primitive polynomial for the first dimension will be initialized with a default value.</p>
<pre lang="csharp">dim = 6;

BitArray[] primitivePolys = new BitArray[dim];
primitivePolys[0] = new BitArray( new bool[] { true, true } ); // x + 1
primitivePolys[1] = new BitArray( new bool[] { true, true, true } ); // x^2 + x + 1
primitivePolys[2] = new BitArray( new bool[] { true, false, true, true } ); // x^3 + x + 1
primitivePolys[3] = new BitArray( new bool[] { true, true, false, true } ); // x^3 + x^2 + 1
primitivePolys[4] = new BitArray( new bool[] { true, false, false, true, true } ); // x^4 + x + 1
primitivePolys[5] = new BitArray( new bool[] { true, true, false, false, true } ); // x^4 + x^3 + 1

SobolQuasiRandomGenerator sobol = new SobolQuasiRandomGenerator( dim, primitivePolys );</pre>
<p>Now let&#8217;s use this generator to approximate the integral:</p>
<pre lang="csharp">int numPoints = 180000;
DoubleMatrix points = new DoubleMatrix( dim, numPoints );
sobol.Fill( points );

double sum = 0;
for ( int i = 0; i &lt; numPoints; i++ )
{
  sum += F( points.Col( i ) );
}
sum /= numPoints;

double actualIntegralValue = -0.022;
Console.WriteLine( "Actual integral value = " + actualIntegralValue );
Console.WriteLine( "\nMonte-Carlo approximated integral value = " + sum );</pre>
<p>The output is:</p>
<pre>Actual integral value = -0.022
Monte-Carlo approximated integral value = -0.0232768655843053</pre>
<p>Ken</p>
<p>The post <a rel="nofollow" href="https://www.centerspace.net/quasirandom-points">Quasirandom Points</a> appeared first on <a rel="nofollow" href="https://www.centerspace.net">CenterSpace</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.centerspace.net/quasirandom-points/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3192</post-id>	</item>
	</channel>
</rss>
