This notebook plots the distribution of spatially opponent, non-opponent and unresponsive cells in different layers of our model as a function of bottleneck size. It corresponds to Figures 2(a) and 2(b) in the paper.
Note: The easiest way to use this is as a colab notebook, which allows you to dive in with no setup.
from os.path import exists
if not exists('opponency.zip'):
!wget -O opponency.zip https://github.com/ecs-vlc/opponency/archive/master.zip
!unzip -qq opponency.zip
!mv opponency-master/* ./
!rm -r opponency-master
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib import rc
import matplotlib.font_manager
rc('font',**{'family':'serif','serif':['Computer Modern Roman'],'size':13})
rc('text', usetex=True)
import pandas as pd
import numpy as np
from statistics import load
def plot(ax, frame, cell_type, d_vvs, legend=False):
frame = frame[frame['d_vvs'] == d_vvs]
opps = load.spatial(frame, cell_type.lower())
retina2 = opps[opps['layer'] == 'retina_relu2']
ventral0 = opps[opps['layer'] == 'ventral_relu0']
ventral1 = opps[opps['layer'] == 'ventral_relu1']
ax.plot(retina2['n_bn'], retina2['mean_rel_amount'], label='Retina 2', linestyle=':')
ax.fill_between(
retina2['n_bn'],
retina2['mean_rel_amount'] + retina2['std_rel_amount'],
retina2['mean_rel_amount'] - retina2['std_rel_amount'],
alpha=0.1
)
ax.plot(ventral0['n_bn'], ventral0['mean_rel_amount'], label='Ventral 1', linestyle='--')
ax.fill_between(
ventral0['n_bn'],
ventral0['mean_rel_amount'] + ventral0['std_rel_amount'],
ventral0['mean_rel_amount'] - ventral0['std_rel_amount'],
alpha=0.1
)
ax.plot(ventral1['n_bn'], ventral1['mean_rel_amount'], label='Ventral 2', linestyle='-.')
ax.fill_between(
ventral1['n_bn'],
ventral1['mean_rel_amount'] + ventral1['std_rel_amount'],
ventral1['mean_rel_amount'] - ventral1['std_rel_amount'],
alpha=0.1
)
if legend:
ax.legend(frameon=False)
if d_vvs == 0:
ax.set_title(cell_type, pad=25)
if cell_type == 'Spatially Opponent':
ax.set_ylabel(f'Depth {d_vvs}', labelpad=25, fontsize='large')
ax.set_xlim(1, 32)
ax.set_ylim(0, 1)
plt.draw()
labels = ax.get_yticklabels()
if len(labels) > 0:
labels[-1] = ""
ax.set_yticklabels(labels)
frame = pd.read_pickle('logs/spatial.pd')
cell_types = ['Spatially Opponent', 'Spatially Non-opponent', 'Spatially Unresponsive']
fig, axs = plt.subplots(5, 3, sharex='col', sharey='row', gridspec_kw={'hspace': 0, 'wspace': 0})
fig.set_size_inches(9, 12.5)
fig.add_subplot(111, frameon=False)
plt.tick_params(labelcolor='none', top=False, bottom=False, left=False, right=False)
plt.grid(False)
plt.xlabel('Bottleneck Size')
plt.ylabel('Percentage')
for d_vvs in range(5):
for c, cell_type in enumerate(cell_types):
plot(axs[d_vvs, c], frame, cell_type, d_vvs, d_vvs == 0 and cell_type == 'Spatially Unresponsive')
plt.savefig('figures/spatial_opponency.pdf', bbox_inches='tight')
findfont: Font family ['serif'] not found. Falling back to DejaVu Sans.