def __generate_distance_matrix_on_separate_features(video1, video2):
        v1_shot_numbers = SimilarityCalculator.__get_video_shots(video1)
        v2_shot_numbers = SimilarityCalculator.__get_video_shots(video2)
        matrix = []
        for v1_shot_number in v1_shot_numbers:
            row = []
            for v2_shot_number in v2_shot_numbers:
                v1_shot = video1.shots[str(v1_shot_number)]
                v2_shot = video2.shots[str(v2_shot_number)]
                distance = 0
                if v1_shot.cluster != v2_shot.cluster:
                    v1_audio_features = SimilarityCalculator.__get_audio_features(
                        v1_shot.features)
                    v1_video_features = SimilarityCalculator.__get_audio_features(
                        v1_shot.features)

                    v2_audio_features = SimilarityCalculator.__get_audio_features(
                        v2_shot.features)
                    v2_video_features = SimilarityCalculator.__get_audio_features(
                        v2_shot.features)

                    audio_distance = utl.calculate_distance(
                        v1_audio_features, v2_audio_features)
                    video_distance = utl.calculate_distance(
                        v1_video_features, v2_video_features)

                    distance = 0.5 * (audio_distance + video_distance)
                row.append(distance)
            matrix.append(row)
        return matrix
def generate_average_distance_csv(features_csv, distance_output):
    feature_vectors = get_features_list(features_csv)
    feature_vector_count = len(feature_vectors)

    print "generating distance csv..."
    distance_count = 0
    distance_sum = 0
    iteration = 1
    for i in range(feature_vector_count):
        if i + 1 > feature_vector_count:
            break
        for j in range(i + 1, feature_vector_count):
            v1 = feature_vectors[i]
            v2 = feature_vectors[j]
            distance_sum += utility.calculate_distance(v1, v2)
            distance_count += 1
        utility.print_progress_bar(iteration, feature_vector_count)
        iteration += 1

    with open(distance_output, 'wb') as f:
        the_writer = csv.writer(f)
        headers = ["file", "average_distance"]
        the_writer.writerow(headers)
        vector = [features_csv, float(distance_sum) / float(distance_count)]
        the_writer.writerow(vector)
        f.close()
Example #3
0
def get_two_categories_distance(category_all_feature_vectors,
                                category_center_feature_vector):
    category_distance_list = []
    for category_feature_vector in category_all_feature_vectors:
        distance = utl.calculate_distance(category_feature_vector,
                                          category_center_feature_vector)
        category_distance_list.append(distance)
    return mean(category_distance_list)
 def __generate_full_distance_matrix(video1, video2):
     v1_shot_numbers = SimilarityCalculator.__get_video_shots(video1)
     v2_shots_numbers = SimilarityCalculator.__get_video_shots(video2)
     row_count = len(v1_shot_numbers)
     column_count = len(v2_shots_numbers)
     matrix = []
     for v1_shot_number in v1_shot_numbers:
         row = []
         for v2_shot_number in v2_shots_numbers:
             v1_shot = video1.shots[str(v1_shot_number)]
             v2_shot = video2.shots[str(v2_shot_number)]
             distance = utl.calculate_distance(v1_shot.features,
                                               v2_shot.features)
             row.append(distance)
         matrix.append(row)
     return matrix, row_count, column_count
def calculate_distance_mean(category, category_data_set):
    print("calculating distance mean for '" + category + "' category  ...")

    category_data_set_len = len(category_data_set)  # type: int
    distance_list = []
    for i in range(0, category_data_set_len):
        for j in range(i + 1, category_data_set_len):
            vec1 = category_data_set[i]
            vec2 = category_data_set[j]
            distance_list.append(utl.calculate_distance(vec1, vec2))
        utl.print_progress_bar(i + 1, category_data_set_len)
    print("")
    print("distance mean calculation for category '" + category +
          "' has been completed!")

    return calculate_mean(distance_list)
Example #6
0
def get_category_self_distance_dictionary(category_all_features,
                                          category_center_features):
    category_distance_dictionary = {}
    for category_name_average, category_average_feature_vector in category_center_features.iteritems(
    ):
        category_distance_dictionary[category_name_average] = []
        for category_complete_feature_vector in category_all_features[
                category_name_average]:
            distance = utl.calculate_distance(
                category_average_feature_vector,
                category_complete_feature_vector)
            category_distance_dictionary[category_name_average].append(
                distance)
    category_average_distance_dictionary = {}
    for category, distance_list in category_distance_dictionary.iteritems():
        category_average_distance_dictionary[category] = mean(distance_list)

    return category_average_distance_dictionary