Beispiel #1
0
def Zipf_subdivision_to_flows(quantity, shape, nbr_flows_max, Xmin):
    flows = []
    i = 0
    z = 0
    nbr_flows = 0
    nbr_flows = int(rand.uniform(nbr_flows_max / 2, nbr_flows_max))
    while (len(flows) < nbr_flows):
        z = zipf.rvs(shape)
        if z < nbr_flows:
            flows.append(z)
        i = i + 1
    (nbrs, intervals) = np.histogram(flows, bins=nbr_flows)

    flows = []
    for l in nbrs:
        if l * int(quantity / (nbr_flows)) + 1 < Xmin:
            flows.append(Xmin)
        else:
            flows.append(l * int(quantity / (nbr_flows)) + 1)

    i = 0
    total = 0
    #fd = open(str(quantity)+".txt", "w")
    for i in range(nbr_flows):
        total = total + flows[i]
        #fd.write("%s %s\n" %(i,flows[i]))
    flows[0] = flows[0] - (total - quantity)
    return flows
Beispiel #2
0
def add_general(phi, theta, num_docs, num_words, deg=0.5):
    "добавляет фоновую тему, deg - её вероятность появления в каждом документе, 0 < deg < 1"
    "num_docs и num_words обычно совпадают с соответствующими размерами phi, theta"
    gen_topic = zipf.rvs(1.01, size=num_words, random_state=1)
    gen_topic = gen_topic / np.sum(gen_topic)
    phi = np.append(phi, gen_topic.reshape(num_words, 1), axis=1)
    theta = theta * (1 - deg)
    theta = np.append(theta, (np.ones(num_docs) * deg).reshape(1, num_docs),
                      axis=0)
    return (phi, theta)
