Exemple #1
0
def Reff(data, si_mean, si_sd, tau=7, conf=0.95, mu=5):
    """ effective reproduction number
    assuming exponential distribution for prior Reff
    input:
      data = daily number of incidence
      si_mean = mean of serial interval
      si_sd = standard deviation of serial interval
      tau = length of time window (integer in days)
      conf = confidence level of estimated Reff
      mu = mean of prior ditribution of Reff
    return:
      R = daily Reff of shape (3,len(data))
      R[0:3] = median, min, max
    reference:
      A. Cori et al
        American Journal of Epidemiology 178 (2013) 1505
          Web Appendix 1
    """
    N = len(data)
    w = si_distr(N, si_mean, si_sd)
    L = np.convolve(data, w)[:N]
    u = np.ones(tau)
    a = 1 + np.convolve(data, u)[:N]
    b = mu / (1 + mu * np.convolve(L, u)[:N])
    return np.vstack([gamma.median(a, 0, b), gamma.interval(conf, a, 0, b)])
import numpy as np
from copy import deepcopy

from scipy.stats import gamma

from problems.vendor_problem.vendor import simulation

runlength = 5
n_customers = 1000
n_products = 2
cost = [5, 10]
sell_price = [8, 18]

set_constraints = {}
median = gamma.median(n_customers, scale=1)
intervals = [[0.0, median], [median, np.inf]]
for i in xrange(2):
    for j in xrange(2):
        set_constraints[i * 2 + j] = [intervals[i], intervals[j]]

# n=5
# x=[2, 3, 4, 1, 1]
# replications=5
# customers=10
# simulation(x, replications, customers, n, [5,6, 3, 1, 1], [8, 12, 7, 2, 3])


def toy_example(n_samples, x):
    """
Exemple #3
0
def gammamedian(concentration, scale):
    return gamma.median(a=concentration, scale=scale)
Exemple #4
0
 def median(self, n, p):
     med = gamma.median(self, n, p)
     return med
Exemple #5
0
    d3 = d3[0]/d0[0]
    d0 = d0[0]/d0[0]

    return dm2, dm1, d0, d1, d2, d3

#dm2, dm1, d0, d1, d2, d3 = getProbabilities(5)


# Example from:
# http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.gamma.html
# http://docs.scipy.org/doc/scipy-0.14.0/reference/tutorial/integrate.html

# gamma function
a = 5
rv = gamma(a, loc=0., scale = 1.)       # scale = 1.0 / lambda.
median = gamma.median(a)
mean = gamma.mean(a)

x0 = scipy.optimize.fsolve(lambda x: rv.pdf(x), 0.1)       # 0.3 is the starting point

# find the top
increase = True
df0 = 0
delta = 0.01
x = 0.01

while increase == True:
    h = rv.pdf(x+delta) - rv.pdf(x)
    if h < 0:
        increase = False
    else:
Exemple #6
0
    d0 = d0[0] / d0[0]

    return dm2, dm1, d0, d1, d2, d3


# dm2, dm1, d0, d1, d2, d3 = getProbabilities(5)


# Example from:
# http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.stats.gamma.html
# http://docs.scipy.org/doc/scipy-0.14.0/reference/tutorial/integrate.html

# gamma function
a = 5
rv = gamma(a, loc=0.0, scale=1.0)  # scale = 1.0 / lambda.
median = gamma.median(a)
mean = gamma.mean(a)

x0 = scipy.optimize.fsolve(lambda x: rv.pdf(x), 0.1)  # 0.3 is the starting point

# find the top
increase = True
df0 = 0
delta = 0.01
x = 0.01

while increase == True:
    h = rv.pdf(x + delta) - rv.pdf(x)
    if h < 0:
        increase = False
    else: