# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python (dh)
#     language: python
#     name: dh
# ---

import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import display, HTML

df = pd.read_csv("Xy-arch-accuracy.csv")
df = df.drop(labels='Unnamed: 0', axis=1)

df.columns

df.head()


def get_Xy(df, dataset_names=None, exp_names=None, feature_names=None, prop=0.01):

    if dataset_names is not None:
        df = df[df.dataset.isin(dataset_names)]
        
    if exp_names is not None:
        df = df[df.exp.isin(exp_names)]
    
    dataset_names = df.dataset.unique()
    dfs = []
    N_list = []
    
    for dataset_name in dataset_names:
        N = int(0.5 + prop * df[(df.dataset == dataset_name)].shape[0])
        print(f"N = {N} for dataset: {dataset_name}")
        N_list.append(N)
        dfs.append(df[(df.dataset == dataset_name)].sort_values("acc", ascending=False)[:N])
        
    concat_df = pd.concat(dfs, axis=0).reset_index()
    
    X = concat_df[feature_names].to_numpy()
    y = concat_df.acc.to_numpy()
    
    return X, y, N_list


def PCA(X):
    from sklearn import decomposition
    pca = decomposition.PCA(n_components=2)
    u = pca.fit_transform(X)

    return u, pca.explained_variance_ratio_


# +
exp_names = ["AgEBO-NR-LR-BS"]
feature_names = {
    "$H_a$": [f"op-{i}" for i in range(37)],
    "$H_m$": ["batch_size", "learning_rate", "ranks_per_node"],
}

U_list = []
N_list = []
V_list = [] # Explained variance ratio

for k,v in feature_names.items():
    X, _, N = get_Xy(df, None, exp_names, feature_names=v)
    N_list.append(N)
    
    U, V = PCA(X)
    U_list.append(U)
    V_list.append(V)

# +
# %matplotlib notebook

import seaborn as sns

width = 1.692*3
height = width/1.618

markers = ["o", "P", "^", "X"]
labels = df.dataset.unique()

plt.figure(figsize=(width,height))
for i, (U, N, V, name) in enumerate(zip(U_list, N_list, V_list, feature_names.keys())):
    plt.subplot(1, 2, i+1)
    plt.title(name)

    plt.grid(b=True, which='major', color='#666666', linestyle=':')
    
    cur = 0
    for n, m, l in zip(N, markers, labels):
        plt.scatter(U[cur:cur+n,0], U[cur:cur+n,1], marker=m, label=l, s=100)
        cur += n

    plt.xlabel(f"Dim 1 ({V[0]*100:.2f}%)", fontsize=12)
    plt.ylabel(f"Dim 2 ({V[1]*100:.2f}%)", fontsize=12)
    if i == 1:
        plt.legend(loc='best', fancybox=True, shadow=False, fontsize=9)
# plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', fancybox=True, shadow=False, ncol=1, fontsize=10)
plt.tight_layout()
plt.show()
# -



StarcoderdataJupyterScriptsDedupFiltered