cut_off = 1. max_freq = np.zeros((len(ei_ratio), len(l3l5_ratio))) freq_pow = np.zeros_like(max_freq) for k1, k2, k3 in zip(params['k_l3l5_e'], params['k_l3l5_i'], params['k_l5l3_i']): if not results[k1][k2][k3].isnull().any().any(): _ = plot_psd(results[k1][k2][k3], tmin=cut_off, show=False) pow = plt.gca().get_lines()[-1].get_ydata() freqs = plt.gca().get_lines()[-1].get_xdata() r, c = np.argmin(np.abs(ei_ratio - k1/k2)), np.argmin(np.abs(l3l5_ratio - k2/k3)) max_freq[r, c] = freqs[np.argmax(pow)] freq_pow[r, c] = np.max(pow) plt.close(plt.gcf()) cm1 = cubehelix_palette(n_colors=int(len(ei_ratio)*len(l3l5_ratio)), as_cmap=True, start=2.5, rot=-0.1) cm2 = cubehelix_palette(n_colors=int(len(ei_ratio)*len(l3l5_ratio)), as_cmap=True, start=-2.0, rot=-0.1) cax1 = plot_connectivity(max_freq, ax=ax[0, idx], yticklabels=list(np.round(ei_ratio, decimals=2)), xticklabels=list(np.round(l3l5_ratio, decimals=2)), cmap=cm1) cax1.set_xlabel('L3/L5 coupling strength') cax1.set_ylabel('exc/inh coupling strength') cax1.set_title(f'max freq (C = {C})') cax2 = plot_connectivity(freq_pow, ax=ax[1, idx], yticklabels=list(np.round(ei_ratio, decimals=2)), xticklabels=list(np.round(l3l5_ratio, decimals=2)), cmap=cm2) cax2.set_xlabel('L3/L5 coupling strength') cax2.set_ylabel('exc/inh coupling strength') cax2.set_title(f'freq power (C = {C})') plt.suptitle('Cortical microcircuit sensitivity to inter-laminar coupling') plt.tight_layout(pad=2.5, rect=(0.01, 0.01, 0.99, 0.96)) fig.savefig("/home/rgast/Documents/Studium/PhD_Leipzig/Figures/BGTCS/cmc_coupling", format="svg") plt.show()
# target values targets = config['targets'] # STEP 2: Go through results files and store scores ################################################### etas, alphas, scores = [], [], [] for f in [f for f in os.listdir(path) if '.npy' in f]: idx = int(f.split(".")[0].split("_")[-1]) alphas.append(config['alphas'][idx]) etas.append(config['etas'][idx]) scores.append(np.load(f"{path}/{f}")) # STEP 3: Visualization ####################### # visualization etas_unique = np.sort(np.unique(etas)) alphas_unique = np.sort(np.unique(alphas)) scores_2d = np.zeros((len(alphas_unique), len(etas_unique))) for eta, alpha, score in zip(etas, alphas, scores): idx_c = np.argwhere(etas_unique == eta) idx_r = np.argwhere(alphas_unique == alpha) if score >= 0.0: scores_2d[idx_r, idx_c] = score plot_connectivity(scores_2d, xticklabels=np.round(etas_unique, decimals=2), yticklabels=np.round(alphas_unique, decimals=2)) show()
idx_r = np.argmin(np.abs(param_grid['d'] - r_map.at[idx, 'd'])) idx_c = np.argmin(np.abs(param_grid['s'] - r_map.at[idx, 's'])) r = r2.loc[:, ('r', f"{idx}/{out_var}")] diff = r - r1.loc[:, 'r'] d, s = r_map.loc[idx, 'd'], r_map.loc[idx, 's'] order = int(np.round((d / s)**2)) error[idx_r, idx_c] = alpha * np.sqrt(diff.T @ diff) + (1 - alpha) * order print( f"delay = {d}, spread = {s}, order = {order}, rate = {order/d}, error = {error[idx_r, idx_c]}" ) indices[idx_r.squeeze()][idx_c.squeeze()] = idx # display error fig, ax = plt.subplots() ax = plot_connectivity(error, xticklabels=param_grid['s'], yticklabels=param_grid['d'], ax=ax) ax.set_xlabel('s') ax.set_ylabel('d') plt.tight_layout() # display winner together with target fig2, ax2 = plt.subplots() winner = np.argmin(error) idx = np.asarray(indices).flatten()[winner] ax2.plot(r1.loc[:, 'r']) ax2.plot(r2.loc[:, ('r', f"{idx}/{out_var}")]) plt.legend(['discrete', 'gamma']) ax2.set_title( f"delay = {r_map.loc[idx, 'd']}, spread = {r_map.loc[idx, 's']}, error = {error.flatten()[winner]}" )
max_freq[i, j] = freqs[np.argmax(pow)] freq_pow[i, j] = np.max(pow) plt.close('all') fig, ax = plt.subplots(ncols=2, figsize=(15, 5), gridspec_kw={}) cm1 = cubehelix_palette(n_colors=int(len(params['H_e']) * len(params['H_i'])), as_cmap=True, start=2.5, rot=-0.1) cm2 = cubehelix_palette(n_colors=int(len(params['H_e']) * len(params['H_i'])), as_cmap=True, start=-2.0, rot=-0.1) cax1 = plot_connectivity(max_freq, ax=ax[0], yticklabels=list(np.round(params['H_e'], decimals=2)), xticklabels=list(np.round(params['H_i'], decimals=2)), cmap=cm1) cax1.set_xlabel('H_i') cax1.set_ylabel('H_e') cax1.set_title(f'max freq') cax2 = plot_connectivity(freq_pow, ax=ax[1], yticklabels=list(np.round(params['H_e'], decimals=2)), xticklabels=list(np.round(params['H_i'], decimals=2)), cmap=cm2) cax2.set_xlabel('H_i') cax2.set_ylabel('H_e') cax2.set_title(f'freq pow') plt.suptitle('EI-circuit sensitivity to synaptic efficacies (H)') plt.tight_layout(pad=2.5, rect=(0.01, 0.01, 0.99, 0.96))
# load data path = "/home/rgast/MatlabProjects/STN_GPe/PAC_bistable.mat" data = scio.loadmat(path) # extract from data alpha = data['stim_amps_unique'] omega = data['stim_freqs_unique'] MI = data['PAC_max'] PAA_osc = data['PAA_osc'] PAA_env = data['PAA_env'] PAA = PAA_osc / PAA_env # plot MI cmap = create_cmap("pyrates_blue", n_colors=64, as_cmap=False, reverse=False) ax = plot_connectivity(MI, cmap=cmap) ax.set_xticks(ax.get_xticks()[0::2]) ax.set_yticks(ax.get_yticks()[0::2]) ax.set_xticklabels(np.round(omega.squeeze(), decimals=1)[0::2], rotation='horizontal') ax.set_yticklabels(np.round(alpha.squeeze(), decimals=1)[0::2], rotation='horizontal') ax.set_xlabel('omega') ax.set_ylabel('alpha') ax.invert_yaxis() plt.tight_layout() plt.savefig('MI_bs.svg') plt.show() # plot PAA cmap = create_cmap("pyrates_blue", n_colors=64, as_cmap=False, reverse=False)
# calculate order parameter (sync) w = np.pi * rates.values + 1.0j * potentials.values sync = (1 - w) / (1 + w) # store results in 2D arrays col = np.argmin(np.abs(etas - eta)) row = np.argmin(np.abs(alphas - alpha)) sync_mean_2D[row, col] = np.mean(np.abs(sync)) sync_var_2D[row, col] = np.var(np.abs(sync)) # visualization of kuramoto order parameter ########################################### # 2D fig2, ax2 = plt.subplots(ncols=2, figsize=(14, 6)) ax = ax2[0] ax = plot_connectivity(sync_mean_2D, yticklabels=np.round(alphas, decimals=1), xticklabels=np.round(etas, decimals=1), ax=ax) ax.set_title('mean of synchrony') ax = ax2[1] ax = plot_connectivity(sync_var_2D, yticklabels=np.round(alphas, decimals=1), xticklabels=np.round(etas, decimals=1), ax=ax) ax.set_title('var of synchrony') plt.tight_layout() plt.show()
param_map = {'eta': {'vars': ['Op_sfa_syns_noise/eta'], 'nodes': ['qif']}, 'Js': {'vars': ['Op_sfa_syns_noise/J'], 'nodes': ['qif']} } # simulation ############ results, result_map = grid_search(circuit_template="qifs/QIF_sfa_syns_noise", param_grid=params, param_map=param_map, inputs={}, outputs={"r": "qif/Op_sfa_syns_noise/r", "v": "qif/Op_sfa_syns_noise/v"}, step_size=dt, simulation_time=T, permute_grid=True, sampling_step_size=dts, method='RK45') # visualization ############### sigmas = np.zeros((len(Js), len(etas))) for i, J in enumerate(Js[::-1]): for j, eta in enumerate(etas): idx = result_map[result_map['eta'] == eta and result_map['J'] == J] r = results.loc[:, ('r', idx)] v = results.loc[:, ('v', idx)] w = np.complex(real=np.pi*r, imag=-v) sigmas[i, j] = (1-w)/(1+w) plot_connectivity(sigmas, xticklabels=np.round(etas, decimals=2), yticklabels=np.round(Js[::-1], decimals=2)) show()