Esempio n. 1
0
def trajectoryAlldistance(i, trjs):

    trs_matrix = tdist.cdist(trjs, [trjs[i]], metric="hausdorff")
    cPickle.dump(
        trs_matrix,
        open(
            './distance_compution/hausdorff_distance/hausdorff_distance_' +
            str(i), 'w'))

    trs_matrix = tdist.cdist(trjs, [trjs[i]], metric="lcss", eps=200)
    cPickle.dump(
        trs_matrix,
        open('./distance_compution/LCSS_distance/LCSS_distance_' + str(i),
             'w'))
    #
    trs_matrix = tdist.cdist(trjs, [trjs[i]], metric="edr", eps=200)
    cPickle.dump(
        trs_matrix,
        open('./distance_compution/EDR_distance/EDR_distance_' + str(i), 'w'))
    #
    trs_matrix = tdist.cdist(trjs, [trjs[i]], metric="dtw")
    cPickle.dump(
        trs_matrix,
        open('./distance_compution/DTW_distance/DTW_distance_' + str(i), 'w'))

    print 'complete: ' + str(i)
Esempio n. 2
0
def trajectory_distance_batch(i,
                              batch_trjs,
                              trjs,
                              metric_type="hausdorff",
                              data_name='porto'):
    if metric_type == 'lcss' or metric_type == 'edr':
        trs_matrix = tdist.cdist(batch_trjs,
                                 trjs,
                                 metric=metric_type,
                                 eps=0.003)
    # elif metric_type=='erp':
    #     trs_matrix = tdist.cdist(batch_trjs, trjs, metric=metric_type, eps=0.003)
    else:
        trs_matrix = tdist.cdist(batch_trjs, trjs, metric=metric_type)
    cPickle.dump(
        trs_matrix,
        open(
            './features/' + data_name + '_' + metric_type + '_distance_' +
            str(i), 'w'))
    print 'complete: ' + str(i)
def trajectoryAlldistance(i,trjs):

    trs_matrix = tdist.cdist(trjs, [trjs[i]],metric="hausdorff")
    with open('./distance_compution/hausdorff_distance/hausdorff_distance_' + str(i), 'wb') as f:
        pickle.dump(trs_matrix, f, pickle.HIGHEST_PROTOCOL)

    trs_matrix = tdist.cdist(trjs, [trjs[i]],metric="lcss",eps=200)

    with open('./distance_compution/LCSS_distance/LCSS_distance_' + str(i), 'wb') as f:
        pickle.dump(trs_matrix, f, pickle.HIGHEST_PROTOCOL)

    trs_matrix = tdist.cdist(trjs, [trjs[i]],metric="edr",eps=200)
    with open('./distance_compution/EDR_distance/EDR_distance_' + str(i), 'wb') as f:
        pickle.dump(trs_matrix, f, pickle.HIGHEST_PROTOCOL)
    
    trs_matrix = tdist.cdist(trjs, [trjs[i]],metric="dtw")
    with open('./distance_compution/DTW_distance/DTW_distance_'+str(i), 'wb') as f:
        pickle.dump(trs_matrix, f , pickle.HIGHEST_PROTOCOL)

    print(('complete: '+str(i)))
Esempio n. 4
0
import numpy as np
import traj_dist.distance as tdist
import pickle

traj_list = pickle.load(open("/Users/bguillouet/These/trajectory_distance/data/benchmark_trajectories.pkl", "rb"))[:10]
traj_A = traj_list[0]
traj_B = traj_list[1]



# Simple distance

dist = tdist.sspd(traj_A, traj_B)
print(dist)

# Pairwise distance

pdist = tdist.pdist(traj_list, metric="sspd")
print(pdist)

# Distance between two list of trajectories

cdist = tdist.cdist(traj_list, traj_list, metric="sspd")
print(cdist)
Esempio n. 5
0
    # read_name='traffic_set_idx_06260152.txt'
    # read_name='traffic_set_idx_06260227.txt'
    # read_name='traffic_set_idx_06280622.txt'
    # read_name='traffic_set_idx_06290219.txt'
    train_set, train_labels, test_set, truth_labels = read_traffic_dataset(
        resample=True, randomize=True)
    train_num = len(train_labels)
    test_num = len(truth_labels)

    dm_eucl = np.zeros((train_num, test_num))
    for i in range(train_num):
        print(i)
        for j in range(test_num):
            dm_eucl[i, j] = eucdist(train_set[i], test_set[j])

    dm_dtw = tdist.cdist(train_set, test_set, metric='dtw')
    dm_sspd = tdist.cdist(train_set, test_set, metric='sspd')
    dm_lcss = tdist.cdist(train_set, test_set, metric='lcss', eps=0.05)
    dm_edr = tdist.cdist(train_set, test_set, metric='edr', eps=0.05)
    dm_erp = tdist.cdist(train_set,
                         test_set,
                         metric='erp',
                         g=np.zeros(2, dtype=float))
    dm_fre = tdist.cdist(train_set, test_set, metric='frechet')
    dm_hau = tdist.cdist(train_set, test_set, metric='hausdorff')

    np.savez_compressed('traffic_dm_eucl', dm_eucl)
    np.savez_compressed('traffic_dm_dtw', dm_dtw)
    np.savez_compressed('traffic_dm_sspd', dm_sspd)
    np.savez_compressed('traffic_dm_lcss', dm_lcss)
    np.savez_compressed('traffic_dm_edr', dm_edr)
Esempio n. 6
0
def trajectoryAlldistance(i,trjs):
    trs_matrix = tdist.cdist(trjs, [trjs[i]],metric="edr",eps=0.05)
    #print(trs_matrix)
    cPickle.dump(trs_matrix, open('./distance_compution/EDR_distance/EDR_distance_' + str(i), 'w'))
    print 'complete: '+str(i)
import numpy as np

# Three 2-D Trajectory
traj_A = np.array([[-122.39534, 37.77678],[-122.3992 , 37.77631],[-122.40235, 37.77594],[-122.40553, 37.77848],
                   [-122.40801, 37.78043],[-122.40837, 37.78066],[-122.41103, 37.78463],[-122.41207, 37.78954],
                   [-122.41252, 37.79232],[-122.41316, 37.7951 ],[-122.41392, 37.7989 ],[-122.41435, 37.80129],
                   [-122.41434, 37.80129]])
traj_B = np.array([[-122.39472, 37.77672],[-122.3946 , 37.77679],[-122.39314, 37.77846],[-122.39566, 37.78113],
                   [-122.39978, 37.78438],[-122.40301, 37.78708],[-122.4048 , 37.78666],[-122.40584, 37.78564],
                   [-122.40826, 37.78385],[-122.41061, 37.78321],[-122.41252, 37.78299]])
traj_C = np.array([[-122.39542, 37.77665],[-122.3988 , 37.77417],[-122.41042, 37.76944],[-122.41459, 37.77016],
                   [-122.41462, 37.77013]])
traj_list = [traj_A, traj_B, traj_C]

import traj_dist.distance as tdist

# Simple distance

dist = tdist.sspd(traj_A,traj_B)
print(dist)

# Pairwise distance

pdist = tdist.pdist(traj_list,metric="sspd")
print(pdist)

# Distance between two list of trajectories

cdist = tdist.cdist(traj_list, traj_list,metric="sspd")
print(cdist)