Exemplo n.º 1
0
import sys
import networkx as nx
sys.path.append("..")
from implementation import network_distance as nd

with open("fig8.csv", 'w') as f:
    f.write(
        "chain length\tge\tmmc\tannihil\temd\tspl single\tspl avg\tspl complete\tgft\tmapp\n"
    )
    for n in range(2, 101):
        print(n)
        G = nx.path_graph(n)
        src = {0: 1}
        trg = {n - 1: 1}
        ge = nd.ge(src, trg, G)
        mmc = nd.mmc(src, trg, G)
        annihil = nd.annihilation(src, trg, G)
        emd = nd.emd(src, trg, G)
        spl_s = nd.spl(src, trg, G, linkage="single")
        spl_a = nd.spl(src, trg, G, linkage="avg")
        spl_c = nd.spl(src, trg, G, linkage="complete")
        gft_e = nd.gft(src, trg, G, linkage="euclidean")
        mapp = nd.mapp(src, trg, G)
        f.write("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n" %
                (n, ge, mmc, annihil, emd, spl_s, spl_a, spl_c, gft_e, mapp))
        f.flush()
Exemplo n.º 2
0
      G = generate_network(network_type)
      infection = random.random()
      line = []
      line.append("%s" % infection)
      src, trg = generate_change(G, infection)
      if len(trg) > 0:
         signal.alarm(2)
         try:
            mapp = float(nd.mapp(src, trg, G))
            signal.alarm(0)
         except:
            fail += 1
            sys.stderr.write("MAPP failed (%1.2f%% failure rate)\n" % (100 * fail / (fail + i)))
            continue
         i += 1
         sys.stderr.write("%s\n" % i)
         line.append("%s" % float(nd.ge(src, trg, G)))   
         line.append("%s" % float(nd.mmc(src, trg, G)))
         line.append("%s" % float(nd.annihilation(src, trg, G)))
         line.append("%s" % float(nd.emd(src, trg, G)))   
         line.append("%s" % float(nd.spl(src, trg, G, linkage = "single")))
         line.append("%s" % float(nd.spl(src, trg, G, linkage = "avg")))
         line.append("%s" % float(nd.spl(src, trg, G, linkage = "complete")))   
         line.append("%s" % float(nd.gft(src, trg, G)))
         line.append("%s" % float(mapp))
         line.append("%s" % abs(len(src) - len(trg)))
         f.write("%s\n" % '\t'.join(line))
         f.flush()
         if i == 350:
            break
Exemplo n.º 3
0
 f.write("%s\t%s\t%s\t%s\n" %
         (country, i, "lapl", nd.ge(src, trg, G, Q=ge_Q)))
 f.write("%s\t%s\t%s\t%s\n" %
         (country, i, "mmc",
          nd.mmc(src, trg, G, P=mmc_P, time_steps=diameter)))
 f.write("%s\t%s\t%s\t%s\n" %
         (country, i, "annihil",
          nd.annihilation(src, trg, G, Q=ann_Q)))
 f.write("%s\t%s\t%s\t%s\n" %
         (country, i, "otp",
          nd.emd(src, trg, G, shortest_path_lengths=spl)))
 f.write("%s\t%s\t%s\t%s\n" %
         (country, i, "spls",
          nd.spl(src,
                 trg,
                 G,
                 linkage="single",
                 shortest_path_lengths=spl)))
 f.write(
     "%s\t%s\t%s\t%s\n" %
     (country, i, "spla",
      nd.spl(
          src, trg, G, linkage="avg",
          shortest_path_lengths=spl)))
 f.write("%s\t%s\t%s\t%s\n" %
         (country, i, "splc",
          nd.spl(src,
                 trg,
                 G,
                 linkage="complete",
                 shortest_path_lengths=spl)))