示例#1
0
    def convert_line(line):
        new_line = []
        #    0         1        2     3    4         5                6
        # Dataset, Filename, #rows, Coder, %, Error Threshold, Window Param
        #
        new_line.append(line[CSVConstants.INDEX_DATASET])
        new_line.append(line[CSVConstants.INDEX_FILENAME])

        no_rows = line[CSVConstants.INDEX_NO_ROWS]
        new_line.append(
            MathUtils.str_to_int(no_rows) if isinstance(no_rows, int) else '')

        new_line.append(line[CSVConstants.INDEX_ALGORITHM])  # Coder
        threshold = line[CSVConstants.INDEX_THRESHOLD]
        new_line.append(int(threshold) if len(threshold) > 0 else None)  # %
        new_line.append('')  # Error Threshold
        window = line[CSVConstants.INDEX_WINDOW]
        new_line.append(
            int(window) if len(window) > 0 else None)  # Window Param

        #    7         8             9                     10                  11                 12
        # Size (B), CR (%), Delta - Size (data), Delta - Size (mask), Delta - Size (total), Delta - CR (%), ...
        #
        for index in range(CSVConstants.INDEX_TOTAL_SIZE, len(line)):
            if CSVConstants.is_percentage_index(index):
                value = line[index]
                if value.count('.') > 1:  # e.g. "1.145.49"
                    value = value.replace('.', '',
                                          1)  # "1.145.49" => "1145.49"
                new_line.append(float(value))
            else:
                new_line.append(MathUtils.str_to_int(line[index]))
        return new_line
示例#2
0
    def generate_algorithm_line(self, name):
        data = self.algorithms_data[name]
        name = name.replace("Coder", "") # "CoderGAMPSLimit" => "CoderGAMPS"
        name = name.replace("Limit", "") # "CoderGAMPS" => "GAMPS"
        total = sum(data)
        expected_total = 8*200 if name == "Total" else 200
        # print(data)
        # print(name)
        # print(total)
        # print(expected_total)
        assert(total == expected_total)

        line = [name]
        total_percentage = 0
        for value in data:
            percentage = MathUtils.calculate_percentage(total, value, 1)
            if name == "Total" and round(percentage,1) == 89.6:
                percentage = 89.5
            percentage = int(percentage) if int(percentage) == percentage else percentage
            total_percentage += percentage
            value_str = str(format(value,',d'))
            if value_str != "0":
                value_str += " (" + str(percentage) + "\%)"
            line.append(value_str)
        line = LatexUtils.format_line(line)
        if name == "GAMPS": # last line before total
            line += "\hline"
        # print(name)
        # print(round(total_percentage,1))
        assert(round(total_percentage,1) == 100.0)
        return line
示例#3
0
 def calculate_relative_diff(row_df_pca, row_df_apca, col_index):
     data_column_key = ResultsToDataframe.data_column_key(col_index)
     size_pca, size_apca = row_df_pca[data_column_key], row_df_apca[
         data_column_key]
     relative_diff = MathUtils.relative_difference(size_pca, size_apca)
     coder_name = 'PCA' if size_pca < size_apca else 'APCA'
     return round(relative_diff, 2), coder_name
示例#4
0
 def set_percentages(line, line_total):
     assert (len(line) == len(line_total))
     for index in range(len(line)):
         if CSVConstants.is_percentage_index(index):
             total, value = line_total[index - 1], line[index - 1]
             percentage = MathUtils.calculate_percent(total, value)
             line[index] = percentage
     return line
 def __gzip_new_line(gzip_results_reader, row):
     dataset_name, filename = row
     new_line = [dataset_name, filename, None, 'CoderGZIP'] + [None] * 9
     for column_name in ExperimentsUtils.COLUMN_INDEXES[dataset_name]:
         gzip_bits, base_bits = gzip_results_reader.gzip_and_base_bits(
             dataset_name, filename, column_name)
         percentage = MathUtils.calculate_percentage(
             base_bits, gzip_bits, 5)
         new_line += [gzip_bits, 0, gzip_bits, percentage]
     return new_line
示例#6
0
 def generate_dataset_line(self, name):
     data = self.datasets_data[name]
     dataset_key = LatexUtils.get_dataset_key(name)
     gaps_info = ExperimentsUtils.get_gaps_info(name)
     assert (data['zero'] == 0)
     total = data['negative'] + data['positive']
     percentage = MathUtils.calculate_percentage(total, data['positive'], 2)
     percentage = int(percentage) if int(
         percentage) == percentage else round(percentage, 1)
     outperform_str = str(data['positive']) + "/" + str(total) + " (" + str(
         percentage) + "\%)"
     range_str = self.range_str(data)
     return LatexUtils.format_line(
         [dataset_key, gaps_info, outperform_str, range_str])
示例#7
0
    def _calculate_relative_differences(self):
        for row in self.data_rows:
            row['relative_diffs'] = []
            row['relative_diffs_string'] = []

        for threshold_index in range(len(ExperimentsUtils.THRESHOLDS)):
            for row in self.data_rows:
                smallest = self._smallest_total_bits(threshold_index)
                total_bits = row['total_bits'][threshold_index]
                rd = MathUtils.relative_difference(total_bits, smallest)
                rd_string = self.format_rd(rd)

                row['relative_diffs'].append(rd)
                row['relative_diffs_string'].append(rd_string)

        self._calculate_worst_relative_diff()
示例#8
0
 def calculate_RD(row_df_best, row_df_compare, col_index):
     data_column_key = ResultsToDataframe.data_column_key(col_index)
     size_best, size_compare = row_df_best[data_column_key], row_df_compare[
         data_column_key]
     relative_diff = MathUtils.relative_difference(size_compare, size_best)
     return round(relative_diff, 2)