<jupyter_start><jupyter_text>Dx and Dy Selectivity Results by layer<jupyter_code>stream_affinity_profile(all_x_df,prop='dx',plot_func=sns.boxplot)
stream_affinity_profile(all_y_df,prop='dy',plot_func=sns.boxplot)
from sklearn.preprocessing import MinMaxScaler

scaler = MinMaxScaler(feature_range=(0,1))
rescaled_class = scaler.fit_transform(all_df.query('property == "class"').dropna()['affinity'].values.reshape(-1,1))

norm_class = all_df.query('property == "class"').dropna()[['recon','xent','ecc_max','label_corruption','unit','layer_depth','layer_name']]
norm_class['property']='norm_class'
norm_class['affinity']=np.squeeze(rescaled_class)
# norm_class = pd.DataFrame.from_records({'affinity': np.squeeze(rescaled_class),'property':'norm_class'})
# norm_class.index = all_df.query('property == "class"').dropna()

all_df_ = all_df.append(norm_class)
all_df = all_df_
ydf = all_df.query('layer_name == "y"').reset_index()
ydf = pd.pivot_table(ydf,index=['xent','recon','unit'],columns='property',values='affinity')
ydf['layer_name']= 'y'

zdf = all_df.query('layer_name == "z"').reset_index()
zdf = pd.pivot_table(zdf,index=['xent','recon','unit'],columns='property',values='affinity')
zdf['layer_name']= 'z'

l4df = pd.concat([ydf,zdf])

l3df = all_df.query('layer_name == "l3"').reset_index()
l3df = pd.pivot_table(l3df,index=['xent','recon','unit'],columns='property',values='affinity')
l3df['layer_name']= 'l3'


l2df = all_df.query('layer_name == "l2"').reset_index()
l2df = pd.pivot_table(l2df,index=['xent','recon','unit'],columns='property',values='affinity')
l2df['layer_name']= 'l2'


l1df = all_df.query('layer_name == "l1"').reset_index()
l1df = pd.pivot_table(l1df,index=['xent','recon','unit'],columns='property',values='affinity')
l1df['layer_name']= 'l1'

# ydf['dx_selectivity'] = y_x_sel_df['dx_selectivity']
# zdf = z_c_sel_df
# zdf['dx_selectivity'] = z_x_sel_df['dx_selectivity']
# l3df = l3_c_sel_df
# l3df['dx_selectivity'] = l3_x_sel_df['dx_selectivity']
def pop_scatter(x='dx',y='dy',dsets=[l1df,l2df,l3df,l4df,],plot_func=sns.scatterplot,**plot_kw):
    filts =[
        'recon == 0 & xent == 15',
        'recon == 25 & xent == 0',
        'recon == 25 & xent == 15',
        
    ]
    fig,axs = plt.subplots(len(dsets),3,figsize=(2.5*3,2.5*len(dsets),),
    #                        subplot_kw={'xlim':(-.1,1),'ylim':(-0.1,1)},
                           sharex=True,sharey=True)
    objective_conds = ['Only Xent','Only Recon','Xent+Recon']
    for filt,coli,obj in zip(filts,np.arange(3),objective_conds):
        for ax,df,rowi in zip(axs[:,coli],dsets,np.arange(len(dsets))):
            plot_func(x=x,y=y,data=df.query(filt),ax=ax,**plot_kw)
            if coli == 0:
                ax.set_ylabel('Layer {}'.format(rowi+1))
            
        axs[0,coli].set_title(obj)
# sns.scatterplot(x=xvar,y=yvar,data=ydf.query(filt),ax=axs[1])
# sns.scatterplot(x=xvar,y=yvar,data=zdf.query(filt),ax=axs[2])
def pop_kde(x='dx',y='dy',dsets=[l1df,l2df,l3df,l4df,],clip=(0,1),rug_plot=False,**plot_kw):
    filts =[
        'recon == 0 & xent == 15',
        'recon == 25 & xent == 0',
        'recon == 25 & xent == 15',
        
    ]
    fig,axs = plt.subplots(3,len(dsets),figsize=(3*len(dsets),3*3,),
                           subplot_kw={'xlim':(0,1),'ylim':(0,1)},
                           sharex=True,sharey='row')
    objective_conds = ['Only Xent','Only Recon','Xent+Recon']
    layer_names = ['1','2','3','y+z',]
    for coli,df,layer_lab in zip(np.arange(len(dsets)),dsets,layer_names):
        for filt,ax,obj in zip(filts,axs[:,coli],objective_conds):
            fdf = df.query(filt).dropna()
            if coli != len(dsets)-1:
                sns.kdeplot(data=fdf[x].values,data2=fdf[y].values,ax=ax,clip=clip,**plot_kw)
            else:
                ax.scatter(fdf.query('layer_name == "y"')[x].values,fdf.query('layer_name == "y"')[y].values,marker='.',**plot_kw)
                ax.scatter(fdf.query('layer_name == "z"')[x].values,fdf.query('layer_name == "z"')[y].values,marker='.',c='orange',**plot_kw)

