コード例 #1
0
ファイル: splat.py プロジェクト: caitaozhan/Localization
def main1():
    random.seed(0)
    np.random.seed(0)
    ll = Localization(grid_len=10)
    # ll.init_data()
    inter = Interpolate(ll.sensors, ll.means, ll.stds)  #''' args... '''
    sensors_inter, means_inter, stds_inter = inter.idw_inter(factor=4)
    ll_inter = Localization(grid_len=40)
    ll_inter.init_data_direct(ll.covariance, sensors_inter, means_inter,
                              stds_inter)
コード例 #2
0
ファイル: overall.py プロジェクト: caitaozhan/Localization
def overall():
    '''Overall approach
    '''
    config = 'config/splat_config_40.json'
    cov_file = 'dataSplat/1600/cov'
    sensor_file = 'dataSplat/1600/sensors'
    intruder_hypo_file = 'dataSplat/1600/hypothesis'
    primary_hypo_file = 'dataSplat/1600/hypothesis_primary'
    secondary_hypo_file = 'dataSplat/1600/hypothesis_secondary'
    primary = [123, 1357]  # fixed

    selectsensor = Localization(config)
    selectsensor.init_data(
        cov_file, sensor_file,
        intruder_hypo_file)  # offline step: init intruder hypo
    selectsensor.setup_primary_transmitters(
        primary, primary_hypo_file)  # offline step: construct primary
    selectsensor.add_primary(
        primary_hypo_file)  # offline step: construct intruder + primary

    counter = 0
    while counter < 3:
        time.sleep(1)
        # if counter % 1 == 0:                                                      # Change secondary
        #     secondary = random_secondary()
        #     selectsensor.setup_secondary_transmitters(secondary, secondary_hypo_file)    # online step: construct secondary
        #     selectsensor.add_secondary(secondary_hypo_file)  # online step: construct primary + intruder + secondary
        #     selectsensor.rescale_all_hypothesis()
        #     selectsensor.transmitters_to_array()
        #     #results = selectsensor.select_offline_greedy_lazy_gpu(25, 10, o_t_approx_kernal2)
        #     results = selectsensor.select_offline_greedy_hetero(25, 10, o_t_approx_kernal2)
        #     print(results[-1])
        #     #plots.visualize_selection(counter, selectsensor.grid_len, primary, secondary, results[-1], selectsensor.sensors)
        '''
コード例 #3
0
ファイル: utah.py プロジェクト: caitaozhan/Localization
def main2():
    '''SPLOT
    '''
    random.seed(0)
    np.random.seed(0)
    means, stds, locations, wall = read_utah_data(path='dataUtah')
    lt = LocationTransform(locations, cell_len=1)

    ll = Localization(grid_len=lt.grid_len, case='utah', debug=False)
    ll.init_utah(means, stds, locations, lt, wall, interpolate=False)

    a, b = 0, 100
    num_of_intruders = 2
    errors = []
    misses = []
    false_alarms = []
    for i in range(a, b):
    # for i in [89]:
        if i == 29 or i == 74 or i == 77 or i == 84:
            i += 100
        print('\n\nTest ', i)
        random.seed(i)
        np.random.seed(i)
        true_powers = [random.uniform(-0, 0) for i in range(num_of_intruders)]
        intruders_real, true_indices = generate_intruders_utah(grid_len=ll.grid_len, locations=locations, lt=lt, num=num_of_intruders, min_dist=1, max_dist=3)

        intruders, sensor_outputs = set_intruders_utah(true_indices=true_indices, powers=true_powers, means=means, grid_loc=lt.grid_location, ll=ll, randomness=True)
        
        r1 = 10
        r2 = 6
        threshold = -51
        pred_locations = ll.splot_localization(sensor_outputs, intruders, fig=i, R1=r1, R2=r2, threshold=threshold)

        print('True', end=' ')
        for intru in intruders:
            print(intru)
        true_locations = ll.convert_to_pos(true_indices)
        pred_locations_real = [lt.gridcell_2_real(cell) for cell in pred_locations]

        try:
            error, miss, false_alarm = ll.compute_error2(intruders_real, pred_locations_real)
            if len(error) != 0:
                errors.extend(error)
            misses.append(miss)
            false_alarms.append(false_alarm)
            print('\nerror/miss/false = {:.3f}/{}/{}'.format(np.array(error).mean(), miss, false_alarm) )
            if ll.debug:
                visualize_localization(ll.grid_len, true_locations, pred_locations, i)
        except Exception as e:
            print(e)

    try:
        # plot_cdf(errors)
        # np.savetxt('visualize/utah/ridge.txt', errors, delimiter=',')
        errors = np.array(errors)
        print('(mean/max/min) error=({:.3f}/{:.3f}/{:.3f}), miss=({:.3f}/{}/{}), false_alarm=({:.3f}/{}/{})'.format(errors.mean(), errors.max(), errors.min(), \
              sum(misses)/(b-a), max(misses), min(misses), sum(false_alarms)/(b-a), max(false_alarms), min(false_alarms) ) )
    except Exception as e:
        print(e)
コード例 #4
0
ファイル: utah.py プロジェクト: caitaozhan/Localization
def main1():
    '''Our localization
    '''
    random.seed(0)
    np.random.seed(0)
    means, stds, locations, wall = read_utah_data(path='dataUtah')
    lt = LocationTransform(locations, cell_len=1)

    ll = Localization(grid_len=lt.grid_len, case='utah', debug=False)
    ll.init_utah(means, stds, locations, lt, wall, interpolate=True, percentage=.8)

    num_of_intruders = 3
    a, b = 0, 100

    errors = []
    misses = []
    false_alarms = []
    power_errors = []
    ll.counter.num_exper = b-a
    ll.counter.time_start()
    for i in range(a, b):
    # for i in [27, 50]:
        if i == 29 or i == 74 or i == 77 or i == 84:
            i += 100
        print('\n\nTest ', i)
        random.seed(i)
        np.random.seed(i)
        true_powers = [random.uniform(-0, 0) for i in range(num_of_intruders)]
        intruders_real, true_indices = generate_intruders_utah(grid_len=ll.grid_len, locations=locations, lt=lt, num=num_of_intruders, min_dist=1, max_dist=3)
        intruders, sensor_outputs = set_intruders_utah(true_indices=true_indices, powers=true_powers, means=means, grid_loc=lt.grid_location, ll=ll, randomness=True)
        print('True: ' + ''.join(map(lambda x:str(x), intruders)))

        pred_locations, pred_power = ll.our_localization(sensor_outputs, intruders, i)

        true_locations = ll.convert_to_pos(true_indices)
        pred_locations_real = [lt.gridcell_2_real(cell) for cell in pred_locations]

        try:
            error, miss, false_alarm, power_error = ll.compute_error(intruders_real, true_powers, pred_locations_real, pred_power)
            if len(error) != 0:
                errors.extend(error)
                power_errors.extend(power_error)
            misses.append(miss)
            false_alarms.append(false_alarm)
            print('\nerror/miss/false/power = {:.3f}/{}/{}/{:.3f}'.format(np.array(error).mean(), miss, false_alarm, np.array(power_error).mean()) )
            if ll.debug:
                visualize_localization(ll.grid_len, true_locations, pred_locations, i)
        except Exception as e:
            print(e)

    try:
        # plot_cdf(errors)
        # np.savetxt('visualize/utah/0.7.txt', errors, delimiter=',')
        errors = np.array(errors)
        power_errors = np.array(power_errors)
        print('(mean/max/min) error=({:.3f}/{:.3f}/{:.3f}), miss=({:.3f}/{}/{}), false_alarm=({:.3f}/{}/{}), power=({:.3f}/{:.3f}/{:.3f})'.format(errors.mean(), errors.max(), errors.min(), \
              sum(misses)/(b-a), max(misses), min(misses), sum(false_alarms)/(b-a), max(false_alarms), min(false_alarms), power_errors.mean(), power_errors.max(), power_errors.min() ) )
        ll.counter.time_end()
        ratios = ll.counter.procedure_ratios()
        print(ratios)
        print('Proc-1 time = {:.3f}, Proc-1.1 = {:.3f}, Proc-2-2 time = {:.3f}, Proc-2-3 time = {:.3f}'.format(ll.counter.time1_average(), ll.counter.time2_average(), ll.counter.time3_average(), ll.counter.time4_average()))
    except Exception as e:
        print(e)
コード例 #5
0
import numpy as np
import pandas as pd
import sys
import time
import random
sys.path.append('../..')
from localize import Localization
from utility_ipsn import generate_intruders


# SelectSensor version on May 31, 2019
ll = Localization(grid_len=50)
ll.init_data('../../data50/homogeneous-200/cov', '../../data50/homogeneous-200/sensors', '../../data50/homogeneous-200/hypothesis')

num_of_intruders = 10

a, b = 0, 50
errors = []
misses = []
false_alarms = []
power_errors = []
start = time.time()
for i in range(a, b):
    print('\n\nTest ', i)
    random.seed(i)
    true_powers = [random.uniform(-2, 2) for i in range(num_of_intruders)]
    random.seed(i)
    np.random.seed(i)
    true_indices, true_powers = generate_intruders(grid_len=ll.grid_len, edge=2, num=num_of_intruders, min_dist=1, powers=true_powers)
    intruders, sensor_outputs = ll.set_intruders(true_indices=true_indices, powers=true_powers, randomness=True)
コード例 #6
0
import numpy as np
import pandas as pd
import sys
import time
import random
sys.path.append('../..')
from localize import Localization
from utility import generate_intruders

# SelectSensor version on May 31, 2019
ll = Localization(grid_len=50)
ll.init_data('../../data50/homogeneous-200/cov',
             '../../data50/homogeneous-200/sensors',
             '../../data50/homogeneous-200/hypothesis')

num_of_intruders = 1

a, b = 0, 50
errors = []
misses = []
false_alarms = []
power_errors = []
start = time.time()
for i in range(a, b):
    print('\n\nTest ', i)
    random.seed(i)
    true_powers = [random.uniform(-2, 2) for i in range(num_of_intruders)]
    random.seed(i)
    np.random.seed(i)
    true_indices, true_powers = generate_intruders(grid_len=ll.grid_len,
                                                   edge=2,
コード例 #7
0
ファイル: server.py プロジェクト: caitaozhan/Localization
    transmit_power = {"T1": 30}  # 3
    full_training_data = 'inter-' + str(gran)
    sub_training_data = full_training_data + '_{}'.format(sensor_density)  # 4

    result_date = '10.22-2'  # 5
    train_percent = int(gran * gran / (40 * 40) * 100)  # 6
    output_dir = 'results/{}'.format(result_date)
    output_file = 'log'  # 7
    train = TrainingInfo.naive_factory(data_source, sub_training_data,
                                       train_percent)
    # subsample_from_full(train, grid_len, sensor_density, transmit_power)      # 8

    print(train)
    server_support = ServerSupport(train.hostname_loc, output_dir, output_file,
                                   train.tx_calibrate)
    ll = Localization(grid_len=grid_len, case=data_source, debug=True)
    ll.init_data(train.cov, train.sensors, train.hypothesis, SplatMap)

    # init another object named ll_ss add primary
    num_authorized = 5  # 9
    authorized = Authorized(grid_len=grid_len,
                            edge=2,
                            case=data_source,
                            num=num_authorized)
    ll_ss = Localization(grid_len=grid_len,
                         case=data_source,
                         debug=True,
                         authorized=authorized)
    ll_ss.init_data(train.cov, train.sensors, train.hypothesis, SplatMap)
    true_data_path = Default.true_data_path.format(sensor_density)
    hypothesis_file = true_data_path + '/hypothesis'
コード例 #8
0
    num_authorized = args.num_authorized[0]
    sen_density = args.sen_density[0]
    methods = args.methods
    repeat = args.repeat
    port = args.port[0]

    # Client.test_server(Default.server_ip, port)

    myinput = Input(num_intruder=num_intruder,
                    data_source='splat',
                    methods=methods,
                    sen_density=sen_density,
                    num_authorized=num_authorized)

    # initialize a Localization object with the ground truth, use it to generate read data
    ll = Localization(grid_len=40, case='splat', debug=False)
    true_data_path = Default.true_data_path.format(sen_density)
    cov_file = true_data_path + '/cov'
    sensor_file = true_data_path + '/sensors'
    hypothesis_file = true_data_path + '/hypothesis'
    print('client side true data: \n{}\n{}\n{}\n'.format(
        cov_file, sensor_file, hypothesis_file))
    ll.init_data(cov_file, sensor_file, hypothesis_file)
    ll.init_truehypo(hypothesis_file)

    authorized = Authorized(grid_len=Default.grid_len,
                            edge=2,
                            case='splat',
                            num=num_authorized)

    myrange = range(repeat[0], repeat[1])
コード例 #9
0
import numpy as np
import pandas as pd
import sys
import time
import random

sys.path.append('../..')
from localize import Localization
from utility import generate_intruders

# SelectSensor version on May 31, 2019
ll = Localization(grid_len=40)
ll.init_data('../../dataSplat/homogeneous-200/cov',
             '../../dataSplat/homogeneous-200/sensors',
             '../../dataSplat/homogeneous-200/hypothesis')

num_of_intruders = 3

a, b = 0, 50
errors = []
misses = []
false_alarms = []
power_errors = []
ll.counter.num_exper = b - a
ll.counter.time_start()
for i in range(a, b):
    print('\n\nTest ', i)
    random.seed(i)
    true_powers = [random.uniform(-2, 2) for i in range(num_of_intruders)]
    random.seed(i)
    np.random.seed(i)