Example #1
0
def dtw_kl_divergence(x, y):
    """ Kullback-Leibler divergence """
    if x.shape[0] > 0 and y.shape[0] > 0:
        d = dtw.dtw(x, y, kullback_leibler.kl_divergence, True)
    elif x.shape[0] == y.shape[0]:
        d = 0
    else:
        d = np.inf
    return d
Example #2
0
def kl_divergence(x, y, normalized):
    """Kullback-Leibler divergence"""
    if x.shape[0] > 0 and y.shape[0] > 0:
        d = dtw.dtw(x, y, kullback_leibler.kl_divergence, normalized)
    elif x.shape[0] == y.shape[0]:
        d = 0
    else:
        d = np.inf
    return d
Example #3
0
def dtw_kl_divergence(x, y):
    """ Kullback-Leibler divergence
    """
    if x.shape[0] > 0 and y.shape[0] > 0:
        d = dtw.dtw(x, y, kullback_leibler.kl_divergence)
    elif x.shape[0] == y.shape[0]:
        d = 0
    else:
        d = np.inf
    return d
Example #4
0
def dtw_kl_divergence(x, y):
    """ Kullback-Leibler divergence """
    # times on rows, features on columns
    if x.shape[0] > 0 and y.shape[0] > 0:
        d = dtw.dtw(x, y, kullback_leibler.kl_divergence, True)
    elif x.shape[0] == y.shape[0]:
        d = 0
    else:
        d = np.inf
    return d
Example #5
0
def distance(x, y, normalized):
    """Dynamic time warping cosine distance

    The "feature" dimension is along the columns and the "time" dimension
    along the lines of arrays x and y
    """
    if x.shape[0] > 0 and y.shape[0] > 0:
        # x and y are not empty
        d = dtw.dtw(x, y, cosine.cosine_distance, normalized)
    elif x.shape[0] == y.shape[0]:
        # both x and y are empty
        d = 0
    else:
        # x or y is empty
        d = np.inf
    return d
Example #6
0
def default_distance(x, y):
    """ Dynamic time warping cosine distance

    The "feature" dimension is along the columns and the "time" dimension
    along the lines of arrays x and y
    """
    if x.shape[0] > 0 and y.shape[0] > 0:
        # x and y are not empty
        d = dtw.dtw(x, y, cosine.cosine_distance)
    elif x.shape[0] == y.shape[0]:
        # both x and y are empty
        d = 0
    else:
        # x or y is empty
        d = np.inf
    return d
Example #7
0
def dtw_cosine_distance(x, y):
    return dtw.dtw(x, y, cosine.cosine_distance)
Example #8
0
def dtw_cosine_distance(x, y, normalized):
    return dtw.dtw(x, y, cosine.cosine_distance, normalized)
Example #9
0
def dtw_cosine_distance(x, y, normalized):
    return dtw.dtw(x, y, cosine.cosine_distance, normalized)
Example #10
0
def dtw_cosine_distance(x, y):
    return dtw.dtw(x, y, cosine.cosine_distance)
Example #11
0
                        help=('if true, take mean distance along'
                              'dtw path length instead of sum'))
    args = parser.parse_args()
    assert path.exists(args.feat_file), ("No such file "
                                         "{}".format(args.feat_file))
    assert path.exists(args.task_file), ("No such file "
                                         "{}".format(args.task_file))
    dis_file = path.join(args.res_folder, 'distances',
                         args.res_id + '.distances')
    score_file = path.join(args.res_folder, 'scores', args.res_id + '.scores')
    result_file = path.join(args.res_folder, 'results', args.res_id + '.txt')
    assert not(path.exists(dis_file)), \
        "{} already exists".format(dis_file)
    assert not(path.exists(score_file)), \
        "{} already exists".format(score_file)
    assert not(path.exists(result_file)), \
        "{} already exists".format(result_file)
    assert args.distance in ['kl', 'cos', 'dur'], \
        "Distance function {} not supported".format(args.distance)
    if args.distance == 'kl':
        frame_dis = kl.kl_divergence
    elif args.distance == 'cos':
        frame_dis = cos.cosine_distance
    if args.distance in ['kl', 'cos']:
        distance = lambda x, y, normalized: dtw.dtw(
            x, y, frame_dis, normalized=normalized)
    else:
        distance = lambda x, y, normalized: np.abs(x.shape[0] - y.shape[0])
    run_ABX(args.feat_file, args.task_file, dis_file, score_file, result_file,
            distance, args.normalized)