def get_best_k_params_dist(n_iter,k_test,beta,Ncorr,
                        n_systems,n_concepts,emb_dim,noise,n_epicentres,linearsep,sd):
    all_dicts = []
    for i_iter in range(n_iter):
        sd = np.random.randint(0,10e5)
        A,B,X_A,X_B,B_shuff,B_idx_map = emb.get_data(n_systems,n_concepts,emb_dim,noise,n_epicentres,linearsep,sd,bplot=False)
        dict_run = get_best_k_run_dist(k_test,beta,A,B_shuff,B_idx_map,Ncorr,i_iter)
        all_dicts.append(dict_run)  
    #Get all_accs_per_k
    all_accs_per_k = []
    for k in k_test:
        arr_k = np.array([d[k] for d in all_dicts]) #all values for each k
        all_accs_per_k.append(arr_k)
    #Get best average
    avgs = np.array([np.mean(np.array(accs)) for accs in all_accs_per_k])
    best_idx = np.argmax(avgs)
    best_k_avg = k_test[best_idx] #rad value with highest average
    best_avg = np.mean(np.array(all_accs_per_k[best_idx])) #highest average
    clear_output(wait=True)
    return best_k_avg, best_avg , all_accs_per_k
def get_best_Ncorr_krad_params_dist(n_iter,
                                n_systems,n_concepts,emb_dim,noise,n_epicentres,linearsep,sd,
                                Ncorr_test,k_test = None,rad_test = None):
    all_dicts = []
    p_test = k_test if k_test is not None else rad_test
    pairs = list(itertools.product(Ncorr_test,p_test))
    for i_iter in range(n_iter):
        sd = np.random.randint(0,10e5)
        A,B,X_A,X_B,B_shuff,B_idx_map = emb.get_data(n_systems,n_concepts,emb_dim,noise,n_epicentres,linearsep,sd,bplot=False)
        dict_run = get_best_Ncorr_krad_run_angles(i_iter,A,B_shuff,B_idx_map,Ncorr_test,k_test = k_test,rad_test = rad_test)
        all_dicts.append(dict_run)  
    #Get all_accs_per_Ncorr_krad
    all_accs_per_Ncorr_krad = []
    for Ncorr,p in pairs:
        arr_Ncorr_krad = np.array([d[(Ncorr,p)] for d in all_dicts]) #all values for each k
        all_accs_per_Ncorr_krad.append(arr_Ncorr_krad)
    #Get best average
    avgs = np.array([np.mean(np.array(accs)) for accs in all_accs_per_Ncorr_krad])
    best_idx = np.argmax(avgs)
    best_Ncorr_krad = pairs[best_idx] #rad value with highest average
    best_avg = np.mean(np.array(all_accs_per_Ncorr_krad[best_idx])) #highest average
    clear_output(wait=True)
    return best_Ncorr_krad, best_avg , all_accs_per_Ncorr_krad
def get_best_krad_param_angles(n_iter,Ncorr,
                               n_systems,n_concepts,emb_dim,noise,n_epicentres,linearsep,sd,
                               k_test = None,rad_test = None):
    #Test either k or rad
    all_dicts = []
    for i_iter in range(n_iter):
        sd = np.random.randint(0,10e5)
        A,B,X_A,X_B,B_shuff,B_idx_map = emb.get_data(n_systems,n_concepts,emb_dim,noise,n_epicentres,linearsep,sd,bplot=False)
        dict_run = get_best_krad_run_angles(i_iter,Ncorr,A,B_shuff,B_idx_map,k_test = k_test,rad_test = rad_test)
        all_dicts.append(dict_run)
    #Get all_accs_per_rad
    all_accs_per_p = []
    p_test = k_test if k_test is not None else rad_test
    for p in p_test:
        arr_p = np.array([d[p] for d in all_dicts]) #all values for each k
        all_accs_per_p.append(arr_p)
    #Get best average
    avgs = np.array([np.mean(np.array(accs)) for accs in all_accs_per_p])
    best_idx = np.argmax(avgs)
    best_p = p_test[best_idx] #rad value with highest average
    best_avg = np.mean(np.array(all_accs_per_p[best_idx])) #highest average
    clear_output(wait=True)
    return best_p, best_avg , all_accs_per_p