Esempio n. 1
0
y_list = load_data(debug_file, debug_line)
y_list = y_list[:-(len(y_list) % cf.ds_time)]
query, reference = cal_warped_signals(y_list, 'right')

# plot warped signal
# downsample times
xvals, yinterp = plot_warped_signals(reference, query, cf.ds_time)
query2 = pd.DataFrame({'t': xvals, 'q': yinterp})

# calculate the corresponding point pair
query.drop(['shift', 't'], axis=1)
query2['close_index'] = 0
true_align_dict = get_true_aligned(cf.ds_time, query, query2)
group_num_dict = get_group_number(true_align_dict, query)

reference_slope_col(reference, cf.ds_time)
slope_col(query2)
d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t',
                                                       'avg_slope']].values,
                                            query2[['t', 'slope']].values,
                                            dist=norm)
get_link_graph(reference, query2, path, -3, 'Downsampled signal with dDTW',
               '(b) dDTW')
fact_align_dict = get_fact_align(path)
reverse_dict = get_reverse_dict(path)
print("path = " + str(len(path[0])))
print('group = ' +
      str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
print("SS1 of ddtw is " + str(get_SS1(fact_align_dict, cf.ds_time)))
print("SS2 of ddtw is " +
      str(get_SS2(fact_align_dict, reverse_dict, cf.ds_time)))
query2 = pd.DataFrame(yinterp)
query2['aligned_index'] = 0
query2['t'] = query['t']
query2.columns = ['q', 'aligned_index', 't']
query2.loc[len(query2) - 1, 'aligned_index'] = len(query) - 1
for i in range(len(query2) - 1):
    for j in range(len(query['t2']) - 1):
        if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
            if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] - query['q'][j + 1]):
                query2.loc[i, 'aligned_index'] = j
            else:
                query2.loc[i, 'aligned_index'] = j + 1


if sub_len%2 == 0:
    raise Exception("Sub_len must be odd number!")

refer_descriptors, query_descriptors = cal_refer_query_descriptor(reference_norm, yinterp_norm, sub_len)


d, cost_matrix, acc_cost_matrix, path = dtw(refer_descriptors, query_descriptors, dist=norm)
get_link_graph(reference, query, path, -3, 'shapedtw without downsample')
true_align_dict = get_true_align(query2)
fact_dict = get_fact_align(path)
reverse_dict = get_reverse_dict(path)
print("error rate of shapedtw is " + str(get_k_accuracy_same(true_align_dict, fact_dict, reference)))
print("W of shapedtw is " + str(get_W(path)))
print("SS2 of shapedtw is " + str(get_SS2(fact_dict, reverse_dict, 1)))


Esempio n. 3
0
def norm(x, y):
    return math.fabs(x[1] - y[1])


y_list = load_data(debug_file, debug_line)
query, reference = cal_warped_signals(y_list, 'right')

# plot warped signal
# downsample times
xvals, yinterp = plot_warped_signals(reference, query, cf.ds_time)

# calculate the corresponding point pair
query.drop('shift', axis=1)
query.drop('t', axis=1)
query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
query2['close_index'] = 0
true_align_dict = get_true_aligned(cf.ds_time, query, query2)
group_num_dict = get_group_number(true_align_dict, query)

d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'q']].values,
                                            query2[['t', 'q']].values,
                                            dist=norm)
get_link_graph(reference, query2, path, -3, None, '(c) DTW')
fact_align_dict = get_fact_align(path)
reverse_dict = get_reverse_dict(path)
print('group = ' +
      str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
print("SS1 of dtw is " + str(get_SS1(fact_align_dict, cf.ds_time)))
print("SS2 of dtw is " +
      str(get_SS2(fact_align_dict, reverse_dict, cf.ds_time)))
                                             height=np.mean(query2.loc[:,
                                                                       'q']),
                                             distance=20)
pairs = get_matched_pairs(reference, query2, refer_peak_indexes[0],
                          query_peak_indexes[0], 20)
refer_indexes = []
query_indexes = []

for i in range(0, len(pairs)):
    refer_indexes.append(pairs[i][0])
    query_indexes.append(pairs[i][1])

draw_the_peaks(reference, query2, refer_indexes, query_indexes, -3,
               'Downsampled signal with peaks')
calculate_event(refer_indexes, reference, 1)
calculate_event(query_indexes, query2, cf.ds_time)
d, cost_matrix, acc_cost_matrix, path = dtw(
    reference[['t', 'q', 'upslope', 'downslope']].values,
    query2[['t', 'q', 'upslope', 'downslope']].values,
    dist=norm)

