<jupyter_start><jupyter_text>Error Visualization<jupyter_code>def generateRandomLocs(piece, num):

    score_info_dir = '/home/mshan/ttemp/spring2020/data-v2.1/score_info/p{}.scoreinfo.csv'.format(piece)
    with open(score_info_dir) as score_info_file:
        reader = csv.reader(score_info_file)
        next(reader)
        rows = []
        for row in reader:
            rows.append(row)
        locs = sorted(random.sample(range(len(rows)-1), num))
        
    return locs
def generateLocDicts(i):
    random_locs_2 = {}
    random_locs_3 = {}
    random_locs_4 = {}
    for piece in range(1, 201):
        random.seed(piece)
        random_locs_2[piece] = generateRandomLocs(piece, 2)
        random_locs_3[piece] = generateRandomLocs(piece, 3)
        random_locs_4[piece] = generateRandomLocs(piece, 4)
    return random_locs_2, random_locs_3, random_locs_4
def calDistInfo(i, sys='subseqDTW', data='data'):
    with open('/home/mshan/ttemp/data/hyp/{}/{}/p{}.pkl'.format(sys, data, i), 'rb') as f:
        d = pickle.load(f)
    white = 0
    if i in [4, 6, 7, 8, 14, 29, 30, 31, 32, 48, 53, 54, 59, 62, 98, 124, 136, 140, 150, 191, 199]:
        white = 1
    if i in [133, 138]:
        white = 2
    accu_time, total_time, accu_info, change_line_info = accuracy(d['actual_time'], i, d['events'], data=data, white=white, wp=d['wp'], )
    time_list = [(d['actual_time'][i], d['actual_time'][i+1]) for i in range(len(d['actual_time'])-1)]
    return time_list, accu_info, change_line_info
def calDistInfoHier(i, sys='hierarchicalDTW_v3.AD', data='data'):
    pklfile = '/home/mshan/ttemp/data/hyp/{}/{}/{}/p{}.pkl'.format(sys, data, 0.7, i)
    with open(pklfile, 'rb') as f:
        d = pickle.load(f)
    white = 0
    if i in [4, 6, 7, 8, 14, 29, 30, 31, 32, 48, 53, 54, 59, 62, 98, 124, 136, 140, 150, 191, 199]:
        white = 1
    if i in [133, 138]:
        white = 2
    accu_time, total_time, accu_info, change_line_info = accuracy(d['actual_time'], i, d['events'], sys=sys, data=data, white=white, pred_lines=d['pred_lines'])
    time_list = [(d['actual_time'][i], d['actual_time'][i+1]) for i in range(len(d['actual_time'])-1)]
    return time_list, accu_info, change_line_info
def errorPlotNoRepeat(i, data='data'):
    color = {}
    color['c'] = '0.9'
    color['w'] = 'red'
    color['f'] = 'black'
    
    time_list1, acc_info1, change_info1 = calDistInfo(i, sys='subseqDTW', data=data)
    time_list2, acc_info2, change_info2 = calDistInfo(i, sys='jumpDTW', data=data)
    time_list3, acc_info3, change_info3 = calDistInfoHier(i, data=data)
    fig, axs = plt.subplots(4, figsize=(30,4))
    fig.suptitle('No Repeat', fontsize=25, y=1.05)
    for i in range(4):
        axs[i].axis('off')
        axs[i].axvspan(float(time_list1[0][0]), float(time_list1[-1][1]), color=color['c'])
    axs[0].text(-12, 0.3, 'Truth', fontsize=22)
    axs[1].text(-12, 0.3, 'subDTW', fontsize=22)
    axs[2].text(-12, 0.3, 'jumpDTW', fontsize=22)
    axs[3].text(-12, 0.3, 'hierDTW', fontsize=22)
    for idx, time in enumerate(time_list1):
        axs[1].axvspan(float(time[0]), float(time[1]), color=color[acc_info1[idx]])
    for idx, time in enumerate(time_list2):
        axs[2].axvspan(float(time[0]), float(time[1]), color=color[acc_info2[idx]])
    for idx, time in enumerate(time_list3):
        axs[3].axvspan(float(time[0]), float(time[1]), color=color[acc_info3[idx]])
        if change_info3[idx] == 'f':
            axs[0].axvspan(float(time[0]), float(time[0]), color=color[change_info3[idx]])
    return fig
