Ejemplo n.º 1
0
def NHPP(num):
    rst = []
    LAMBDA = 7
    s = 0
    seed = 1234
    while num>0:
        seed, u1 = u16807d.u16807d(seed)
        lmbd = intensityFunction(s)
        s += -1/LAMBDA*np.log(u1)
        seed, u2 = u16807d.u16807d(seed)
        if u2*LAMBDA<intensityFunction(s):
            rst.append(s)
            num -= 1
    return rst
Ejemplo n.º 2
0
def poisgen(seed, lbmd):
    seed, u = u16807d.u16807d(seed)
    k = 0
    cu = 1
    P = 0
    while P<u:
        P += np.e**(-lbmd)*lbmd**k/cu
        k += 1
        cu *= k
    return seed, k-1
Ejemplo n.º 3
0
def LaplaceGenerator(lbda, iseed):
    """
        input:
            lbda    :   lambda
            iseed   :   current seed
        output:
            x       :   random variate obey laplace distribution
            iseed   :   new seed
    """
    iseed, u = u16807d.u16807d(iseed)
    x = -1.0/lbda*sgn(u-0.5)* np.log(1-2*np.abs(u-0.5))
    return x, iseed
Ejemplo n.º 4
0
def Beasley_Springer_Moro(seed):
    a0=2.50662823884;
    a1=-18.61500062529;
    a2=41.39119773534;
    a3=-25.44106049637;

    b0=-8.47351093090;
    b1=23.08336743743;
    b2=-21.06224101826;
    b3=3.13082909833;

    c0=0.3374754822726147;
    c1=0.9761690190917186;
    c2=0.1607979714918209;
    c3=0.0276438810333863;
    c4=0.0038405729373609;
    c5=0.0003951896511919;
    c6=0.0000321767881768;
    c7=0.0000002888167364;
    c8=0.0000003960315187;

    seed, u1 = u16807d.u16807d(seed)
    y = u1 - 0.5
    result = 0


    if (abs(y) < 0.42):
        r = y*y
        result = y * (a0 + r*(a1 + r*(a2 + r*a3))) / (1.0 + r*(b0 + r*(b1 + r*(b2 + r*b3))))
    else:
        if (y <= 0):
            r = u1
        else:
            r = 1 - u1
        # print r
        s = np.log( - np.log(r) )
        t = c0 + s*(c1 + s*(c2 + s*(c3 + s*(c4 + s*(c5 + s*(c6 + s*(c7+ s*c8)))))))

        if (u1>0.5):
            result = t
        else:
            result = -t

    return result, seed
Ejemplo n.º 5
0
def newsvendorOneDay(iseed, x):
    """
        input:
            iseed   :   uniform random seed
            x       :   daily purchased newspaper
        output:
            iseed   :   new value of iseed
            profit  :   profit on this day
    """
    c, s, w = 15, 70, 3
    lmda = 35
    iseed, u = u16807d.u16807d(iseed)
    pois = poisgen(lmda, u)

    profit = 0
    if (x>pois):
        profit = (s-c)*pois - (c-w)*(x-pois)
    else:
        profit = (s-c)*x

    return iseed, profit
Ejemplo n.º 6
0
def main():
    seed = 1
    for i in range(0, 10000):
        seed, u16807 = u16807d.u16807d(seed)
    print seed, u16807