def save_datas(energies_file_pegas, energies_file_dwave, test_set_file, n): with open(energies_file_pegas, "r") as intput: energies_pegas = eval(intput.read()) with open(energies_file_dwave, "r") as intput: energies_dwave = eval(intput.read()) with open(test_set_file, "r") as inf: dict_from_file = eval(inf.read()) for energy_pegas, energy_dwave, cnf, sat in zip(energies_pegas, energies_dwave, dict_from_file['cnf'], dict_from_file['sat']): m = len(cnf) if m + energy_pegas == 0: en_p = 1 else: en_p = 0 if m + energy_dwave == 0: en_dw = 1 else: en_dw = 0 save_to_csv('max_sat_pegas_vs_2000', [[m, m / n, en_p, en_dw, sat]], n)
def report_random_forest(): size_k = len(list_k) size_min_samp = len(min_samp_list) print "k=", size_k, "min_samples=", size_min_samp matrix = [[0 for x in range(size_min_samp)] for y in range(size_k)] i = 0 j = 0 last_value_min_samples = list_k[0] for param, mean_score, cv_scores in clf.grid_scores_: if param["feature_selection__k"] != last_value_min_samples: i += 1 j = 0 last_value_min_samples = param["feature_selection__k"] #print param, "mean=", mean_score, "i=", i, "j=", j matrix[i][j] = mean_score j += 1 import numpy as np header = [""] + min_samp_list matrix = np.c_[list_k, matrix] u.save_to_csv("RandomForest.csv", Algorithms_path, matrix, header) u.change_decimal_separator("RandomForest.csv", Algorithms_path)
def report_decision_tree(): size_k = len(list_k) size_min_samp = len(min_samp_list) print "k=", size_k, "min_samples=", size_min_samp matrix = [[0 for x in range(size_min_samp)] for y in range(size_k)] i = 0 j = 0 last_value_min_samples = min_samp_list[0] for param, mean_score, cv_scores in clf.grid_scores_: if param[ "decision_tree__min_samples_split"] != last_value_min_samples: i += 1 j = 0 last_value_min_samples = param[ "decision_tree__min_samples_split"] #print param, "mean=", mean_score, "i=", i, "j=", j matrix[j][i] = mean_score j += 1 import numpy as np header = [""] + min_samp_list matrix = np.c_[list_k, matrix] u.save_to_csv("DecisionTree.csv", Algorithms_path, matrix, header) u.change_decimal_separator("DecisionTree.csv", Algorithms_path)
def report_SVM(): size_k = len(list_k) size_c = len(list_C) print "k=", size_k, "c=", size_c matrix = [[0 for x in range(size_c)] for y in range(size_k)] i = 0 j = 0 last_value_C = list_C[0] for param, mean_score, cv_scores in clf.grid_scores_: if param["SVM__C"] != last_value_C: i += 1 j = 0 last_value_C = param["SVM__C"] #print param, "mean=", mean_score, "i=", i, "j=", j matrix[j][i] = mean_score j += 1 import numpy as np header = [""] + list_C matrix = np.c_[list_k, matrix] u.save_to_csv("SVM.csv", Algorithms_path, matrix, header) u.change_decimal_separator("SVM.csv", Algorithms_path)
def pegasus_phase_draw(energies_file, test_set_file, n): with open(energies_file, "r") as intput: energies = eval(intput.read()) with open(test_set_file, "r") as inf: dict_from_file = eval(inf.read()) for energy, cnf , sat in zip(energies, dict_from_file['cnf'], dict_from_file['sat']): m = len(cnf) if m + energy == 0: en = 1 else: en = 0 save_to_csv('max_sat_', [[m, m / n, en , sat]], n) import pandas as pd import numpy as np import matplotlib.pyplot as plt df = pd.read_csv('logs_max_sat__{0}.csv'.format(n), names=['M','alfa','y_hat','y_acc'], sep=',').sort_values(['alfa'])[0:1000] bins = np.arange(0, 2.1, 0.20) df['bins'] = pd.cut(df.alfa, bins) ss_acc = df.groupby('bins')['y_acc'].agg(['sum', 'count']) ss_hat = df.groupby('bins')['y_hat'].agg(['sum', 'count']) y = [x.mid for x in ss_acc.index.values] plt.title('2-SAT, each point is averaged by step: (1/20)', fontsize=14) plt.plot(y, ss_hat['sum']/ss_hat['count'], "-",label='Pegasus-{0}'.format(n)) plt.plot(y, ss_acc['sum']/ss_acc['count'], "-",label='MiniSAT-{0}'.format(n)) plt.xticks(fontsize = 15) plt.yticks(fontsize = 15) plt.grid() plt.legend(fontsize=12) plt.show() plt.savefig('phase{0}'.format(n)) plt.close()
def main(): # for logging purposes start_time = time() # create the sitemap and convert the dictionaries to CSV result = create_sitemap(START_URL, EXPLORED, TO_VISIT) sitemap, n_pages = result[0], result[1] to_csv = dict_to_csv(sitemap) elapsed_time = time() - start_time stats = f"Explored { n_pages - 1 } pages in { elapsed_time } seconds" print(colored("=" * 50, "white")) print(colored(stats, "blue")) # write the data to a sitemap CSV file (easily exportable to Excel) save_to_csv(to_csv, "sitemap") print(colored("Successfully saved sitemap to CSV", "magenta"))