示例#1
0
def size_series():
    SERIES = [5000, 10000, 50 * 1000, 100 * 1000]
    M = 10
    tau = 0.5
    gamma = 1.0
    NUM_INIT = 10
    NUM_ITER = 25

    db = MongoClient('localhost', 27017)[qm.DB4]

    for serie in SERIES:
        N = serie
        rho = float(NUM_INIT / N)
        NAME = 'size_series_' + str(serie)

        graph_id = qm.insert_ba_graph(db, N, M)
        epi_id = qm.insert_epidemic_params(db, tau, gamma, rho, name=NAME)
        prop_list = []
        for i in range(RESOLUTION):
            prop_list.append(i / RESOLUTION)
        qm.populate_quarantine_by_prop(db,
                                       graph_id,
                                       epi_id,
                                       prop_list,
                                       NUM_ITER,
                                       name=NAME,
                                       save_full_data=False,
                                       prefix=str(serie))
示例#2
0
def cluster_series():
    SERIES = [0.05, 0.1, 0.15, 0.2, 0.25]
    N = 10 * 1000
    M = 10
    tau = 0.5
    gamma = 1.0
    NUM_INIT = 10
    NUM_ITER = 25

    db = MongoClient('localhost', 27017)[qm.DB4]
    rho = float(NUM_INIT / N)

    for serie in SERIES:
        NAME = 'cluster_series_' + str(serie)
        p = make_plc_cluster(N, M, serie)
        graph_id = qm.insert_plc_graph(db, N, M, p)
        epi_id = qm.insert_epidemic_params(db, tau, gamma, rho, name=NAME)
        prop_list = []
        for i in range(RESOLUTION):
            prop_list.append(i / RESOLUTION)
        qm.populate_quarantine_by_prop(db,
                                       graph_id,
                                       epi_id,
                                       prop_list,
                                       NUM_ITER,
                                       name=NAME,
                                       save_full_data=False,
                                       prefix=str(serie))
def main(args):
    name = args.name
    # Parse graph params
    graph_type = args.graph_type
    N = int(float(args.N))
    graph_params = args.graph_params

    # Parse infection params
    tau = float(args.tau)
    gamma = float(args.gamma)
    rho = float(args.init_infected / N)

    # Parse run params
    num_iter = args.num_iter

    # Run thing we want to run (and print as we go along!)
    db = MongoClient('localhost', 27017)[qm.DB2]
    if graph_type == 'ba':
        m = int(graph_params[0])
        graph_id = qm.insert_ba_graph(db, N, m, name=name)
    elif graph_type == 'plc':
        m = int(graph_params[0])
        p = float(graph_params[1])
        graph_id = qm.insert_plc_graph(db, N, m, p, name=name)
    elif graph_type == 'rw':
        qe = float(graph_params[0])
        qv = float(graph_params[1])
        graph_id = qm.insert_rw_graph(db, N, qe, qv, name=name)
    elif graph_type == 'nn':
        u = float(graph_params[0])
        k = int(graph_params[1])
        graph_id = qm.insert_nn_graph(db, N, u, k, name=name)
    elif graph_type == 'ws':
        k = int(graph_params[0])
        p = float(graph_params[1])
        graph_id = qm.insert_ws_graph(db, N, k, p, name=name)
    else:
        raise NotImplementedError("Only BA/PLC graphs supported")

    epi_id = qm.insert_epidemic_params(db, tau, gamma, rho, name=name)

    prop_range = [_ / RESOLUTION for _ in range(0, RESOLUTION)]

    qm.populate_quarantine_by_prop(db,
                                   graph_id,
                                   epi_id,
                                   prop_range,
                                   num_iter,
                                   name=name,
                                   save_full_data=False)
示例#4
0
def main(args):
    name = args.name
    # Parse graph params
    graph_type = args.graph_type
    graph_params = args.graph_params
    if len(graph_params) == 1:
        graph_params = graph_params[0]
    #Parse infection params
    tau = float(args.tau)
    gamma = float(args.gamma)

    # Parse run params
    num_iter = args.num_iter

    # Run thing we want to run (and print as we go along!)
    db = MongoClient('localhost', 27017)[qm.DB2]
    if graph_type == 'gemsec_fb':
        graph = gg.load_gemsec_fb(graph_params)

    elif graph_type == 'gemsec_deezer':
        graph = gg.load_gemsec_deezer(graph_params)

    elif graph_type == 'arxiv':
        graph = gg.load_arxiv_collab(graph_params)

    elif graph_type == 'hiv':
        graph = gg.load_hiv(int(graph_params))
        return graph
    elif graph_type == 'hs':
        minutes = float(graph_params[0])
        scale = int(graph_params[1])
        graph = gg.load_highschool(minutes, scale=scale)
        return graph

    else:
        raise NotImplementedError("Nope")
    rho = float(args.init_infected / len(graph))
    epi_id = qm.insert_epidemic_params(db, tau, gamma, rho, name=name)

    prop_range = [_ / RESOLUTION for _ in range(0, RESOLUTION)]

    qm.populate_quarantine_by_prop(db,
                                   None,
                                   epi_id,
                                   prop_range,
                                   num_iter,
                                   name=name,
                                   save_full_data=False,
                                   graph=graph)
示例#5
0

def prod(iter_list):
	count = 1 
	for el in iter_list:
		count *= len(el)
	return count 

if __name__ == '__main__':
	client = pymongo.MongoClient('localhost', 27017)
	N = 10 ** 4
	ms = [3, 5] 
	p = 0.4
	tau = 0.1 
	r0s = [0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0] 
	rho = 25 / N
	qprop = [[x / 20, y / 20] for x in range(16) for y in range(16)]
	num_runs = 5 

	total_count = prod([ms, r0s, qprop])
	count = 0 
	for m in ms:
		graph_id = qm.insert_plc_graph(client, N, m, p)
		for r0 in r0s:
			epidemic_id = qm.insert_epidemic_params(client, tau, tau / r0, rho)
			for qlist in qprop:
				count += 1
				print("%s/ %s" % (count, total_count))
				qm.populate_plc_qtines(client, graph_id, epidemic_id, num_runs, 
									   qlist)
	main()