コード例 #1
0
def _get_top_n_samples(model_predictions: List[ModelPrediction], n: int, best: bool):
    top_n_samples = SortedList(key=lambda sample: -sample.true_label_probability) if best else SortedList()
    for model_prediction in model_predictions:
        if best == model_prediction.is_correct():
            if len(top_n_samples) < n:
                top_n_samples.add(model_prediction)
            else:
                if best != (model_prediction < top_n_samples[-1]):
                    top_n_samples.pop()
                    top_n_samples.add(model_prediction)
    return [sample for sample in top_n_samples]  # so that it returns a normal list instead of SortedList
コード例 #2
0
    def test_nlines(self):
        reader, start_time = self.init_reader()
        tpoints = SortedList()
        time_points, jobs = reader.next(start_time)
        tpoints.update(time_points)
        total_jobs = len(jobs)
        while True:
            if not tpoints:
                break
            _time = tpoints.pop(0)
            time_points, jobs = reader.next(_time)
            total_jobs += sum([len(js) for js in jobs.values()])
            tpoints.update(time_points)

        self.assertEqual(total_jobs, 25)
コード例 #3
0
ds = [a for a in AnmalZoo]

for uat in ds:
    r = SortedList()
    big128, big256 = 0, 0

    automatas = atma.parse_anml_file(anml_path[uat])
    automatas.remove_ors()
    automatas = automatas.get_connected_components_as_automatas()

    for atm in automatas:
        nc = atm.nodes_count
        if nc >= 128:
            big128 += 1
        if nc >= 256:
            big256 += 1

        if nc > bigest_component_size:
            print "this NFA can not be fit:", uat
            break

        if r and nc <= r[-1]:  # can be packed
            cand_residual = r.pop(-1)
            r.add(cand_residual - nc)
        else:  # new fcb
            r.add(bigest_component_size - nc)

    print "uat %s needs %d connected local switches each with (%d,%d) size. There are %d nodes not being assigned." \
          " It has %d CCs bigger than 128 and %d CCs bigger than 256"\
          %(uat, len(r), fcb_size, fcb_size, sum(r[:-1]), big128, big256)