Beispiel #3
0
    Additional keyword arguments are passed to `matplotlib.pyplot.loglog`.
    '''
    x = np.asarray(x)
    exp_max = np.ceil(np.log2(x.max()))
    bins = np.logspace(0, exp_max, exp_max + 1, base=2)
    ax = plt.gca()
    hist, _ = np.histogram(x, bins=bins)
    binsize = np.diff(np.asfarray(bins))
    hist = hist / binsize
    ax.loglog(bins[1:], hist, 'ow', **kwargs)
    return ax


if __name__ == '__main__':
    from scipy.stats import zipf
    x = zipf.rvs(2, size=10000)
    plt.figure(figsize=(9, 3))
    plt.subplot(131)
    plot_cdf(x, fractional=False)
    plt.title("CCDF")
    ylim = plt.ylim()

    plt.subplot(132)
    plot_cdf(x)
    plt.title("CCDF with fractional ranks")
    plt.ylim(*ylim)

    plt.subplot(133)
    plot_pdf_log2(x)
    plt.title("PDF")
Beispiel #4
0
def trafic(src, dst, sim_time, burst, idle, shape, nb_flux):

    debut = math.floor(sim_time * 0.10)
    fin = sim_time - debut

    dst.write("Agent/TCP set packetSize_ 1500\n")
    dst.write("Agent/TCP set windowSize_ 536\n")
    dst.write("Agent/UDP set packetSize_ 1500\n")

    for line in src:

        traf = line.rstrip('\n\r').split(" ")
        data = int(traf[2])

        pareto_traf = int(math.floor(0.85 * data))
        ftp_traf = int(data - pareto_traf)

        nb_cycle = (burst + idle) / sim_time
        rate_val = (pareto_traf * 2) / sim_time

        if rate_val == 0:
            print "\nValeur nulle %s avec pareto*2 : %s sim_time: %s" % (
                rate_val, pareto_traf * 2, sim_time)
            rate_val = (pareto_traf * 2 * 1000) / sim_time
            print "New rate %s\n" % (rate_val)
            rate = rate_val * pow(10, 1)
            #rate = 1
        else:
            rate = rate_val * pow(10, 3)
            #rate = rate_val

        dst.write("set sink_udp(%s,%s) [new Agent/UDP]\n" % (traf[0], traf[1]))
        dst.write("$ns attach-agent $n(%s) $sink_udp(%s,%s)\n" %
                  (traf[1], traf[0], traf[1]))
        dst.write("set udp(%s,%s) [new Agent/UDP]\n" % (traf[0], traf[1]))
        dst.write("$ns attach-agent $n(%s) $udp(%s,%s)\n" %
                  (traf[0], traf[0], traf[1]))
        dst.write("$ns connect $udp(%s,%s) $sink_udp(%s,%s)\n" %
                  (traf[0], traf[1], traf[0], traf[1]))

        dst.write("set p(%s,%s) [new Application/Traffic/Pareto]\n" %
                  (traf[0], traf[1]))
        dst.write("$p(%s,%s) set packetSize_ 1500\n" % (traf[0], traf[1]))
        dst.write("$p(%s,%s) set burst_time_ %sms\n" %
                  (traf[0], traf[1], burst))
        dst.write("$p(%s,%s) set idle_time_ %sms\n" % (traf[0], traf[1], idle))
        dst.write("$p(%s,%s) set shape_ %s\n" % (traf[0], traf[1], shape))
        dst.write("$p(%s,%s) set rate_ %sk\n" % (traf[0], traf[1], rate))
        dst.write("$p(%s,%s) attach-agent $udp(%s,%s)\n" %
                  (traf[0], traf[1], traf[0], traf[1]))
        dst.write("$ns at %s \"$p(%s,%s) start\"\n" %
                  (debut, traf[0], traf[1]))
        dst.write("$ns at %s \"$p(%s,%s) stop\"\n\n" % (fin, traf[0], traf[1]))

        random_traf = 0
        i = 0

        print "%s %s" % (pareto_traf, ftp_traf)
        offset = multiple10(ftp_traf)

        while random_traf < ftp_traf:

            sent_val = zipf.rvs(shape) * offset
            instant = int(rand.uniform(debut, fin))
            if sent_val == 0:
                print "\nValeur nulle sent : %s\n" % (sent_val)
            sent = sent_val * pow(10, 3)
            #sent = sent_val

            if sent_val < ftp_traf and sent_val > 0:
                if i > nb_flux - 1:
                    dst.write("$ns at %s \"$tcp(%s,%s,%s) send %s\"\n\n" %
                              (instant, traf[0], traf[1], i % nb_flux, sent))

                else:
                    dst.write("set tcp(%s,%s,%s) [new Agent/TCP]\n" %
                              (traf[0], traf[1], i))
                    dst.write("$ns attach-agent $n(%s) $tcp(%s,%s,%s)\n" %
                              (traf[0], traf[0], traf[1], i))

                    dst.write("set sink(%s,%s,%s) [new Agent/TCPSink]\n" %
                              (traf[0], traf[1], i))
                    dst.write("$ns attach-agent $n(%s) $sink(%s,%s,%s)\n" %
                              (traf[1], traf[0], traf[1], i))
                    dst.write("$ns connect $tcp(%s,%s,%s) $sink(%s,%s,%s)\n" %
                              (traf[0], traf[1], i, traf[0], traf[1], i))
                    dst.write("$ns at %s \"$tcp(%s,%s,%s) send %sk\"\n\n" %
                              (instant, traf[0], traf[1], i, sent))

                random_traf += sent_val
                i += 1
Beispiel #5
0
 def _sample_scipy(self, size):
     s = float(self.s)
     from scipy.stats import zipf
     return zipf.rvs(a=s, size=size)
def generate_n_obs_zipf (tail_index, n) :
    return list(zipf.rvs(tail_index, size=n))
Beispiel #7
0
def generate_n_obs_zipf(tail_index, n):
    return list(zipf.rvs(tail_index, size=n))
Beispiel #8
0
def create_trafic(trace, output, on, off, forme, debut, fin, nb_flux):

    output.write("Agent/TCP set packetSize_ 1500\n")
    output.write("Agent/TCP set windowSize_ 75\n")
    output.write("Agent/UDP set packetSize_ 1500\n")

    for ligne in trace:

        decoupe = ligne.split()
        qtite = int(decoupe[2])

        pareto = int((0.85 * qtite) // 1)
        ftp = int(qtite - pareto)

        debit_temp = pareto * 2 / (fin + fin / 9)

        if debit_temp == 0:
            debit = debit_temp * 1000
        else:
            debit = debit_temp * 100

        output.write("set (sudp%s-%s) [new Agent/UDP]\n" %
                     (decoupe[0], decoupe[1]))
        output.write("$ns attach-agent $(n%s) $(sudp%s-%s)\n" %
                     (decoupe[1], decoupe[0], decoupe[1]))
        output.write("set (udp%s-%s) [new Agent/UDP]\n" %
                     (decoupe[0], decoupe[1]))
        output.write("$ns attach-agent $(n%s) $(udp%s-%s)\n" %
                     (decoupe[0], decoupe[0], decoupe[1]))
        output.write("$ns connect $(udp%s-%s) $(sudp%s-%s)\n" %
                     (decoupe[0], decoupe[1], decoupe[0], decoupe[1]))

        output.write("set (par%s-%s) [new Application/Traffic/Pareto]\n" %
                     (decoupe[0], decoupe[1]))
        output.write("$(par%s-%s) set packetSize_ 1500\n" %
                     (decoupe[0], decoupe[1]))
        output.write("$(par%s-%s) set burst_time_ %sms\n" %
                     (decoupe[0], decoupe[1], on))
        output.write("$(par%s-%s) set idle_time_ %sms\n" %
                     (decoupe[0], decoupe[1], off))
        output.write("$(par%s-%s) set shape_ %s\n" %
                     (decoupe[0], decoupe[1], forme))
        output.write("$(par%s-%s) set rate_ %sk\n" %
                     (decoupe[0], decoupe[1], debit))
        output.write("$(par%s-%s) attach-agent $(udp%s-%s)\n" %
                     (decoupe[0], decoupe[1], decoupe[0], decoupe[1]))
        output.write("$ns at %s \"$(par%s-%s) start\"\n" %
                     (debut, decoupe[0], decoupe[1]))
        output.write("$ns at %s \"$(par%s-%s) stop\"\n\n" %
                     (fin, decoupe[0], decoupe[1]))

        random = 0
        k = 0

        dec = mult(ftp)

        while random < ftp:
            sent = zipf.rvs(forme) * dec
            inst = int(rand.uniform(debut, fin))
            if sent == 0:
                print "\nValeur nulle envoyee : %s\n" % (sent)

            if sent < ftp and sent > 0:
                if k > nb_flux - 1:
                    output.write(
                        "$ns at %s \"$(tcp%s-%s-%s) send %s\"\n\n" %
                        (inst, decoupe[0], decoupe[1], k % nb_flux, sent))
                else:
                    output.write("set (tcp%s-%s-%s) [new Agent/TCP]\n" %
                                 (decoupe[0], decoupe[1], k))
                    output.write("$ns attach-agent $(n%s) $(tcp%s-%s-%s)\n" %
                                 (decoupe[0], decoupe[0], decoupe[1], k))
                    output.write("set (stcp%s-%s-%s) [new Agent/TCPSink]\n" %
                                 (decoupe[0], decoupe[1], k))
                    output.write("$ns attach-agent $(n%s) $(stcp%s-%s-%s)\n" %
                                 (decoupe[1], decoupe[0], decoupe[1], k))
                    output.write(
                        "$ns connect $(tcp%s-%s-%s) $(stcp%s-%s-%s)\n" %
                        (decoupe[0], decoupe[1], k, decoupe[0], decoupe[1], k))
                    output.write("$ns at %s \"$(tcp%s-%s-%s) send %sk\"\n\n" %
                                 (inst, decoupe[0], decoupe[1], k, sent))

                random += sent
                k += 1
Beispiel #9
0
# In[1]:

from scipy.stats import zipf
import numpy as np
import matplotlib.pyplot as plt

a = 2
k = 1
# x = np.arange(zipf.ppf(0.01, a),
#               zipf.ppf(0.99, a))

# rv = zipf(a)
# prob = zipf.cdf(x, a)
# np.allclose(x, zipf.ppf(prob, a))
r = zipf.rvs(a, size=10)
pf = zipf.pmf(k, a, loc=0)
# print(r)
#print(pf)
# pmf(k, a, loc=0)
# la = 1-pf

# In[2]:

# np.random.choice(5, 3, p=[0.1, 0, 0.3, 0.6, 0])

from random import choices
files = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
weights = [
    0.6079271018540265, 0.04356365534955261, 0.04356365534955261,
    0.04356365534955261, 0.04356365534955261, 0.04356365534955261,