#                 ax.set_ylim(0,)
                
            if layer_lab == layer_names[-1] and rug_plot:
                sns.rugplot(fdf.query('layer_name == "y"')[x].values,ax=ax)
                sns.rugplot(fdf.query('layer_name == "z"')[x].values,ax=ax,color="g")
                sns.rugplot(fdf.query('layer_name == "y"')[y].values,ax=ax,vertical=True)
                sns.rugplot(fdf.query('layer_name == "z"')[y].values,ax=ax,color="g",vertical=True)
#                 ax.scatter(fdf[x].values,fdf[y].values,c="w",marker="+",linewidths=1)
            if coli == 0:
                ax.set_ylabel('{}'.format(obj))
            
            if obj == objective_conds[-1]:
                ax.set_xlabel(x)
            
        axs[0,coli].set_title('Layer {}'.format(layer_lab))
#         axs[0,coli].set_ylabel()
# l3df.query(f).dropna().head()
# sns.kdeplot()
pop_kde(
#     clip=(-0.1,0.75),
#     shade=True,shade_lowest=False,
)
# plt.xlim(0,0.6)
# plt.ylim(0,0.6)
pop_kde(x='norm_class',y='dx',
#         clip=(-0.1,1),
#         shade=True,shade_lowest=False
       )

# sns.kdeplot()
filt = 'recon == 25 & xent == 15'
xvar = 'norm_class'
yvar = 'dx'

g = sns.JointGrid(x=xvar,y=yvar,data=l4df.query(filt),space=0.5,
#                   xlim=(-0.05,0.5),
#                   ylim=(-0.05,0.5)
                 )
g = g.plot_joint(sns.kdeplot,
                 shade=True,shade_lowest=False,
                )
# g.ax_joint.set_xlim(-0.05,0.5)
# g.ax_joint.set_ylim(-0.05,0.9)
# g = g.plot_marginals(sns.kdeplot)
sns.kdeplot(l4df.query('{} & layer_name == "y"'.format(filt))[xvar],ax=g.ax_marg_x,legend=None)
sns.kdeplot(l4df.query('{} & layer_name == "z"'.format(filt))[xvar],ax=g.ax_marg_x,c="orange",legend=None)
sns.kdeplot(l4df.query('{} & layer_name == "y"'.format(filt))[yvar],ax=g.ax_marg_y,legend=None,vertical=True)
sns.kdeplot(l4df.query('{} & layer_name == "z"'.format(filt))[yvar],ax=g.ax_marg_y,c="orange",vertical=True)
g.ax_marg_y.legend(['y','z'],loc='upper center', bbox_to_anchor=(1.7, 1.1), shadow=True, ncol=1)

g.ax_marg_x.set_title('Both')
# sns.rugplot(l4df.query('{} & layer_name == "y"'.format(filt))[yvar],ax=g.ax_joint,vertical=True)
# sns.rugplot(l4df.query('{} & layer_name == "z"'.format(filt))[yvar],ax=g.ax_joint,c="g",vertical=True)
pop_kde(y='dy',x='norm_class')
pop_scatter(x='dx',y='norm_class',hue='layer_name',legend=None)
pop_scatter(xvar='dx',yvar='norm_class',hue='layer_name')
pop_scatter(xvar='dy',yvar='class')
fig,axs = plt.subplots(1,3,figsize=(15,5),
#                        subplot_kw={'xlim':(0,3),'ylim':(0,3)},
                       sharex=True,sharey=True)

filt = 'recon == 25 & xent == 0'
xvar = 'dx'
yvar = 'dy'
sns.scatterplot(x=xvar,y=yvar,data=l3df.query(filt),ax=axs[0])
sns.scatterplot(x=xvar,y=yvar,data=ydf.query(filt),ax=axs[1])
sns.scatterplot(x=xvar,y=yvar,data=zdf.query(filt),ax=axs[2])
fig,axs = plt.subplots(1,3,figsize=(15,5),
#                        subplot_kw={'xlim':(0,3),'ylim':(0,3)},
                       sharex=True,sharey=True)

filt = 'recon == 25 & xent == 15'
xvar = 'dx'
yvar = 'dy'
sns.scatterplot(x=xvar,y=yvar,data=l3df.query(filt),ax=axs[0])
sns.scatterplot(x=xvar,y=yvar,data=ydf.query(filt),ax=axs[1])
sns.scatterplot(x=xvar,y=yvar,data=zdf.query(filt),ax=axs[2])
# ydf[['recon','xent','unit']]
ydf.head()
fig,axs = plt.subplots(1,3,figsize=(15,5),
#                        subplot_kw={'xlim':(0,3),'ylim':(0,3)},
                       sharex=True,sharey=True)
