jeudi 15 avril 2021

Broken numpy prng

I'm generating points (x, y, radius) from a Poisson point process using numpy.random.poission distribution.

Here's my implementation:

import numpy as np


def index_to_coordinates(size, point):
    quotient, x = divmod(point, size)
    z, y = divmod(quotient, size)
    return x, y, z


def coordinates_to_index(size, x, y, z):
    return x + y * size + z * size ** 2


def poisson_point_process(rate, area):
    point = 0
    while point <= area:
        # w = int(-np.log(np.random.uniform(0, 1)) * rate)
        w = np.random.poisson(rate)
        point += w
        yield point

Most of the time seams to work fine, but with certain combination it breaks, i.g.

size = 256
area = size * size * 5 - 1  # 327679
rate = area // 30  # 10922

rate10922_area327679.png

or

size = 256
area = size * size * 8 - 1  # 524287
rate = area // 32  # 16383

rate16383_area524287.png.

My guess is due to some quirk in prng, but I couldn't find any obvious reason in source.

P.S. Please, tell me if I should elaborate.




Aucun commentaire:

Enregistrer un commentaire