Poisson-distributed Random Generator

De Augusto Baffa Wiki
Revisão de 09h50min de 30 de dezembro de 2020 por Abaffa (discussão | contribs) (Criou página com '== Sample Python Code ==')
(dif) ← Edição anterior | Revisão atual (dif) | Versão posterior → (dif)
Ir para navegação Ir para pesquisar
Outros idiomas:
English • ‎português do Brasil

It is a discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time or space if these events occur with a known constant mean rate and independently of the time since the last event.

Sample Python Code

1 million attempts sample
def pseudo_poisson(alpha, size=1):
    """
    Poisson generator from uniform generator
    """
    poisson = []
    for _ in range(size):
    
        # Sets seed based on the decimal portion of the current system clock
        t = time.perf_counter()
        seed = int(10**9*float(str(t-int(t))[0:]))
        
        U = pseudo_uniform(seed=seed, size=5*alpha)
        X,P,i = 0,1,0
        while P >= np.exp(-alpha):
            P = U[i]*P
            X += 1
            i += 1
        
        poisson.append(X)
    
    return np.array(poisson)