Example #1
0
def boot_mednfrac(vector, centwin=0.90, confdeg=0.90, nsamples=None, \
                                            printns=False):
    """
    boot_mednfrac computes symmetric confidence limits for a median-fractile 
    estimate for confidence degree 'confdeg' using mednfrac and bootstrapping. 
    Lower and upper limit of 1) the median, 2) the lower fractile and 3) the 
    upper fractile for confidence degree 'confdeg'. When the number of bootstrap 
    samples nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1
    will be used. For printns=True the number of bootstrap samples used are 
    printed to stdout.
        
    For more general bootstrap sampling needs the methods 'bootvector' and 
    'bootindexvector' of the RandomStructure class may be used as a basis.
    """

    assert 0.0 <= centwin and centwin <= 1.0, \
          "Fractile interval must be in [0.0, 1.0] in boot_mednfrac!"
    assert 0.0 <= confdeg and confdeg <= 1.0, \
          "Confidence degree must be in [0.0, 1.0] in boot_mednfrac!"

    length  = len(vector)

    if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL/length)) + 1

    if nsamples < 101:
        nsamples = 101
        wtxt1 = "Number of samples in the bootstrap in boot_mednfrac should\n"
        wtxt2 = "be at least 101 (101 samples will be used)"
        warn(wtxt1+wtxt2)


    median = []
    lower  = []
    upper  = []

    rstream = GeneralRandomStream()
    for k in range(0, nsamples):
        bootv = [vector[rstream.runif_int0N(length)] for v in vector]
        med, low, upp = mednfrac(bootv, centwin)
        median.append(med)
        lower.append(low)
        upper.append(upp)

    med, lowmed, uppmed  =  mednfrac(median, confdeg)
    med, lowlow, upplow  =  mednfrac(lower,  confdeg)
    med, lowupp, uppupp  =  mednfrac(upper,  confdeg)

    if printns and nsamples != None:
        print("(number of bootstrap samples used in boot_mednfrac = " + \
                                                     str(nsamples) + ")")

    return lowmed, uppmed, lowlow, upplow, lowupp, uppupp
Example #2
0
def boot_mednfrac(vector, centwin=0.90, confdeg=0.90, nsamples=None, \
                                            printns=False):
    """
    boot_mednfrac computes symmetric confidence limits for a median-fractile 
    estimate for confidence degree 'confdeg' using mednfrac and bootstrapping. 
    Lower and upper limit of 1) the median, 2) the lower fractile and 3) the 
    upper fractile for confidence degree 'confdeg'. When the number of bootstrap 
    samples nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1
    will be used. For printns=True the number of bootstrap samples used are 
    printed to stdout.
        
    For more general bootstrap sampling needs the methods 'bootvector' and 
    'bootindexvector' of the RandomStructure class may be used as a basis.
    """

    assert 0.0 <= centwin and centwin <= 1.0, \
          "Fractile interval must be in [0.0, 1.0] in boot_mednfrac!"
    assert 0.0 <= confdeg and confdeg <= 1.0, \
          "Confidence degree must be in [0.0, 1.0] in boot_mednfrac!"

    length = len(vector)

    if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL / length)) + 1

    if nsamples < 101:
        nsamples = 101
        wtxt1 = "Number of samples in the bootstrap in boot_mednfrac should\n"
        wtxt2 = "be at least 101 (101 samples will be used)"
        warn(wtxt1 + wtxt2)

    median = []
    lower = []
    upper = []

    rstream = GeneralRandomStream()
    for k in range(0, nsamples):
        bootv = [vector[rstream.runif_int0N(length)] for v in vector]
        med, low, upp = mednfrac(bootv, centwin)
        median.append(med)
        lower.append(low)
        upper.append(upp)

    med, lowmed, uppmed = mednfrac(median, confdeg)
    med, lowlow, upplow = mednfrac(lower, confdeg)
    med, lowupp, uppupp = mednfrac(upper, confdeg)

    if printns and nsamples != None:
        print("(number of bootstrap samples used in boot_mednfrac = " + \
                                                     str(nsamples) + ")")

    return lowmed, uppmed, lowlow, upplow, lowupp, uppupp
Example #3
0
def calcAvgCostOfB(mu_r, b):
    costs = []
    global server_service_time
    global retrail_service_time
    server_service_time = GeneralRandomStream(201703271005 + 2**26 - 270317)
    retrail_service_time = GeneralRandomStream(201703272100 + 2**26 - 270317)
    for i in range(0, nrealizations):
        if i % 100 == 0:
            print("calcAvgCostOfB b = " + str(b) + " nrealizations = " +
                  str(i))
        costs += [calcCostOfB(mu_r, b, i)]
    mean_res = np.mean(costs)
    #print(str(b)+" costs: " + str(costs))
    print("Mean of " + str(b) + " costs: " + str(mean_res))
    return mean_res
