def _fifi2fid(x): x = kept_within(0.0, x) cdf = chyperexpo(means, qumul, x) pdf = dhyperexpo(means, qumul, x) fi = cdf - prob if pdf <= 0.0: if fi == 0.0: fi2fid = 1.0 else: fi2fid = MAXFLOAT else: fi2fid = fi/pdf return fi, fi2fid
def rhyperexpo(self, means, qumul, xmax=float('inf'), pmax=1.0): """ Generates a random number from the hyperexponential distribution f = sumk pk * exp(x/mk) / mk, F = sumk pk * (1-exp(x/mk)) NB Input to the function is the list of CUMULATIVE FREQUENCIES ! """ assert xmax >= 0.0, "xmax must be a non-negative float in rhyperexpo!" self._checkpmax(pmax, 'rhyperexpo') pmx = pmax if xmax < float('inf'): pmx = min(pmax, chyperexpo(means, qumul, xmax)) p = pmx * self.runif01() x = ihyperexpo(p, means, qumul) return x