def start(conn_str, table_name, inits, estims, ls, sel_types, pxs, types, run_id_n=5): sql_insert = f""" INSERT INTO {table_name} ({','.join(cols)}) VALUES %s; """ with open_db_cursor(conn_str) as (cursor, conn): for init in inits: for estim in estims: for sel_type in sel_types: for size_type in types: n = N_POP[size_type] for l in ls: print((init, estim, l, n, sel_type)) px = pxs[(l, n, sel_type)] for i in range(run_id_n): run(cursor, conn, i, l, n, px, sql_insert, estim, init, sel_type, size_type)
def run_static_with_conditions_extended(): with open_db_cursor(CONN_STR) as (cursor, conn): rin_with_conditions('uniform', 'l-hamming_d', 'tournament_2', 100, 1000, 7.25166297e-06 * 0.9, 5, 'task1_extended_test', 'task1_extended_run_details_test', 'test_8', cursor, conn)
def run_static_task1_test_px_extended(): with open_db_cursor(GCLOUD_CONN_STR) as (cursor, conn): test_px_extended('task1_extended', 'task1_extended_test', 'task1_extended_run_details_test', 10, cursor, conn, add_select=' AND id=115')
def get_data(conn_str, l, n, sel_type, init, run_id=0): with open_db_cursor(conn_str) as (cur, conn): sql = f""" SELECT run_id, expected_value_pair, expected_value_wild, expected_value_ideal, std_pair, std_wild, std_ideal, variance_coef_pair, variance_coef_wild, variance_coef_ideal, mean_health, mean_health_diff_0, best_health_diff_0 FROM task2_full_gcloud_v1 WHERE L={l} AND N={n} AND sel_type='{sel_type}' AND init='{init}' AND run_id={run_id} ORDER BY run_id, iteration LIMIT 20000 """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() return data
def run_static_task1_retest_px_extended(): with open_db_cursor(GCLOUD_CONN_STR) as (cursor, conn): sql = """ SELECT init, estim, type, l, n, test_px * 0.9 FROM task1_extended_test_3 WHERE count_succ <> 10 AND estim='l-hamming_d' AND type='rws' ORDER BY init, estim, type, l, n; """ cursor.execute(sql) rows = cursor.fetchall() rows = [(None, row[0], row[1], row[2], row[3], row[4], row[5]) for row in rows] test_px_extended('', 'task1_extended_test', 'task1_extended_run_details_test', 10, cursor, conn, rows=rows)
import numpy as np import matplotlib.pyplot as plt from old.database import open_db_cursor with open_db_cursor('bla') as (cursor, conn): sql = """ SELECT l, final_px FROM final_pxs WHERE N=100 ORDER BY L; """ cursor.execute(sql) rows = cursor.fetchall() data_x = np.array([row[0] for row in rows]) data_y = np.array([row[1] for row in rows]) plt.plot(data_x, data_y) plt.show()
import numpy as np import pandas.io.sql as sqlio from psycopg2.extras import execute_values from old.database import open_db_cursor with open_db_cursor('postgresql://*****:*****@146.148.7.100:5432/thesis') as (cur, conn): sql = f""" SELECT id, pairwise_hamming_distribution_p, ideal_hamming_distribution_p, wild_type_hamming_distribution_p FROM task_2_variant_2 """ df = sqlio.read_sql_query(sql, conn) runs = df.to_numpy() # print(runs) max_pair = [] min_pair = [] max_ideal = [] min_ideal = [] max_wild = [] min_wild = [] for i in range(len(runs)): max_pair.append(int(np.array(runs[i][1]).argmax())) min_pair.append(int(np.array(runs[i][1]).argmin())) max_ideal.append(int(np.array(runs[i][2]).argmax())) min_ideal.append(int(np.array(runs[i][2]).argmin())) max_wild.append(int(np.array(runs[i][3]).argmax())) min_wild.append(int(np.array(runs[i][3]).argmin())) print(list(runs[:,0].astype(int)) )
import matplotlib.pyplot as plt import pandas.io.sql as sqlio from old.database import open_db_cursor with open_db_cursor('postgresql://*****:*****@localhost:5432/thesis_bump') as (cur, conn): for N, c in zip([100, 120, 140, 160, 180, 195], ['tab:blue','tab:orange','tab:green','tab:red','tab:purple','tab:olive','tab:brown', 'tab:pink']): sql = f""" SELECT l, test_px FROM task1_aggr_gcloud_test_visualize WHERE N = {N} ORDER BY l """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() ham, = plt.plot(data[:,0], data[:,1], c=c, label=f'N={N}') plt.legend() plt.xlabel("L") plt.ylabel("Pmax") plt.title('RWS') plt.show()
def main(): with open_db_cursor( 'postgresql://*****:*****@localhost:5432/thesis_bump') as (cur, conn): def compare_estims(): sql = f""" SELECT l * n, AVG(final_px) FROM final_pxs_extended WHERE estim='sigma_2' AND type='tournament_2' AND L IN (10, 20, 80, 100, 200) AND N IN (100, 200) GROUP BY l*n ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() s2, = plt.plot(data[:, 0], data[:, 1], c='blue', label='sigma_2') sql = f""" SELECT l * n, AVG(final_px) FROM final_pxs_extended WHERE estim='sigma_4' AND type='tournament_2' AND L IN (10, 20, 80, 100, 200) AND N IN (100, 200) GROUP BY l*n ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() s4, = plt.plot(data[:, 0], data[:, 1], c='green', label='sigma_4') sql = f""" SELECT l * n, AVG(final_px) FROM final_pxs_extended WHERE estim='sigma_10' AND type='tournament_2' AND L IN (10, 20, 80, 100, 200) AND N IN (100, 200) GROUP BY l*n ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() s10, = plt.plot(data[:, 0], data[:, 1], c='springgreen', label='sigma_10') sql = f""" SELECT l * n, AVG(final_px) FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='tournament_2' AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) GROUP BY l*n ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() d2, = plt.plot(data[:, 0], data[:, 1], c='r', label='l-hamming_d') plt.legend(handles=[s2, s4, s10, d2]) plt.xlabel('L*N') plt.ylabel('Pmax') plt.title("Toournament 2") def compare_inits(): sql = f""" SELECT l * n, AVG(final_px) FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='rws' AND init='uniform' AND L IN (10, 20, 80, 100, 200) AND N IN (100, 200) GROUP BY l * n ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() ham, = plt.plot(data[:, 0], data[:, 1], c='r', label='uniform') sql = f""" SELECT l * n, AVG(final_px) FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='rws' AND init='all_0' AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) GROUP BY l * n ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() d2, = plt.plot(data[:, 0], data[:, 1], c='b', label='all_0') sql = f""" SELECT l * n, AVG(final_px) FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='rws' AND init='normal' AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) GROUP BY l * n ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() d4, = plt.plot(data[:, 0], data[:, 1], c='teal', label='normal') plt.legend(handles=[ham, d2, d4]) plt.xlabel('L*N') plt.ylabel('Pmax') plt.title("RWS") def scatter_lines(): sql = f""" SELECT l * n, final_px FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='rws' AND init='uniform' -- AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() a = plt.scatter(1 / data[:, 0], data[:, 1], c='b', s=5, label='rws') sql = f""" SELECT l * n, final_px FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='tournament_4' AND init='uniform' -- AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() c = plt.scatter(1 / data[:, 0], data[:, 1], c='teal', s=5, label='tournament_4') sql = f""" SELECT l * n, final_px FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='tournament_12' AND init='uniform' -- AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() d = plt.scatter(1 / data[:, 0], data[:, 1], c='springgreen', s=5, label='tournament_12') sql = f""" SELECT l * n, final_px FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='tournament_2' AND init='uniform' -- AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() b = plt.scatter(1 / data[:, 0], data[:, 1], c='g', s=5, label='tournament_2') plt.legend(handles=[a, b, c, d]) plt.show() def plot(): sql = f""" SELECT l * n, final_px FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='rws' AND init='uniform' AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() ham, = plt.plot(data[:, 0], data[:, 1], c='r', label='rws') sql = f""" SELECT l * n, final_px FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='tournament_2' AND init='uniform' AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() d2, = plt.plot(data[:, 0], data[:, 1], c='b', label='tournament_2') sql = f""" SELECT l * n, final_px FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='tournament_4' AND init='uniform' AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() d4, = plt.plot(data[:, 0], data[:, 1], c='teal', label='tournament_4') sql = f""" SELECT l * n, final_px FROM final_pxs_extended WHERE estim='l-hamming_d' AND type='tournament_12' AND init='uniform' AND L IN (10, 20, 80, 100, 200, 800, 1000, 2000) AND N IN (100, 200) ORDER BY l * n """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() d10, = plt.plot(data[:, 0], data[:, 1], c='springgreen', label='tournament_12') plt.legend(handles=[ham, d2, d4, d10]) plt.title("Selection") compare_inits() plt.show()
import matplotlib.pyplot as plt import pandas.io.sql as sqlio from old.database import open_db_cursor with open_db_cursor('postgresql://*****:*****@146.148.7.100:5432/thesis') as (cur, conn): sql = f""" SELECT unnest(t1.mean_health) FROM task1_extended_run_details_test t1 WHERE t1.run_id=420 AND t1.run_number=2 LIMIT 20000; """ df = sqlio.read_sql_query(sql, conn) data = df.to_numpy() plt.plot(data) plt.show()
import matplotlib.pyplot as plt import numpy as np from old.database import open_db_cursor with open_db_cursor('postgresql://*****:*****@localhost:5432/thesis') as ( cur, conn): sql = f""" SELECT test_px120, (select MAX(a) from unnest(runs_succ) as a) as avg FROM task1_visualize_mean WHERE id>=94 """ cur.execute(sql) row = np.array(cur.fetchall()) plt.plot(row[:, 0], row[:, 1], c='b') plt.plot([-40, 40], [20000, 20000], '--', c='r') plt.xlabel('%') plt.ylabel('Iteration') plt.show()
def run_static_task1_find_px_extended(): with open_db_cursor(GCLOUD_CONN_STR) as (cursor, conn): find_px_extended('task1_extended', ['uniform'], ['l-hamming_d'], ['tournament_4'], [10], [100], 10, cursor, conn)
def get_pxs(conn_str, factor=1): with open_db_cursor(conn_str) as (cursor, conn): cursor.execute("SELECT L, N, type, final_px FROM final_pxs;") rows = cursor.fetchall() res = {(row[0], row[1], row[2]): row[3] * factor for row in rows} return res