Example #4
0
def boot_ratio(vnumer, vdenom, confdeg=0.90, nsamples=None, printns=False):
    """
    boot_ratio computes symmetric confidence limits for a ratio of a sum to 
    another sum for confidence degree 'confdeg' using bootstrapping. The 
    sums are defined by the two input sequences (lists/'d' arrays/tuples).
    Lower and upper limit are returned. When the number of bootstrap samples 
    nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 
    will be used. For printns=True the number of bootstrap samples used 
    are printed to stdout.
        
    For more general bootstrap sampling needs the methods 'bootvector' and 
    'bootindexvector' of the RandomStructure class may be used as a basis.
    """

    length  = len(vnumer)
    assert len(vdenom) == length, \
           "lengths of numerator and denominator must be equal in boot_ratio!"

    if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL/length)) + 1

    if nsamples < 101:
        nsamples = 101
        wtxt1 = "Number of samples in the bootstrap in boot_ratio should be\n"
        wtxt2 = "at least 101 (101 samples will be used)"
        warn(wtxt1+wtxt2)

    ratio   = []
    rstream = GeneralRandomStream()
    for k in range(nsamples):
        sumd    = 0.0
        sumn    = 0.0
        indexv  = [rstream.runif_int0N(length) for n in vnumer]
        for i in indexv:
           sumn += vnumer[i]
           sumd += vdenom[i]

        rate = sumn / float(sumd)   # Safety first - input could be ranks...
        ratio.append(rate)

    median, conflow, confupp  =  mednfrac(ratio, confdeg)

    if length <= 1: confupp = conflow = None

    if printns and nsamples != None:
        print("(number of bootstrap samples used in boot_ratio = " +\
                                                 str(nsamples) + ")")

    return conflow, confupp
Example #5
0
def boot_ratio(vnumer, vdenom, confdeg=0.90, nsamples=None, printns=False):
    """
    boot_ratio computes symmetric confidence limits for a ratio of a sum to 
    another sum for confidence degree 'confdeg' using bootstrapping. The 
    sums are defined by the two input sequences (lists/'d' arrays/tuples).
    Lower and upper limit are returned. When the number of bootstrap samples 
    nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 
    will be used. For printns=True the number of bootstrap samples used 
    are printed to stdout.
        
    For more general bootstrap sampling needs the methods 'bootvector' and 
    'bootindexvector' of the RandomStructure class may be used as a basis.
    """

    length = len(vnumer)
    assert len(vdenom) == length, \
           "lengths of numerator and denominator must be equal in boot_ratio!"

    if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL / length)) + 1

    if nsamples < 101:
        nsamples = 101
        wtxt1 = "Number of samples in the bootstrap in boot_ratio should be\n"
        wtxt2 = "at least 101 (101 samples will be used)"
        warn(wtxt1 + wtxt2)

    ratio = []
    rstream = GeneralRandomStream()
    for k in range(nsamples):
        sumd = 0.0
        sumn = 0.0
        indexv = [rstream.runif_int0N(length) for n in vnumer]
        for i in indexv:
            sumn += vnumer[i]
            sumd += vdenom[i]

        rate = sumn / float(sumd)  # Safety first - input could be ranks...
        ratio.append(rate)

    median, conflow, confupp = mednfrac(ratio, confdeg)

    if length <= 1: confupp = conflow = None

    if printns and nsamples != None:
        print("(number of bootstrap samples used in boot_ratio = " +\
                                                 str(nsamples) + ")")

    return conflow, confupp
Example #6
0
def calcAvgCostOfB(mu_r,b):
    #with open('simGraphs/avgPerIteration.log', 'a') as avglogFile:
#        print("mu_r = " ,mu_r, file=avglogFile)
    costs = []
    global server_service_time
    global retrail_service_time
    server_service_time  = GeneralRandomStream(seed)
    retrail_service_time = GeneralRandomStream(seed2)
    for i in range(0, nrealizations):
        if i % 100 == 0:
            print("calcAvgCostOfB b = " + str(b) + " nrealizations = " + str(i))
        costs += [calcCostOfB(mu_r,b, i)]
 #       if i % 10 == 0:
 #           print("calcAvgCostOfB b = " , str(b) , " nrealizations = " ,str(i), " avg till now = ",np.mean(costs))
 #           print("calcAvgCostOfB b = " , str(b) , " nrealizations = " ,str(i), " avg till now = ",np.mean(costs), file=avglogFile)
    mean_res = np.mean(costs)    
    #print(str(b)+" costs: " + str(costs))
    print("Mean of "+str(b)+" cost: "+str(mean_res))
    return mean_res
