Ejemplo n.º 1
0
def bubble(numbers):
    ret = 0
    for i in range(0, len(numbers) - 1):
        for j in range(0, len(numbers) - i - 1):
            if numbers[i] > numbers[i + 1]:
                numbers[i], numbers[i + 1] = numbers[i + 1], numbers[i]
            ret += 1
    print_res("Bubble sort:", ret)
Ejemplo n.º 2
0
def selection(numbers):
    ret = 0
    for x in range(0, len(numbers) - 1):
        min = x
        for y in range(x + 1, len(numbers)):
            if numbers[y] < numbers[min]:
                min = y
            ret += 1
        numbers[x], numbers[min] = numbers[min], numbers[x]
    print_res("Selection sort:", ret)
Ejemplo n.º 3
0
def main(args):
    numbers = get_values(args[0])
    if (len(numbers) <= 0):
        sys.exit(84)
    print(len(numbers), " element", sep="", end="")
    print("s" if len(numbers) > 1 else "")
    selection(numbers[::])
    insertion(numbers[::])
    bubble(numbers[::])
    print_res("Quicksort:", 0 if (len(numbers) <= 1) else quicksort(numbers[::])[1])
    print_res("Merge sort:", merge(numbers[::])[1])
Ejemplo n.º 4
0
def insertion(numbers):
    ret = 0
    for x in range(1, len(numbers)):
        y = x
        while (y > 0):
            ret += 1
            if (numbers[y - 1] <= numbers[y]):
                numbers[y], numbers[y - 1] = numbers[y - 1], numbers[y]
                y -= 1
            else:
                break
    print_res("Insertion sort:", ret)
def process_ms(msname, outfn):
    station_map = utils.get_station_map(msname)
    station_names = sorted(station_map.keys())
    stations2 = sorted(map(station_map.get, station_names))
    ref_station_name = '1' # ANTENNA table has ID, Name and 'Station' fields'; here we want the last of these
    ref_station2 = station_map[ref_station_name]
    ref_s_ind2 = stations2.index(ref_station2)
    swid, pol_id, polind, = (0, 0, 0)

    for timeq in timeqs:
        delays, phases, rates, sigs = [], [], [], []
        for pol_id in [0,3]:
            dels, phs, rs, sig = fringer.fit_fringe_lm(msname, stations2, ref_s_ind2,
                                                       swid, polind, pol_id, timeq, solint=300)
            delays.append(dels)
            phases.append(phs)
            rates.append(rs)
            sigs.append(sig)
        outf = file(outfn, 'w')
        print >>outf, "#\n#{}\n#".format(timeq)
        utils.print_res(station_map, stations2, phases, delays, rates, sigs=sigs, outf=outf)
Ejemplo n.º 6
0
def main():
    testset, test_sampler = get_test_sampler(args)
    loss = get_val_loss_fn(args)

    # getting number of classes in the training set
    if 'imagenet' in args['model.dataset']:
        ncls = 351 if 'tiered' in args['model.dataset'] else 64
    else:
        ncls = 100

    # defining the model
    model = get_model(ncls, args, ensemble=False)
    model.eval()

    checkpointer = CheckPointer('singles', args, model)
    ckpt_path = checkpointer.best_ckpt
    if os.path.isfile(ckpt_path):
        start_epoch, best_val_loss, best_val_acc, waiting_for =\
            checkpointer.restore_model(ckpt='best', strict=False)
    else:
        print('Model ckpt file was not found at {}'.format(ckpt_path))
        exit(1)

    loss = get_val_loss_fn(args)

    if args['test.determ']:
        set_determ(args['test.seed'])

    losses, accs, _ = [], [], []
    for sample in tqdm(test_sampler):
        with torch.no_grad():
            _, stats_dict, pred_dict = loss(model, sample,
                                            args['test.distance'])
        losses.append(stats_dict['loss'])
        accs.append(stats_dict['acc'] * 100)

    model_path = '/'.join(ckpt_path.split('/')[:-1])
    print_res(losses, 'loss', os.path.join(model_path, 'stats.txt'))
    print_res(accs, 'accuracy', os.path.join(model_path, 'stats.txt'), prec=2)
