def plot_correlation_hist(data): """ Plot histogram of all correlations """ # gather data corrs = [] for raw_res, enh_list in data: _, raw_mat, _ = raw_res if not raw_mat is None: raw_vec = extract_sig_entries(raw_mat) corrs.extend(raw_vec) for enh_res in enh_list: _, enh_mat, _ = enh_res if not enh_mat is None: enh_vec = extract_sig_entries(enh_mat) corrs.extend(enh_vec) # plot result fig = plt.figure() plot_histogram(corrs, plt.gca()) plt.xlabel('simulated correlations') fig.savefig('images/all_sim_corrs.pdf')
def extract_entries(row): """ Extract needed amount of entries from each matrix """ return pd.Series({ 'type': row.type, 'id': row.id, 'raw_res': row.raw_res, 'enh_res': row.enh_res, 'raw_vals': extract_sig_entries(row.raw_mat), 'enh_vals': extract_sig_entries(row.enh_mat[:3, :3]) })
def extract_entries(row): """ Extract needed amount of entries from each matrix """ return pd.Series({ 'type': row.type, 'id': row.id, 'raw_res': row.raw_res, 'enh_res': row.enh_res, 'raw_vals': extract_sig_entries(row.raw_mat), 'enh_vals': extract_sig_entries(row.enh_mat[:3,:3]) })
def find_threshold(data): """ Use std/2 of correlation distribution closest to 0 (most likely) to switch sign as detection threshold """ cur = [] for raw, enh_res in data: _, rd = raw _, rdm, _ = rd cur.append(extract_sig_entries(rdm)) for enh in enh_res: _, ed = enh _, edm, _ = ed if not edm is None: cur.append(extract_sig_entries(edm[:-1, :-1])) idx = np.argmin(abs(np.mean(cur, axis=0))) return np.std(cur, axis=0)[idx] / 2
def handle_enh_entry(raw_res, enh_res, val_func): """ Compare given networks with given function """ raw_sde, raw_odesde = raw_res enh_sde, enh_odesde = enh_res raw, raw_mat, raw_sol = raw_odesde enh, enh_mat, enh_sol = enh_odesde if raw_mat is None or enh_mat is None: return -1 enh_mat = enh_mat[:-1, :-1] # disregard fourth node raw_vals = extract_sig_entries(raw_mat) enh_vals = extract_sig_entries(enh_mat) return val_func(raw_vals, enh_vals)
def handle_enh_entry(raw_res, enh_res, val_func): """ Compare given networks with given function """ raw_sde, raw_odesde = raw_res enh_sde, enh_odesde = enh_res raw, raw_mat, raw_sol = raw_odesde enh, enh_mat, enh_sol = enh_odesde if raw_mat is None or enh_mat is None: return -1 enh_mat = enh_mat[:-1,:-1] # disregard fourth node raw_vals = extract_sig_entries(raw_mat) enh_vals = extract_sig_entries(enh_mat) return val_func(raw_vals, enh_vals)
def get_correlation_median(syst, mat): vals = extract_sig_entries(mat) avg = np.median(vals) return avg
def get_correlation_variance(syst, mat): vals = extract_sig_entries(mat) var = np.var(vals) return var