mercredi 6 juillet 2016

How to evaluate beta distribution only once in python?

In a simulation that I am running I have to draw many many values from the same beta distribution. Currently, I am using

import random

...

for i in range(n_Aa):
   h = random.betavariate(a, b) // With some values for 'a' and 'b'

...

This code, however, is very slow. I think it is because the beta distribution is evaluated over and over again, when it could just be evaluated once since it does not change over the course of the simulation. Is there some way of achieving this?




Aucun commentaire:

Enregistrer un commentaire