Ejemplo n.º 7
0
def main():
    testset, test_sampler = get_test_sampler(args)
    loss = get_val_loss_fn(args)

    # getting number of classes in the training set
    if 'imagenet' in args['model.dataset']:
        ncls = 351 if 'tiered' in args['model.dataset'] else 64
    else:
        ncls = 100

    # defining the model
    model = get_model(ncls, args, ensemble=True)
    model.eval()

    checkpointer = CheckPointer('ensembles', args, model)
    ckpt_path = checkpointer.best_ckpt
    if os.path.isfile(ckpt_path):
        start_epoch, best_val_loss, best_val_acc, waiting_for =\
            checkpointer.restore_model(ckpt='best', strict=False)
    elif 'copy__' in ckpt_path:
        checkpointer.restore_from_singles()
    else:
        print('Model ckpt file was not found at {}'.format(ckpt_path))
        exit(1)

    # to ensure deterministic behavior
    if args['test.determ']:
        set_determ(args['test.seed'])

    # to collect testing results and report statistics later
    losses, probsum_accs, voted_accs, all_accs, agreements = [], [], [], [], []

    for sample in tqdm(test_sampler):
        with torch.no_grad():
            _, stats_dict, pred_dict = loss(model, sample)
        losses.append(stats_dict['loss'])
        voted_accs.append(stats_dict['voted_acc'] * 100)
        probsum_accs.append(stats_dict['probsum_acc'] * 100)
        all_accs.append(stats_dict['accs'] * 100)
        agreements.append(stats_dict['agreement'])

    model_path = '/'.join(ckpt_path.split('/')[:-1])
    stats_path = os.path.join(model_path, 'stats.txt')
    if 'copy__' in model_path or args['test.noprint']:
        stats_path = None

    # processing and printing out statistics
    agreement_mat = np.array(agreements).mean(0)
    np.set_printoptions(precision=2)
    print(agreement_mat)

    accs_mat = np.stack(all_accs)
    accs = accs_mat.mean(0)
    min_ind = accs.argmin(0)
    max_ind = accs.argmax(0)
    print('All accs: ', accs)
    print_res(losses, 'loss', stats_path)
    print_res(accs_mat.mean(1), 'mean_accuracy', stats_path, prec=2)
    print_res(accs_mat[:, min_ind], 'min_accuracy', stats_path, prec=2)
    print_res(accs_mat[:, max_ind], 'max_accuracy', stats_path, prec=2)
    print_res(voted_accs, 'voted_accuracy', stats_path, prec=2)
    print_res(probsum_accs, 'probsum_accuracy', stats_path, prec=2)
Ejemplo n.º 8
0
stations2 = [0, 1, 2, 3, 4, 5, 6, 7, 9, 10]

ref_station_name = myrefant  # '1' is Effelsberg
ref_station2 = station_map[ref_station_name]
ref_s_ind2 = stations2.index(ref_station2)
swid, polind, = (0, 0)

#stations2 = [0,1,2,3,4,5,6,7,9,10]
stations2 = [0, 1, 2, 3, 4, 5, 6, 7, 9, 10]

for timeq, swid in itertools.product(timeqs, range(4)):
    timeq2 = ffd.actual_timerangeq(msname, timeq)
    delays, phases, rates, sigs = [], [], [], []
    for pol_id in [0, 3]:
        print "# Doing a thing", swid, pol_id
        dels, phs, rs, sig = fringer.fit_fringe_lm(msname,
                                                   stations2,
                                                   ref_s_ind2,
                                                   swid,
                                                   polind,
                                                   pol_id,
                                                   timeq2,
                                                   solint=mysolint,
                                                   threshold=1000)
        delays.append(dels)
        phases.append(phs)
        rates.append(rs)
        sigs.append(sig)
    print "#\n#{}\n# IF {}\n#".format(timeq, swid + 1)
    utils.print_res(station_map, stations2, phases, delays, rates)