Exemple #1
0
def test_threshold_analyze():
    try:
        if not os.path.exists('test_items'):
            os.makedirs('test_items')
        item_file = 'test_items/data.item'
        feature_file = 'test_items/data.features'
        distance_file = 'test_items/data.distance'
        scorefilename = 'test_items/data.score'
        taskfilename = 'test_items/data.abx'
        analyzefilename = 'test_items/data.csv'
        threshold = 2

        items.generate_db_and_feat(3, 3, 1, item_file, 2, 3, feature_file)
        task = ABXpy.task.Task(item_file, 'c0', 'c1', 'c2')
        task.generate_triplets(taskfilename, threshold=threshold)
        distances.compute_distances(feature_file,
                                    '/features/',
                                    taskfilename,
                                    distance_file,
                                    dtw_cosine_distance,
                                    normalized=True,
                                    n_cpu=1)
        score.score(taskfilename, distance_file, scorefilename)
        analyze.analyze(taskfilename, scorefilename, analyzefilename)
        number_triplets = np.loadtxt(analyzefilename,
                                     dtype=int,
                                     delimiter='\t',
                                     skiprows=1,
                                     usecols=[-1])
        assert np.all(number_triplets == threshold)
    finally:
        shutil.rmtree('test_items', ignore_errors=True)
Exemple #2
0
def test_analyze():
    try:
        if not os.path.exists('test_items'):
            os.makedirs('test_items')
        item_file = 'test_items/data.item'
        feature_file = 'test_items/data.features'
        distance_file = 'test_items/data.distance'
        scorefilename = 'test_items/data.score'
        taskfilename = 'test_items/data.abx'
        analyzefilename = 'test_items/data.csv'

        items.generate_db_and_feat(3, 3, 1, item_file, 2, 3, feature_file)
        task = ABXpy.task.Task(item_file, 'c0', 'c1', 'c2')
        task.generate_triplets(taskfilename)
        distances.compute_distances(feature_file, '/features/', taskfilename,
                                    distance_file, dtw_cosine_distance)
        score.score(taskfilename, distance_file, scorefilename)
        analyze.analyze(taskfilename, scorefilename, analyzefilename)
    finally:
        try:
            os.remove(item_file)
            os.remove(feature_file)
            os.remove(taskfilename)
            os.remove(distance_file)
            os.remove(scorefilename)
            os.remove(analyzefilename)
            # pass
        except:
            pass
Exemple #3
0
def test_analyze():
    try:
        if not os.path.exists('test_items'):
            os.makedirs('test_items')
        item_file = 'test_items/data.item'
        feature_file = 'test_items/data.features'
        distance_file = 'test_items/data.distance'
        scorefilename = 'test_items/data.score'
        taskfilename = 'test_items/data.abx'
        analyzefilename = 'test_items/data.csv'

        items.generate_db_and_feat(3, 3, 1, item_file, 2, 3, feature_file)
        task = ABXpy.task.Task(item_file, 'c0', 'c1', 'c2')
        task.generate_triplets(taskfilename)
        distances.compute_distances(feature_file,
                                    '/features/',
                                    taskfilename,
                                    distance_file,
                                    dtw_cosine_distance,
                                    normalized=True,
                                    n_cpu=1)
        score.score(taskfilename, distance_file, scorefilename)
        analyze.analyze(taskfilename, scorefilename, analyzefilename)
    finally:
        shutil.rmtree('test_items', ignore_errors=True)
Exemple #4
0
def test_threshold_analyze():
    try:
        if not os.path.exists('test_items'):
            os.makedirs('test_items')
        item_file = 'test_items/data.item'
        feature_file = 'test_items/data.features'
        distance_file = 'test_items/data.distance'
        scorefilename = 'test_items/data.score'
        taskfilename = 'test_items/data.abx'
        analyzefilename = 'test_items/data.csv'
        threshold = 2

        items.generate_db_and_feat(3, 3, 1, item_file, 2, 3, feature_file)
        task = ABXpy.task.Task(item_file, 'c0', 'c1', 'c2')
        task.generate_triplets(taskfilename, threshold=threshold)
        distances.compute_distances(
            feature_file, '/features/', taskfilename,
            distance_file, dtw_cosine_distance,
            normalized = True, n_cpu=1)
        score.score(taskfilename, distance_file, scorefilename)
        analyze.analyze(taskfilename, scorefilename, analyzefilename)
        number_triplets = np.loadtxt(analyzefilename, dtype=int,
                                     delimiter='\t', skiprows=1, usecols=[-1])
        assert np.all(number_triplets == threshold)
    finally:
        try:
            shutil.rmtree('test_items')
            # os.remove(item_file)
            # os.remove(feature_file)
            # os.remove(taskfilename)
            # os.remove(distance_file)
            # os.remove(scorefilename)
            # os.remove(analyzefilename)
        except:
            pass
