Exemplo n.º 1
0
def main7():
    '''Weighted Error
    '''
    # DIR  = 'output7'       # 100 hypothesis
    DIR2 = 'interpolate10'  # 1600 hypothesis interpolated
    DIR3 = 'output8'  # 1600 hypothesis
    _, itwom_inter = read_all_data(DIR2)
    fspl_true, itwom_true = read_all_data(DIR3)
    clean_all_itwom(itwom_true, fspl_true)
    mean, median, std, coarse_mean, coarse_median, coarse_std, fine_mean, fine_median, fine_std = customized_error(
        itwom_inter, itwom_true)
    print('\nmean      = {:.3f}, median      = {:.3f}, std      = {:.3f}\ncoar mean = {:.3f}, coar median = {:.3f}, coar std = {:.3f}\nfine mean = {:.3f}, fine median = {:.3f}, fine std = {:.3f}'.format(\
             mean, median, std, coarse_mean, coarse_median, coarse_std, fine_mean, fine_median, fine_std))
Exemplo n.º 2
0
def main3():
    '''fix tx
    '''
    original_dir_10 = 'output7'
    original_dir_40 = 'output8'
    fix_dir_10 = 'output15'
    fix_dir_40 = 'output16'
    fspl10_fix, itwom10_fix = read_all_data(fix_dir_10)
    fspl40_fix, itwom40_fix = read_all_data(fix_dir_40)
    size = len(fspl10_fix)
    for i in range(size):
        tx = '{:04}'.format(i)
        fix_one_tx(original_dir_10, tx, fspl10_fix[i], itwom10_fix[i])
    size = len(fspl40_fix)
    for i in range(size):
        tx = '{:04}'.format(i)
        fix_one_tx(original_dir_40, tx, fspl40_fix[i], itwom40_fix[i])
Exemplo n.º 3
0
def main6():
    DIR = 'output13'  # 100 hypothesis
    DIR2 = 'interpolate13'  # 1600 hypothesis interpolated
    DIR3 = 'output14'  # 1600 hypothesis
    fspl, itwom = read_all_data(DIR)
    clean_all_itwom(itwom, fspl)
    fspl_inter = interpolate_idw(fspl, factor=4)
    itwom_inter = interpolate_idw(itwom, factor=4)

    fspl_true, itwom_true = read_all_data(DIR3)
    clean_all_itwom(itwom_true, fspl_true)
    mean, median, root = compute_error(fspl_inter, fspl_true)
    print(
        'FSPL:\nmean absolute error     = {}\nmedian absolute error   = {}\nroot mean squared error = {}\n'
        .format(mean, median, root))

    mean, median, root = compute_error(itwom_inter, itwom_true)
    print(
        'ITWOM:\nmean absolute error     = {}\nmedian absolute error   = {}\nroot mean squared error = {}\n\n'
        .format(mean, median, root))
    write_all_data(fspl_inter, itwom_inter, DIR2)
Exemplo n.º 4
0
def main1():
    # granularity5  = 'output9'
    # granularity10 = 'output7'
    # granularity20 = 'output10'
    # txmg = TxMultiGran(4, 5, debug=True)
    # txs = [(4, 5), (8, 10)]  # the same tx in grid length 10 and 20
    # grid_lens = [10, 20]
    # granularity_directory = [granularity10, granularity20]
    # for tx, grid_len, directory in zip(txs, grid_lens, granularity_directory):
    #     index = indexconvert(tx, grid_len)
    #     txfile = directory + '/' + '{:04}'.format(index)
    #     itwom = read_clean_itwom(txfile)
    #     txmg.add_sensor_data(grid_len, itwom)
    # txmg.combine_sensor_data()

    DIR0 = 'output9'  # 25  hypotheses
    DIR1 = 'output7'  # 100 hypotheses
    DIR2 = 'output10'  # 400 hypotheses
    DIR3 = 'output8'  # 1600 hypotheses
    DIR4 = 'interpolate8'  # 1600 hypotheses interpolated

    # DIR1 = 'output9'            # 25 hypotheses
    # DIR2 = 'output7'            # 100 hypotheses
    # DIR3 = 'interpolate9'       # 400 hypotheses interpolated
    # DIR4 = 'output10'           # 400 hypotheses

    # txfiles = sorted(glob.glob(DIR1 + '/*'))
    # txs = []
    # factors = [2, 4]   # factors in grid_len
    # directories = [DIR2, DIR3]

    # TxMultiGran.TX_GRID_LEN = 20
    # txfiles = sorted(glob.glob(DIR2 + '/*'))
    # txs = []
    # factors = [0.5, 2]   # factors in grid_len
    # directories = [DIR1, DIR3]

    # TxMultiGran.TX_GRID_LEN = 40
    # txfiles = sorted(glob.glob(DIR3 + '/*'))
    # txs = []
    # factors = [0.25, 0.5]   # factors in grid_len
    # directories = [DIR1, DIR2]

    TxMultiGran.TX_GRID_LEN = 40
    txfiles = sorted(glob.glob(DIR3 + '/*'))
    txs = []
    factors = [0.125, 0.25, 0.5]  # factors in grid_len
    directories = [DIR0, DIR1, DIR2]

    target_grid_len = 40
    for txfile in txfiles:
        tx_1dindex = get_tx_index(txfile)  # 1d index of TX
        try:
            itwom = read_clean_itwom(txfile)
        except:
            print(txfile)
            continue
        grid_len = int(math.sqrt(len(itwom)))
        x, y = indexconvert(tx_1dindex, grid_len)
        txmg = TxMultiGran(x, y, debug=True)
        txmg.add_sensor_data(grid_len, itwom)

        for factor, directory in zip(factors, directories):
            fine_grid_len = int(grid_len * factor)  # multi-granularity sensor
            fine_x = int(x * factor)
            fine_y = int(y * factor)
            txfile = directory + '/{:04}'.format(
                indexconvert((fine_x, fine_y), fine_grid_len))
            itwom = read_clean_itwom(txfile)
            txmg.add_sensor_data(fine_grid_len, itwom)
        txmg.combine_sensor_data()
        txs.append(txmg)

    itwom_inter = MultiIntepolate.idw_interpolate(
        txs, target_grid_len=target_grid_len)

    fspl_true, itwom_true = read_all_data(DIR3)
    clean_all_itwom(itwom_true, fspl_true)

    mean, median, root = compute_error(itwom_inter, itwom_true)
    print(
        'ITWOM:\nmean absolute error     = {}\nmedian absolute error   = {}\nroot mean squared error = {}'
        .format(mean, median, root))

    mean, median, std, coarse_mean, coarse_median, coarse_std, fine_mean, fine_median, fine_std = customized_error(
        itwom_inter,
        itwom_true,
        dist_th=8,
        factor=int(target_grid_len / TxMultiGran.TX_GRID_LEN))
    print('mean      = {:.3f}, median      = {:.3f}, std      = {:.3f}\ncoar mean = {:.3f}, coar median = {:.3f}, coar std = {:.3f}\nfine mean = {:.3f}, fine median = {:.3f}, fine std = {:.3f}'.format(\
             mean, median, std, coarse_mean, coarse_median, coarse_std, fine_mean, fine_median, fine_std))

    write_all_itwom(itwom_inter, DIR4)

    print(Global.GRAN_LEVEL)