예제 #1
0
def get_gamma_rates(a, YangGammaQuant, pp_gamma_ncat):
    b = a
    m = gdtrix(b, a, YangGammaQuant)  # user defined categories
    s = pp_gamma_ncat / sum(
        m
    )  # multiplier to scale the so that the mean of the discrete distribution is one
    return array(m) * s  # SCALED VALUES
예제 #2
0
def get_q_rate_samples():
    q_rates, alpha = res_q[np.random.choice(range(len(res_alpha))
                                            ), :], res_alpha[np.random.choice(
                                                range(len(res_alpha)))]
    if verbose: print("resample:", q_rates, alpha)
    q_rates_bins = get_q_rates_time_bins(q_rates, q_shifts, time_bins)
    rGamma = np.random.gamma(alpha, 1. / alpha, (10000, len(q_rates_bins) - 1))
    q_rates_bins_G = rGamma * (q_rates_bins[:-1] * q_multi_A)
    if verbose: print(q_rates_bins)
    if verbose: print(np.mean(q_rates_bins_G, 0))
    rho_bins_array = 1 - np.exp(-(q_rates_bins_G) * dTime)
    rho_bins = np.mean(rho_bins_array, 0)
    if verbose: print(1 - np.exp(-(q_rates_bins[:-1]) * dTime))
    if verbose: print(rho_bins)
    ncat = 100
    YangGammaQuant = (np.linspace(0, 1, ncat + 1) -
                      np.linspace(0, 1, ncat + 1)[1] / 2)[1:]
    rGamma = gdtrix(alpha, alpha, YangGammaQuant)  # user defined categories
    rGamma = np.repeat(rGamma,
                       len(q_rates_bins) - 1).reshape(
                           (ncat, len(q_rates_bins) - 1))
    return q_rates_bins, rGamma, alpha
예제 #3
0
def gdtrix_comp(b, p):
    return gdtrix(1.0, b, 1-p)
예제 #4
0
def gdtrix_(b, p):
    return gdtrix(1.0, b, p)
예제 #5
0
def gdtrix_comp(b, p):
    return gdtrix(1.0, b, 1-p)
예제 #6
0
def gdtrix_(b, p):
    return gdtrix(1.0, b, p)
예제 #7
0
 def _ppf(self, q, a):
     return special.gdtrix(1.0, a, q)
예제 #8
0
 def _ppf(self, q, a):
     return special.gdtrix(1.0, a, q)
예제 #9
0
    def quantile(self, p):
        """Return the p quantile of the Gamma posterior (using :func:`scipy.stats.gdtrix`).

        - Used only by :class:`BayesUCB` and :class:`AdBandits` so far.
        """
        return gdtrix(self.k, 1. / self.lmbda, p)
예제 #10
0
 def gamma(self, shape, scale=1.0, size=None):
     """ simulate Gamma variates """
     U = self.uniform(0, 1, size)
     X = special.gdtrix(1 / scale, shape, U)
     return X