Quasi-Random Sequences in IronPython QuickStart Sample

Illustrates how to generate quasi-random sequences like Fauré and Sobol sequences using classes in the Numerics.NET.Statistics.Random namespace in IronPython.

View this sample in: C# Visual Basic F#

```Python
import numerics

from Extreme.Statistics.Random import *
from Extreme.Mathematics import *
from Extreme.Mathematics.LinearAlgebra import *

# Illustrates the use of quasi-random sequences by computing
# a multi-dimensional integral.

# This QuickStart Sample demonstrates the use of
# quasi-random sequences by computing
# a multi-dimensional integral.

# We will use one million points.
capacity = 10000
# The number of dimensions:
dimension = 5

# We will evaluate the function
#
#    Product(i = 1 -> # dimensions) |4 x[i] - 2|
#
# over the hypercube 0 <= x[i] <= 1. The value of this integral
# is exactly 1.

# This vector will hold the current vector in the sequence:
point = Vector.Create(dimension)
# Create the sequence:
sequence = HaltonSequence(point, capacity)

print "# iter.  Estimate"
# Compute the integral by summing over all points:
sum = 0.0
for i in range(1, capacity):
	if i % 1000 == 0:
		print "{0:6}  {1:8.4f}".format(i, sum / i)

	# Evaluate the integrand:
	functionValue = 1.0
	for j in range(dimension):
		functionValue *= abs(4.0*point[j]-2.0)
	sum += functionValue

	sequence.MoveNext()

# Print the final result.
print "Final estimate: {0:8.4f}".format(sum / capacity)
print "Exact value: 1.0000"
```