Exemple #5
0
def test_score():
    try:
        if not os.path.exists('test_items'):
            os.makedirs('test_items')
        item_file = 'test_items/data.item'
        feature_file = 'test_items/data.features'
        distance_file = 'test_items/data.distance'
        scorefilename = 'test_items/data.score'
        taskfilename = 'test_items/data.abx'
        items.generate_db_and_feat(3, 3, 1, item_file, 2, 3, feature_file)
        task = ABXpy.task.Task(item_file, 'c0', 'c1', 'c2')
        task.generate_triplets()
        distances.compute_distances(
            feature_file, '/features/', taskfilename,
            distance_file, dtw_cosine_distance,
            normalized = True, n_cpu=3)
        score.score(taskfilename, distance_file, scorefilename)
    finally:
        try:
            shutil.rmtree('test_items')
            # os.remove(item_file)
            # os.remove(feature_file)
            # os.remove(taskfilename)
            # os.remove(distance_file)
            # os.remove(scorefilename)
        except:
            pass
Exemple #6
0
def test_score():
    try:
        if not os.path.exists('test_items'):
            os.makedirs('test_items')
        item_file = 'test_items/data.item'
        feature_file = 'test_items/data.features'
        distance_file = 'test_items/data.distance'
        scorefilename = 'test_items/data.score'
        taskfilename = 'test_items/data.abx'
        items.generate_db_and_feat(3, 3, 1, item_file, 2, 3, feature_file)
        task = ABXpy.task.Task(item_file, 'c0', 'c1', 'c2')
        task.generate_triplets()
        distances.compute_distances(feature_file,
                                    '/features/',
                                    taskfilename,
                                    distance_file,
                                    dtw_cosine_distance,
                                    normalized=True,
                                    n_cpu=3)
        score.score(taskfilename, distance_file, scorefilename)
    finally:
        try:
            shutil.rmtree('test_items')
            # os.remove(item_file)
            # os.remove(feature_file)
            # os.remove(taskfilename)
            # os.remove(distance_file)
            # os.remove(scorefilename)
        except:
            pass
Exemple #7
0
def fullrun():
    if not os.path.exists('example_items'):
        os.makedirs('example_items')
    item_file = 'example_items/data.item'
    feature_file = 'example_items/data.features'
    distance_file = 'example_items/data.distance'
    scorefilename = 'example_items/data.score'
    taskfilename = 'example_items/data.abx'
    analyzefilename = 'example_items/data.csv'

    # deleting pre-existing files
    for f in [item_file, feature_file, distance_file,
              scorefilename, taskfilename, analyzefilename]:
        try:
            os.remove(f)
        except OSError:
            pass

    # running the evaluation
    items.generate_db_and_feat(3, 3, 5, item_file, 2, 2, feature_file)

    task = ABXpy.task.Task(item_file, 'c0', across='c1', by='c2')
    task.generate_triplets(taskfilename)

    distances.compute_distances(
        feature_file, '/features/', taskfilename,
        distance_file, dtw_cosine_distance,
        normalized=True, n_cpu=1)

    score.score(taskfilename, distance_file, scorefilename)

    analyze.analyze(taskfilename, scorefilename, analyzefilename)
Exemple #8
0
def fullrun():
    if not os.path.exists('example_items'):
        os.makedirs('example_items')
    item_file = 'example_items/data.item'
    feature_file = 'example_items/data.features'
    distance_file = 'example_items/data.distance'
    scorefilename = 'example_items/data.score'
    taskfilename = 'example_items/data.abx'
    analyzefilename = 'example_items/data.csv'

    items.generate_db_and_feat(3, 3, 1, item_file, 2, 2, feature_file)
    task = ABXpy.task.Task(item_file, 'c0', 'c1', 'c2',
                           features=feature_file)
    task.generate_triplets()
    distances.compute_distances(feature_file, '/features/', taskfilename,
                                distance_file, dtw_cosine_distance)
    score.score(taskfilename, distance_file, scorefilename)
    analyze.analyze(scorefilename, taskfilename, analyzefilename)