<jupyter_start><jupyter_text>Data Preparation The data is stored in $D$ in the form $D[visdepth][timestep][\alpha][\beta] = performance$where:$\alpha = 10 \times \mbox{learning rate} $$\beta = 10 \times \mbox{discount rate} $Note that $D$ is automatically averaged over runs<jupyter_code>num_runs = 10
max_vis_depth = 4
num_steps = 10
n = 11
step_size = 10<jupyter_output><empty_output><jupyter_text>Loading<jupyter_code>D = np.zeros((max_vis_depth + 1, num_steps + 1, n, n))
for run in range(1, num_runs + 1):
    for depth in range(1, max_vis_depth + 1):
        dir_input = "raw/cat_mouse/depth" + str(depth) + "/run" + str(run) + ".txt"
        with open(os.path.abspath(dir_input)) as f:
            for line in f.readlines():
                line = list(map(int, line.split()))
                a = line[0]
                b = line[1]
                for i in range(2, num_steps + 2):
                    step = i - 1
                    perf = line[i]
                    D[depth][step][a][b] += perf / num_runs<jupyter_output><empty_output><jupyter_text>Preparation of Improvement Tables  Calculation<jupyter_code>I = np.zeros((max_vis_depth + 1, num_steps + 1, n, n))
for depth in range(1, max_vis_depth + 1):
    for step in range(1, num_steps + 1):
        I[depth][step] = (D[depth][step] - D[depth][step - 1]) / step_size
i_stats = tools.get_stats(I[1:max_vis_depth + 1, 1:num_steps + 1])
i_stats<jupyter_output><empty_output><jupyter_text>Normalization<jupyter_code>I_norm = tools.normalize(I, i_stats, invert=True)
i_norm_stats = tools.get_stats(I_norm[1:max_vis_depth + 1, 1:num_steps + 1])
i_norm_stats<jupyter_output><empty_output><jupyter_text>Preparation of Mesh Grids<jupyter_code>def_depth = 1
def_step = 10
X_domain = np.linspace(0, 1, n)
X = np.zeros((4, n, n))
X[0] = np.full((n, n), def_depth)
X[1] = np.full((n, n), def_step * step_size)
X[2], X[3] = np.meshgrid(X_domain, X_domain)
Y = I_norm[def_depth][def_step]
y_stats = tools.get_stats(Y)
y_stats<jupyter_output><empty_output><jupyter_text>Data Visualization  Performance Distribution<jupyter_code>I_flat = I_norm[1:max_vis_depth + 1, 1:num_steps + 1].flatten()
fig, ax = plt.subplots(1, 1, figsize=(3, 3))
dist = tools.plot_dist(X=I_flat,
                       ax=ax,
                       file_name='plots/normed_perf_dist',
                       yticks=[])
plt.close()
dist
percent_in_upper_half = ((0.5 < I_flat) & (I_flat < 1.0)).sum() / I_flat.size
"{:.2%}".format(percent_in_upper_half)<jupyter_output><empty_output><jupyter_text>Performance vs. Depth and Time Heatmap<jupyter_code>tools.heatmap_preprocess(X=I_norm,
                         num_steps=num_steps,
                         save_file="plots/depth_heatmap/cm/frame{:03d}.png",
                         vmin=0.5,
                         vmax=1.0,
                         )
heatmap_vid = tools.animate('plots/depth_heatmap/cm/frame',
                            'plots/depth_heatmap/cm/anim')
heatmap_vid<jupyter_output><empty_output><jupyter_text>Regression<jupyter_code>model = tools.PolynomialRegression(X, Y)<jupyter_output><empty_output><jupyter_text>Linear model<jupyter_code>lin_model = model.process(degree=1)
lin_model.print_func()
print(lin_model.r_squared)<jupyter_output>0.235152011463<jupyter_text>Quadratic model<jupyter_code>quad_model = model.process(degree=2)
quad_model.print_func()
print(quad_model.r_squared)<jupyter_output>0.78807150507<jupyter_text>Cubic model<jupyter_code>cube_model = model.process(degree=3)
cube_model.print_func()
print(cube_model.r_squared)<jupyter_output>0.799414450235<jupyter_text>3D Plotting<jupyter_code>def plot_animate_preprocess(model, degree):
    ax = plot_3d(model, degree)
    
    for ii in range(0, 360, 1):
        ax.view_init(elev=30., azim=ii)
        plt.savefig("plots/regression/degree%d/frame%d.jpeg" % (degree, ii), transparent=True)
    
    plt.close()
def plot_animate_beta(degree, secs=6, fps=60, vid=True):
    frame_steps = 360 // (secs * fps)
    
    images = []
    for ii in range(0, 360, frame_steps):
        images.append(imageio.imread("plots/regression/degree%d/frame%d.jpeg" % (degree,ii)))
        
    save_file = 'plots/regression/degree%d/anim%d' % (degree, fps)
    imageio.mimsave("%s.gif" % save_file, images, fps=60)
    
    tools.gif_to_mp4(save_file, fps)
    
    if vid:
        return HTML('<video controls autoplay loop> <source src="%s.mp4" type="video/mp4"> </video>' % save_file)
    else:
        return HTML('<img src="%s.gif">' % save_file)
ax = tools.plot_3d_normed(model, degree=1)
plt.show()<jupyter_output><empty_output><jupyter_text>Linear Estimate<jupyter_code>plot_animate_preprocess(model, degree=1)
anim1 = plot_animate_beta(degree=1, secs=6, fps=60)
anim1<jupyter_output><empty_output><jupyter_text>Quadratic Estimate<jupyter_code>plot_animate_preprocess(model, degree=2)
anim2 = plot_animate_beta(degree=2, secs=6, fps=60)
anim2<jupyter_output><empty_output><jupyter_text>Cubic Estimate<jupyter_code>plot_animate_preprocess(model, degree=3)
anim3 = plot_animate_beta(degree=3, secs=6, fps=60)
anim3<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1379242691779478, 'fraction_numerical': 0.030606238964096526, 'mean_word_length': 4.072636815920398, 'pattern_counts': {'":': 0, '<': 64, '<?xml version=': 0, '>': 62, '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': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '609843', 'license': 'MIT', 'n_tokens_mistral': 2092, 'n_tokens_neox': 1950, 'n_words': 309, 'path': 'data/.ipynb_checkpoints/Cat-Mouse Data Analysis-checkpoint.ipynb', 'repo_name': 'LE-LOY/socialsims', 'size': '5097'}