From 45a83d473cce74ec6f03336c387574df564db516 Mon Sep 17 00:00:00 2001 From: HappyZ Date: Thu, 23 May 2019 18:08:58 -0500 Subject: [PATCH] bug fix! --- libs/util.py | 1 + localization_log_gamma_model.py | 2 +- syngen_floorplan_multipath.py | 35 +++++++++++++++++++++++++++++++-- tests/spacemap.py | 10 ++++++---- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/libs/util.py b/libs/util.py index b010082..1e325b4 100644 --- a/libs/util.py +++ b/libs/util.py @@ -45,6 +45,7 @@ def convert_vector_to_mat( for i in range(rx_locs.shape[0]): if offset is None: x, y = rx_locs[i, :] / block_size + print(x, y) else: x, y = (rx_locs[i, :] + offset) / block_size result[int(round(x)), int(round(y))] = rx_rsses[i] diff --git a/localization_log_gamma_model.py b/localization_log_gamma_model.py index bb8b696..1abea32 100644 --- a/localization_log_gamma_model.py +++ b/localization_log_gamma_model.py @@ -80,7 +80,7 @@ def fittingSingle(filepath, args): f.write( "{},".format(filename) + "{:.3f},{:.3f},".format(best_tx_loc[0], best_tx_loc[1]) + - "{:.2f},{:.2f}".format(best_tx_pwr, best_env_gamma) + + "{:.2f},{:.2f},".format(best_tx_pwr, best_env_gamma) + "{:.6f},".format(min_fit_mse) + "{:.4f},{:.4f},{:.4f},{:.4f}".format(stat['5perc'], stat['95perc'], stat['median'], stat['mean']) + "\n" diff --git a/syngen_floorplan_multipath.py b/syngen_floorplan_multipath.py index 1acd329..25efd3c 100644 --- a/syngen_floorplan_multipath.py +++ b/syngen_floorplan_multipath.py @@ -51,9 +51,29 @@ def log_gamma_floorplan_multi(floormap, rx_loc, tx_loc, power, gaussian_noise, r power, gaussian_noise=gaussian_noise ) + print(kk, rss) results[kk] = rss +def floormap_noise_injection(floormap, args): + if not args.floormap_rand: + return + for j in range(floormap.map.shape[1]): + if np.random.random() < 0.8: + continue + loss_p, loss_r = floormap.getLoss(i, j) + loss_r = np.random.randint(-3, 3) - 50 + floormap.setLoss( + i, j, + min(loss_p + np.random.randint(-3, 3), 0.0), + loss_r + ) + floormap.setOrientation( + i, j, + np.random.random() * 2 * np.pi - np.pi + ) + + def generateData(floormap, tx_locs, args): ''' ''' @@ -85,12 +105,16 @@ def generateData(floormap, tx_locs, args): rss_vec = [] starttime = int(time.time()) tx_loc = SpaceBlock(3.2, 3.2) + # tx_loc = SpaceBlock(tx_locs[i, 0], tx_locs[i, 1]) + if args.floormap_rand: + floormap = getFloormap(args) + floormap_noise_injection(floormap, args) floormap.traceRays(power, tx_loc) for j in range(0, rx_locs.shape[0], args.procnum): procs = [] results = Manager().dict() for kk in range(args.procnum): - rx_loc = SpaceBlock(rx_locs[j, 0], rx_locs[j, 1]) + rx_loc = SpaceBlock(rx_locs[j + kk, 0], rx_locs[j + kk, 1]) proc = Process( target=log_gamma_floorplan_multi, args=(floormap, rx_loc, tx_loc, power, args.withnoise, results, kk) @@ -195,7 +219,14 @@ if __name__ == '__main__': '--floormap', '-f', dest='floormap', default=None, - help='floormap data' + help='the base of floormap data' + ) + p.add_argument( + '--floormap-rand', '-frnd', + dest='floormap_rand', + action='store_true', + default=False, + help='add some random penetration losses in floormap' ) p.add_argument( '--with-noise', diff --git a/tests/spacemap.py b/tests/spacemap.py index a943628..ba4745b 100644 --- a/tests/spacemap.py +++ b/tests/spacemap.py @@ -53,16 +53,18 @@ def test(): plotSpace(spacemap, cminmax=(-50, 0.0)) - rx_locs = [SpaceBlock(1.0, 4.3), SpaceBlock(4.2, 4.4), SpaceBlock(4.4, 4.4)] + rx_locs = [] + for i in range(64): + rx_locs.append(SpaceBlock(0 + i * 0.1, 4.4)) spacemap.traceRays(-40, SpaceBlock(3.2, 3.2)) for rx_loc in rx_locs: rx_loc_rss, rx_loc_paths = spacemap.traceRay(rx_loc) multipaths = [] for path in rx_loc_paths: - print("found path: {}".format(path)) + # print("found path: {}".format(path)) multipaths.extend(list(path)) - print("rss = {:.6f}dB".format(rx_loc_rss)) - plotSpace(spacemap, space_rays=multipaths, cminmax=(-50, 0.0)) + print("{:.6f}".format(rx_loc_rss)) + # plotSpace(spacemap, space_rays=multipaths, cminmax=(-50, 0.0))