sns.scatterplot(x='dx',y='class',data=l3df.reset_index().query('recon == 0 & xent == 15'),ax=axs[0])
sns.scatterplot(x='dx',y='class',data=ydf.query('recon == 0 & xent == 15'),ax=axs[1])
sns.scatterplot(x='dx',y='class',data=zdf.query('recon == 0 & xent == 15'),ax=axs[2])

# plt.xlim(0.0,3)
# plt.ylim(0.0,3)
axs[0].hlines(y=0.66,xmin=0,xmax=2,linestyles='dashed')
axs[0].vlines(x=0.66,ymin=0,ymax=2,linestyles='dashed')
axs[0].set_title('l3 latent space')
axs[1].hlines(y=0.66,xmin=0,xmax=2,linestyles='dashed')
axs[1].vlines(x=0.66,ymin=0,ymax=2,linestyles='dashed')
axs[1].set_title('y latent space')
axs[2].hlines(y=0.66,xmin=0,xmax=2,linestyles='dashed')
axs[2].vlines(x=0.66,ymin=0,ymax=2,linestyles='dashed')
axs[2].set_title('z latent space')
fig,axs = plt.subplots(1,3,figsize=(15,5),
#                        subplot_kw={'xlim':(0,3),'ylim':(0,3)},
                       sharex=True,sharey=True)
sns.scatterplot(x='dx',y='class',data=l3df.query('recon == 25 & xent == 15'),ax=axs[0])
sns.scatterplot(x='dx',y='class',data=ydf.query('recon == 25 & xent == 15'),ax=axs[1])
sns.scatterplot(x='dx',y='class',data=zdf.query('recon == 25 & xent == 15'),ax=axs[2])

axs[0].hlines(y=0.66,xmin=0,xmax=2,linestyles='dashed')
axs[0].vlines(x=0.66,ymin=0,ymax=2,linestyles='dashed')
axs[0].set_title('l3 latent space')
axs[1].hlines(y=0.66,xmin=0,xmax=2,linestyles='dashed')
axs[1].vlines(x=0.66,ymin=0,ymax=2,linestyles='dashed')
axs[1].set_title('y latent space')
axs[2].hlines(y=0.66,xmin=0,xmax=2,linestyles='dashed')
axs[2].vlines(x=0.66,ymin=0,ymax=2,linestyles='dashed')
axs[2].set_title('z latent space')
fig,axs = plt.subplots(1,3,figsize=(15,5),
#                        subplot_kw={'xlim':(0,3),'ylim':(0,3)},
                       sharex=True,sharey=True)
sns.scatterplot(x='dx',y='class',data=l3df.query('recon == 25 & xent == 0'),ax=axs[0])
sns.scatterplot(x='dx',y='class',data=ydf.query('recon == 25 & xent == 0'),ax=axs[1])
sns.scatterplot(x='dx',y='class',data=zdf.query('recon == 25 & xent == 0'),ax=axs[2])

# plt.xlim(0.0,3)
# plt.ylim(0.0,3)
axs[0].hlines(y=0.66,xmin=0,xmax=2,linestyles='dashed')
axs[0].vlines(x=0.66,ymin=0,ymax=2,linestyles='dashed')
axs[0].set_title('l3 latent space')
axs[1].hlines(y=0.66,xmin=0,xmax=2,linestyles='dashed')
axs[1].vlines(x=0.66,ymin=0,ymax=2,linestyles='dashed')
axs[1].set_title('y latent space')
axs[2].hlines(y=0.66,xmin=0,xmax=2,linestyles='dashed')
axs[2].vlines(x=0.66,ymin=0,ymax=2,linestyles='dashed')
axs[2].set_title('z latent space')
sns.boxplot(y='class_selectivity',x='xent',hue='ecc_max',data=y_sel_df.query('label_corruption == 0.0 & recon == 25'),palette='Purples')
sns.stripplot(y='class_selectivity',x='ecc_max',hue='xent',data=l2_sel_df.query('label_corruption == 0.0'),palette='Purples')
sns.boxplot(y='class_selectivity',x='recon',hue='ecc_max',data=y_sel_df.query('label_corruption == 0.0'))
sns.boxplot(y='class_selectivity',x='recon',hue='ecc_max',data=z_sel_df.query('label_corruption == 0.0'))
sns.boxplot(y='class_selectivity',x='ecc_max',hue='recon',data=z_sel_df.query('label_corruption == 0.0'))
conf_fetch(configs,'xent')
len(configs)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22941616766467066, 'fraction_numerical': 0.03686377245508982, 'mean_word_length': 4.869851729818781, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '446506', 'license': 'MIT', 'n_tokens_mistral': 4891, 'n_tokens_neox': 4715, 'n_words': 396, 'path': 'notebooks/cat_ortho_analysis_3x_z5.ipynb', 'repo_name': 'elijahc/vae', 'size': '10688'}