get_link_graph(reference, query2, path, -3, 'Downsampled signal with EventDTW')
fact_align_dict = get_fact_align(path)
reverse_dict = get_reverse_dict(path)
print("path = " + str(len(path[0])))
print('group = ' +
      str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
print("SS1 of dtw is " + str(get_SS1(fact_align_dict, cf.ds_time)))
print("SS2 of dtw is " +
      str(get_SS2(fact_align_dict, reverse_dict, cf.ds_time)))
Esempio n. 5
0
# store the corresponding point pair
query.drop(['t','shift'], axis=1)
query2 = pd.DataFrame({'t': xvals, 'q': yinterp})
query2['close_index'] = 0
true_align_dict = get_true_aligned(cf.ds_time, query, query2)
group_num_dict = get_group_number(true_align_dict, query)


refer_subsequences = samplingSequences(reference_norm, sub_len)
query_subsequences = samplingSequences(yinterp_norm, int(sub_len/cf.ds_time))
refer_descriptors = np.zeros((len(refer_subsequences), nBlocks * 8))
query_descriptors = np.zeros((len(query_subsequences), nBlocks * 8))
refer_nsubsequences = len(refer_subsequences)
query_nsubsequences = len(query_subsequences)

for i in range(refer_nsubsequences):
    sub_seq = refer_subsequences[i]
    refer_descriptors[i] = cal_descriptor(sub_seq, sub_len)

for i in range(query_nsubsequences):
    sub_seq = query_subsequences[i]
    query_descriptors[i] = cal_descriptor(sub_seq, int(sub_len/cf.ds_time))

d, cost_matrix, acc_cost_matrix, path = dtw(refer_descriptors, query_descriptors, dist=norm)
get_link_graph(reference, query2, path, -3, 'downsampled shapedtw')
fact_align_dict = get_fact_align(path)
reverse_dict = get_reverse_dict(path)
print("error rate of shapedtw is " + str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
print("SS1 of shapedtw is " + str(get_SS1(path, cf.ds_time)))
print("SS2 of shapedtw is " + str(get_SS2(fact_align_dict, reverse_dict, ds_time)))
Esempio n. 6
0
# store the corresponding point pair
query.drop('shift', axis=1)
query.drop('t', axis=1)
query2 = pd.DataFrame(yinterp)
query2['aligned_index'] = 0
query2['t'] = query['t']
query2.columns = ['q', 'aligned_index', 't']
query2.loc[len(query2) - 1, 'aligned_index'] = len(query) - 1
for i in range(len(query2) - 1):
    for j in range(len(query['t2']) - 1):
        if query['t2'][j] <= query2['t'][i] < query['t2'][j + 1]:
            if abs(query2['q'][i] - query['q'][j]) < abs(query2['q'][i] -
                                                         query['q'][j + 1]):
                query2.loc[i, 'aligned_index'] = j
            else:
                query2.loc[i, 'aligned_index'] = j + 1

slope_col(query2)
slope_col(reference)
d, cost_matrix, acc_cost_matrix, path = dtw(reference[['t', 'slope']].values,
                                            query2[['t', 'slope']].values,
                                            dist=norm)
get_link_graph(reference, query2, path, -3)
true_align_dict = get_true_align(query2)
fact_dict = get_fact_align(path)
reverse_dict = get_reverse_dict(path)
print("error rate of dtw is " +
      str(get_k_accuracy_same(true_align_dict, fact_dict, reference)))
print("W of ddtw is " + str(get_W(path)))
print("SS2 of ddtw is " + str(get_SS2(fact_dict, reverse_dict, 1)))
true_align_dict = get_true_aligned(cf.ds_time, query, query2)
group_num_dict = get_group_number(true_align_dict, query)

refer_subsequences = samplingSequences(reference_norm, sub_len)
query_subsequences = samplingSequences(yinterp_norm, int(sub_len / cf.ds_time))
refer_descriptors = np.zeros((len(refer_subsequences), nBlocks * 8))
query_descriptors = np.zeros((len(query_subsequences), nBlocks * 8))
refer_nsubsequences = len(refer_subsequences)
query_nsubsequences = len(query_subsequences)

for i in range(refer_nsubsequences):
    sub_seq = refer_subsequences[i]
    refer_descriptors[i] = cal_descriptor(sub_seq, sub_len)

for i in range(query_nsubsequences):
    sub_seq = query_subsequences[i]
    query_descriptors[i] = cal_descriptor(sub_seq, int(sub_len / cf.ds_time))

d, cost_matrix, acc_cost_matrix, path = dtw(refer_descriptors,
                                            query_descriptors,
                                            dist=norm)
get_link_graph(reference, query2, path, -3, 'Downsampled signal with shapedtw',
               '(d) shapeDTW')
fact_align_dict = get_fact_align(path)
reverse_dict = get_reverse_dict(path)
print("error rate of shapedtw is " +
      str(get_k_accuracy(true_align_dict, fact_align_dict, group_num_dict)))
print("SS1 of shapedtw is " + str(get_SS1(path, cf.ds_time)))
print("SS2 of shapedtw is " +
      str(get_SS2(fact_align_dict, reverse_dict, ds_time)))