def errorPlotRepeat(i, sys='subseqDTW', data='data'):
    color = {}
    color['c'] = '0.9'
    color['w'] = 'red'
    color['f'] = 'black'
    count_line = 0
    time_list1, acc_info1, change_info1 = calDistInfo(i, sys='subseqDTW', data=data)
    time_list2, acc_info2, change_info2 = calDistInfo(i, sys='jumpDTW', data=data)
    time_list3, acc_info3, change_info3 = calDistInfoHier(i, data=data)
    fig, axs = plt.subplots(4, figsize=(30,4))
    fig.suptitle('Repeat 3', fontsize=25, y=1.05)
    for i in range(4):
        axs[i].axis('off')
        axs[i].axvspan(float(time_list1[0][0]), float(time_list1[-1][1]), color=color['c'])
    axs[0].text(-30, 0.3, 'Truth', fontsize=22)
    axs[1].text(-30, 0.3, 'subDTW', fontsize=22)
    axs[2].text(-30, 0.3, 'jumpDTW', fontsize=22)
    axs[3].text(-30, 0.3, 'hierDTW', fontsize=22)
    for idx, time in enumerate(time_list1):
        axs[1].axvspan(float(time[0]), float(time[1]), color=color[acc_info1[idx]])
    for idx, time in enumerate(time_list2):
        axs[2].axvspan(float(time[0]), float(time[1]), color=color[acc_info2[idx]])
    for idx, time in enumerate(time_list3):
        axs[3].axvspan(float(time[0]), float(time[1]), color=color[acc_info3[idx]])
        if change_info3[idx] == 'f':
            count_line += 1
            if data == 'data_repeat3' and count_line in [10,13,31]:
                axs[0].axvline(float(time[0]), linestyle='--', linewidth=6, color='blue')
            else:
                axs[0].axvspan(float(time[0]), float(time[0]), color=color[change_info3[idx]])
    return fig
fig1 = errorPlotNoRepeat(4)
fig2 = errorPlotRepeat(48, data='data_repeat3')<jupyter_output><empty_output><jupyter_text>Error Analysis<jupyter_code>piece = 4
with open('/home/mshan/ttemp/data/bscore_sheet/p{}.pkl'.format(piece), 'rb') as f:
    d = pickle.load(f)
    events = d['events']
with open('/home/mshan/ttemp/data/hyp/hierarchicalDTW_v3.AD/{}/0.7/p{}.pkl'.format('data', piece), 'rb') as f:
    d = pickle.load(f)
    times = d['actual_time']
    lines = d['pred_lines']
bounds = getBoundaryElements(piece, "F")
prev_line = -1
for idx, line in enumerate(lines):
    if line != prev_line:
        start_idx = bounds[line]
        start_event = events[start_idx]
        print("P{}L{} starts at {}.".format(start_event[5]+1, start_event[2]+1, times[idx]))
    prev_line = line<jupyter_output>P21L1 starts at 0.0.
P21L2 starts at 4.800000000000001.
P21L3 starts at 9.4.
P21L4 starts at 13.8.
P21L5 starts at 19.3.
P21L6 starts at 24.400000000000002.
P22L1 starts at 29.5.
P22L2 starts at 34.2.
P22L3 starts at 39.400000000000006.
P22L4 starts at 44.400000000000006.
P22L5 starts at 49.2.
P23L1 starts at 53.7.
P23L2 starts at 59.0.
P23L3 starts at 64.2.
P23L4 starts at 70.4.
P23L5 starts at 74.9.
P24L1 starts at 79.7.
P24L2 starts at 85.10000000000001.
P24L3 starts at 90.30000000000001.
P24L4 starts at 95.2.
P24L5 starts at 100.4.
P24L6 starts at 104.0.
P25L1 starts at 109.10000000000001.
P25L2 starts at 114.5.
P25L3 starts at 119.7.
P25L4 starts at 123.10000000000001.
P25L5 starts at 127.9.
P25L6 starts at 132.6.
{'fraction_non_alphanumeric': 0.17063611697316852, 'fraction_numerical': 0.08968947844437745, 'mean_word_length': 3.7123579545454546, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 8, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '231373', 'license': 'MIT', 'n_tokens_mistral': 3013, 'n_tokens_neox': 2666, 'n_words': 553, 'path': '07_evaluation.ipynb', 'repo_name': 'Shanmy/YoutubeScoreFollowing', 'size': '6634'}