Example #7
0
def boot_aritmean(vector, confdeg=0.90, nsamples=None, printns=False):
    """
    boot_aritmean computes symmetric confidence limits around an arithmetic 
    mean estimate for confidence degree 'confdeg' using bootstrapping. Lower 
    and upper limit are returned. When the number of bootstrap samples 
    nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 will 
    be used. For printns=True the number of bootstrap samples used are printed 
    to stdout.
    
    For more general bootstrap sampling needs the methods 'bootvector' and 
    'bootindexvector' of the RandomStructure class may be used as a basis.
    """

    assert 0.0 <= confdeg and confdeg <= 1.0, \
          "Confidence degree must be in [0.0, 1.0] in boot_aritmean!"

    length  = len(vector)

    if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL/length)) + 1

    if nsamples < 101:
        nsamples = 101
        wtxt1 = "Number of samples in the bootstrap in boot_aritmean should\n"
        wtxt2 = "be at least 101 (101 samples will be used)"
        warn(wtxt1+wtxt2)

    ratio   = []
    rstream = GeneralRandomStream()
    for k in range(0, nsamples):
        bootv = [vector[rstream.runif_int0N(length)] for v in vector]
        rate  = fsum(bootv) / length   # Will be a float...
        ratio.append(rate)

    median, conflow, confupp  =  mednfrac(ratio, confdeg)

    if length <= 1: confupp = conflow = None

    if printns and nsamples != None:
        print("(number of bootstrap samples used in boot_aritmean = " +\
                                                    str(nsamples) + ")")

    return conflow, confupp
Example #8
0
def boot_aritmean(vector, confdeg=0.90, nsamples=None, printns=False):
    """
    boot_aritmean computes symmetric confidence limits around an arithmetic 
    mean estimate for confidence degree 'confdeg' using bootstrapping. Lower 
    and upper limit are returned. When the number of bootstrap samples 
    nsamples=None, a default number int(sqrt(_BOOTCARDINAL/length)) + 1 will 
    be used. For printns=True the number of bootstrap samples used are printed 
    to stdout.
    
    For more general bootstrap sampling needs the methods 'bootvector' and 
    'bootindexvector' of the RandomStructure class may be used as a basis.
    """

    assert 0.0 <= confdeg and confdeg <= 1.0, \
          "Confidence degree must be in [0.0, 1.0] in boot_aritmean!"

    length = len(vector)

    if nsamples == None: nsamples = int(sqrt(_BOOTCARDINAL / length)) + 1

    if nsamples < 101:
        nsamples = 101
        wtxt1 = "Number of samples in the bootstrap in boot_aritmean should\n"
        wtxt2 = "be at least 101 (101 samples will be used)"
        warn(wtxt1 + wtxt2)

    ratio = []
    rstream = GeneralRandomStream()
    for k in range(0, nsamples):
        bootv = [vector[rstream.runif_int0N(length)] for v in vector]
        rate = fsum(bootv) / length  # Will be a float...
        ratio.append(rate)

    median, conflow, confupp = mednfrac(ratio, confdeg)

    if length <= 1: confupp = conflow = None

    if printns and nsamples != None:
        print("(number of bootstrap samples used in boot_aritmean = " +\
                                                    str(nsamples) + ")")

    return conflow, confupp
Example #9
0
MAX_B_SIZE = 44
FIRST_B = 38
DELTA_B = 1



# Tests per one buffer
nrealizations  =  2000

#Org
#seed = 201703271005+ 2**26 - 270317
seed = 201703271005 
seed2 = 201703271005+ 2**26 - 270317

server_service_time   = GeneralRandomStream(seed)
retrail_service_time =  GeneralRandomStream(seed2)

targetfunction_time_vector = []
targetfunction_val_vector = []
debug_print_targetfuncval = False

plt.figure(figsize=(10,5))
c1 = 40.0
c2 = 2.0
l = 10000.0
mus = 10000.01
pL = 0.1
print("c1,c2,l,mus,pL = "+str(c1)+","\
+str(c2)+","\
+str(l)+","\
Example #10
0
# -- Simulation clock time in minutes --

# Should be the same for all tests:
START_MU_R = 0.0
DELTA_MU_R = 1.0
MAX_MU_R = 1.0

MAX_B_SIZE = 40
FIRST_B = 15
DELTA_B = 1

# Tests per one buffer
nrealizations = 5

server_service_time = GeneralRandomStream(201703271005 + 2**26 - 270317)
retrail_service_time = GeneralRandomStream(201703272100 + 2**26 - 270317)
targetfunction_time_vector = []
targetfunction_val_vector = []
eventvector_per_iter = []
timevector_per_iter = []
debug_print_targetfuncval = False

# ----------------------------------------------------------------------


#@profile
def new_customer(tim, mu_r, isReturned):
    global pLeave
    global rejected_till_now
    global c_1