Ejemplo n.º 1
0
def run_experiment(experiment_name,
                   network,
                   alpha,
                   edit_type,
                   n,
                   mcls,
                   temps,
                   cooling_schedules,
                   reps=10):
    d_ns = []
    d_costs = []
    d_temps = []
    d_alphas = []
    d_ls = []
    d_cs = []
    d_init_temps = []

    print("Run " + experiment_name + " for " + network.name + " with " +
          str(reps) + " reps.")

    for start_temp in temps:
        for cooling_schedule in cooling_schedules:
            for mcl in mcls:
                for _ in range(reps):
                    ns, costs, temps, _ = SA(network).run(
                        start_temp,
                        alpha,
                        edit_type,
                        n,
                        mcl,
                        cooling_schedule=cooling_schedule)

                    d_ns += ns
                    d_costs += costs
                    d_temps += temps
                    d_alphas += [alpha] * len(ns)
                    d_ls += [mcl] * len(ns)
                    d_cs += [cooling_schedule] * len(ns)
                    d_init_temps += [start_temp] * len(ns)

                    print("L: " + str(mcl) + "\tT0: " + str(start_temp) +
                          "\tcooling_schedule: " + cooling_schedule +
                          "\tinitial cost: " + str(costs[0]) +
                          "\tfinal cost: " + str(costs[-1]))

    dt = {
        "n": d_ns,
        "cost": d_costs,
        "temp": d_temps,
        "alpha": d_alphas,
        "l": d_ls,
        "cooling_schedule": d_cs,
        "init_temp": d_init_temps
    }

    df = pd.DataFrame().from_dict(dt)

    save_pickle(df, "data/" + network.name + "_" + experiment_name)
Ejemplo n.º 2
0
def run_experiment(filename, lambdas, mu, cs, customers, service_types=["M"], schedulers=["FIFO"], reps=100, scales=[None], verbose=True):
    d_st = []
    d_cs = []
    d_lambdas = []
    d_mus = []
    d_schedulers = []
    d_customers = []
    d_means = []
    d_stds = []
    d_scales = []

    for service_type in service_types:
        for scheduler in schedulers:
            for mc in customers:
                for c in cs:
                    for lambd_o in lambdas:
                        for scale in scales:
                            lambd = lambd_o * c

                            tmp = []
                            for _ in range(reps):
                                data = mXc.run(lambd, mu, c, service_type, scheduler, max_customers=mc, scale=scale)
                                wait_time = list(np.array(data)[:,0])
                                service_time = list(np.array(data)[:,1])
                                tmp += wait_time

                            tmp = np.array(tmp)
                            d_scales.append(scale)
                            d_means.append(np.mean(tmp))
                            d_stds.append(np.std(tmp))

                            d_st.append(service_type)
                            d_cs.append(c)
                            d_lambdas.append(lambd)
                            d_mus.append(mu)
                            d_schedulers.append(scheduler)
                            d_customers.append(mc)

                            if verbose:
                                print("Finished M/" + str(service_type) +"/" + str(c) + "\t(" + str(scheduler) + ")\treps=" + str(reps) + "\tmax_customers=" + str(mc) + 
                                    "\tlambda=" + str(lambd) + "\tmu=" + str(mu) + "\trho=" + str(lambd/(c*mu)) + "\tscale=" + str(scale))

    dt = {
        "service_type": d_st,
        "c": d_cs,
        "lambda": d_lambdas,
        "mu": d_mus,
        "scheduler": d_schedulers,
        "customers": d_customers,
        "wait_time_mean": d_means,
        "wait_time_std": d_stds,
        "scale": d_scales
    }

    df = pd.DataFrame.from_dict(dt)
    save_pickle(df, "data/" + str(filename))
Ejemplo n.º 3
0
def clt(N_samples, N_iter, reps, alg_type):
    sizes = []
    
    for r in range(reps):
        if r % 10000 == 0:
            print(r)
        if alg_type == "mc":
            points = mandelbrot.mc(N_samples, LIMITS, N_iter)

        sizes.append(points.size)

    save_pickle(sizes, "data/clt")
Ejemplo n.º 4
0
def create_list_of_feature_dic(train_sents,
                               word_matrix_size,
                               word_map,
                               tag_matrix_size,
                               tag_map,
                               pkl_path,
                               pickles=True,
                               augmented=False):
    if pickles:
        list_feat_dict_path = pkl_path
        if not os.path.exists(list_feat_dict_path):
            list_feat_dics = []
            for sent in tqdm(train_sents):
                feat_dict = {}
                for i, word1 in enumerate(sent):
                    for j, word2 in enumerate(sent):
                        if (i == j):
                            continue
                        feat_dict[(word1,
                                   word2)] = feature_func(word1,
                                                          word2,
                                                          word_matrix_size,
                                                          tag_matrix_size,
                                                          word_map,
                                                          tag_map,
                                                          augmented=augmented)
                list_feat_dics.append(feat_dict)
            save_pickle(list_feat_dics, list_feat_dict_path)
        else:
            list_feat_dics = load_pickle(list_feat_dict_path)
    else:
        list_feat_dics = []
        for sent in tqdm(train_sents):
            feat_dict = {}
            for i, word1 in enumerate(sent):
                for j, word2 in enumerate(sent):
                    if (i == j):
                        continue
                    feat_dict[(word1,
                               word2)] = feature_func(word1,
                                                      word2,
                                                      word_matrix_size,
                                                      tag_matrix_size,
                                                      word_map,
                                                      tag_map,
                                                      augmented=augmented)
            list_feat_dics.append(feat_dict)

    return list_feat_dics
Ejemplo n.º 5
0
def list_of_word_tup_per_tree(trees_train, pkl_path):
    list_tup_per_tree_path = pkl_path
    if not os.path.exists(list_tup_per_tree_path):
        tree_list_of_tup_words = []
        for tree in trees_train:
            tree_list = []
            for node in range(len(tree.nodes)):
                tail = tree.nodes[node]['word']
                head_idx = tree.nodes[node]['head']
                head = tree.nodes[head_idx]['word']
                if tail == None or head == None:
                    continue
                tree_list.append((head, tail))
            tree_list_of_tup_words.append(tree_list)
        save_pickle(tree_list_of_tup_words, list_tup_per_tree_path)
    else:
        tree_list_of_tup_words = load_pickle(list_tup_per_tree_path)
    return tree_list_of_tup_words