Ejemplo n.º 1
0
def gauss():
    """
    The driver for the generator based implementation
    """
    from Disk import Disk
    from Gaussian import Gaussian
    from Mersenne import Mersenne

    # inputs
    N = 10**5
    box = [(-1,1), (-1,1)]
    B = functools.reduce(operator.mul, ((right-left) for left,right in zip(*box)))#@\label{line:mc:volume}@
    # the point cloud generator
    generator = Mersenne()
    # the region of integration
    disk = Disk(center=(0,0), radius=1)
    # the integrand
    gaussian = Gaussian(mean=(0,0), spread=1/3)

    # the integration algorithm
    # build the point sample
    sample = generator.points(N, box)
    # select the interior points
    interior = disk.interior(sample)
    # compute the integral
    integral = B/N * sum(gaussian.eval(interior))#@\label{line:mc:integral}@

    # print the estimate of the integral
    print("integral: {:.8f}".format(integral))
    return
Ejemplo n.º 2
0
def gauss():
    """
    The driver for the generator based implementation
    """
    from Disk import Disk
    from Gaussian import Gaussian
    from Mersenne import Mersenne

    # inputs
    N = 10**7
    box = [(-1, -1), (1, 1)]
    B = functools.reduce(operator.mul,
                         ((right - left) for left, right in zip(*box)))
    # the point cloud generator
    generator = Mersenne()
    # the region of integration
    disk = Disk(center=(0, 0), radius=1)
    # the integrand
    gaussian = Gaussian(mean=(0, 0), spread=1 / 3)

    # the integration algorithm
    # build the point sample
    sample = generator.points(N, box)
    # select the interior points
    interior = disk.interior(sample)
    # compute the integral
    integral = B / N * sum(gaussian.eval(interior))

    # print out the estimate of the integral
    print("integral: {0:.8f}".format(integral))
    return
Ejemplo n.º 3
0
def gauss():
    """
    The driver for the object oriented solution
    """
    from Disk import Disk
    from Mersenne import Mersenne

    # inputs
    N = 10**5
    box = [(0,0), (1,1)]
    # the point cloud generator
    cloud = Mersenne()
    # the region of integration
    disk = Disk(center=(0,0), radius=1)

    # the integration algorithm
    total = 0
    interior = 0
    while total < N:
        point = cloud.point(box)
        if disk.interior(point):
            interior += 1
        total += 1

    # print out the estimate of #@$\pi$@
    print("pi: {0:.8f}".format(4*interior/N))
    return
Ejemplo n.º 4
0
def gauss():
    """
    The driver for the generator based implementation
    """
    from Disk import Disk
    from Mersenne import Mersenne

    # inputs
    N = 10**5
    box = [(0, 1), (0, 1)]
    # the point cloud
    cloud = Mersenne()
    # the region of integration
    disk = Disk(center=(0, 0), radius=1)

    # the integration algorithm
    # build the point sample
    sample = cloud.points(N, box)
    # count the interior points
    interior = count(disk.interior(sample))

    # print the estimate of π
    print("π: {:.8f}".format(4 * interior / N))
    return
Ejemplo n.º 5
0
def gauss():
    """
    The driver for the object oriented solution
    """
    from Disk import Disk
    from Mersenne import Mersenne

    # inputs
    N = 10**5
    box = [(0,1), (0,1)]
    # the point cloud generator
    cloud = Mersenne()
    # the region of integration
    disk = Disk(center=(0,0), radius=1)

    # the integration algorithm
    interior = 0
    for i in range(N):
        point = cloud.point(box)
        if disk.interior(point):
            interior += 1
    # print the estimate of π
    print("π: {:.8f}".format(4*interior/N))
    return
Ejemplo n.º 6
0
def gauss():
    """
    The driver for the object oriented solution
    """
    from Disk import Disk
    from Mersenne import Mersenne

    # inputs
    N = 10**5
    box = [(0, 1), (0, 1)]
    # the point cloud generator
    cloud = Mersenne()
    # the region of integration
    disk = Disk(center=(0, 0), radius=1)

    # the integration algorithm
    interior = 0
    for i in range(N):
        point = cloud.point(box)
        if disk.interior(point):
            interior += 1
    # print the estimate of π
    print("π: {:.8f}".format(4 * interior / N))
    return
Ejemplo n.º 7
0
def gauss():
    """
    The driver for the container based implementation
    """
    from Disk import Disk
    from Mersenne import Mersenne

    # inputs
    N = 10**5
    box = [(0,1), (0,1)]
    # the point cloud generator
    cloud = Mersenne()
    # the region of integration
    disk = Disk(center=(0,0), radius=1)

    # the integration algorithm
    # build the point sample
    sample = cloud.points(N, box)
    # count the interior points
    interior = len(disk.interior(sample))

    # print the estimate of π
    print("π: {:.8f}".format(4*interior/N))
    return