<jupyter_start><jupyter_text>Plotting<jupyter_code>def filter_df(df, filters):
    for key, value in filters.items():
        df = df[df[key] == value]
    return df
def get_np(df, cols):
    res = []
    for col in cols: res.append(df[col].to_numpy())
    return res
def normalize(array, shift=0.0, range=0.1):
    array -= array.min()
    array /= array.max()
    array *= range
    array += shift
    return array
def stats(array):
    print(pd.DataFrame(array).describe())<jupyter_output><empty_output><jupyter_text>Errors  1. Graph with mean/var on x-y axis, and errors expressed in colors: dimensions 400<jupyter_code>n_vals = scaled.N.unique()
d_vals = scaled.Dimensions.unique()
d_vals
def get_var_err_data(n=100000, dims=400, err="rel_deviation_data", df=scaled):
    df = filter_df(df, {"N":n, "Dimensions":dims})
    variances, err_data = get_np(df, ['Variance', err])
    return variances, err_data
rel_data = {d:{n:get_var_err_data(n, d, "rel_deviation_data", scaled) for n in n_vals} for d in d_vals}
fancy_err_name = {"rel_deviation_data":"Relative Error: Reduced Data", 
                  "rel_deviation_eigv":"Relative Error: Eigen Values",
                  "abs_deviation_data":"Absolute Error: Reduced Data", 
                  "abs_deviation_eigv":"Absolute Error: Eigen Values"}
df = scaled
err_names = ["rel_deviation_data", "rel_deviation_eigv", "abs_deviation_data", "abs_deviation_eigv"]
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(18,14));
axs = axs.reshape(-1)
for i, err_name in enumerate(err_names):
    ax = axs[i]
    plot_data = {d:{n:get_var_err_data(n, d, err_name, df) for n in n_vals} for d in d_vals}
    for n, (variances, errs) in plot_data[400].items():
        ax.scatter(variances, errs, label=f"{n}")
        ax.set_xlabel("Variance")
        ax.set_ylabel(fancy_err_name[err_name])
        ax.set_title("Mean Error with columns=400 with scaling")
        ax.set_xscale("log", basex=2)
        ax.set_yscale("log", basey=10)
        ax.set_ylim(top=10**3, bottom=10**(-6))
        ax.legend(loc=4, prop={'size': 7})
        
fig.savefig("plots/scaling_400_errors_scatter.png")
df = nscaled
err_names = ["rel_deviation_data", "rel_deviation_eigv", "abs_deviation_data", "abs_deviation_eigv"]
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(18,14));
axs = axs.reshape(-1)
for i, err_name in enumerate(err_names):
    ax = axs[i]
    plot_data = {d:{n:get_var_err_data(n, d, err_name, df) for n in n_vals} for d in d_vals}
    for n, (variances, errs) in plot_data[400].items():
        ax.scatter(variances, errs, label=f"{n}")
        ax.set_xlabel("Variance")
        ax.set_ylabel(fancy_err_name[err_name])
        ax.set_title("Mean Error with columns=400 and no scaling")
        ax.set_xscale("log", basex=2)
        ax.set_yscale("log", basey=10)
        ax.set_ylim(top=10**3, bottom=10**(-6))
        ax.legend(loc=4, prop={'size': 7})
        
fig.savefig("plots/no_scaling_400_errors_scatter.png")<jupyter_output><empty_output><jupyter_text>Speed<jupyter_code>x = res.groupby(by=["Dimensions", "N"]).mean().iloc[:,-2:]
res.Dimensions.unique()
fig, axes = plt.subplots(3, 2, figsize=(14, 15))
axes = axes.reshape(-1)

for i, dim in enumerate(res.Dimensions.unique()):
    x.loc[dim].plot(ax=axes[i])
    axes[i].set_title(f"Columns: {dim}")
    axes[i].set_xscale("log")
    
fig.savefig("plots/speed.png")<jupyter_output><empty_output><jupyter_text>Heatmap<jupyter_code>scaled_pivots = [pd.pivot_table(scaled, values=e, index=['N'], columns='Variance') for e in err_names]
nscaled_pivots= [pd.pivot_table(nscaled,values=e, index=['N'], columns='Variance') for e in err_names]
fig, axes = plt.subplots(4, 2, figsize=(15,20))
fig.tight_layout(pad=7.0)
axes = axes.reshape(-1)

for i in range(0,8,2):
    sns.heatmap(scaled_pivots[i//2],  ax=axes[i])
    axes[i].set_title(f"Scaled data: {fancy_err_name[err_names[i//2]]}")
    sns.heatmap(nscaled_pivots[i//2], ax=axes[i+1])
    axes[i+1].set_title(f"Not Scaled data: {fancy_err_name[err_names[i//2]]}")
    
fig.savefig("plots/heatmap.png")<jupyter_output><empty_output><jupyter_text>FP16 Representation<jupyter_code>limits = [2**i for i in range(-13, 17)]
precis = [2**i for i in range(-24, 6)]
len(limits), len(precis)
plt.rcParams["figure.figsize"] = (8, 6)
plt.plot(limits, precis)
plt.xscale("log", basex=2)
plt.yscale("log", basey=2)
plt.xlabel("Range")
plt.ylabel("Distance between closest numbers")
plt.savefig("plots/fp16_precision.png")<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup