Beispiel #1
0
raw_joint_distribution_F_iterable = [utils.independent_categorical_joint_distribution_F()]
joint_x_distribution_F_iterable = itertools.imap(tensor_scan_fxns.joint_x_distribution_F, raw_joint_distribution_F_iterable)
background_count_F_iterable = itertools.starmap(tensor_scan_fxns.region_x_independent_tensor_count_F, itertools.product(bin_region_count_F_iterable, joint_x_distribution_F_iterable))
foreground_count_F_iterable = [tensor_scan_fxns.empirical_tensor_count_F()]
optimizer_F_iterable = [utils.iterative_argmax_F(utils.get_initial_subset_x_random(0.5), utils.cycle_through_coord_iterative_step(), 20, 0.001)]
p_value_F_iterable = [tensor_scan_fxns.identity_test_stat_F()]
pattern_test_stat_iterable = [tensor_scan_fxns.pattern_test_stat]
pattern_F_iterable = itertools.starmap(tensor_scan_fxns.pattern_F, itertools.product(background_count_F_iterable, foreground_count_F_iterable, optimizer_F_iterable, pattern_test_stat_iterable, p_value_F_iterable))
pattern_finder_regions_F_iterable = itertools.imap(tensor_scan_fxns.background_and_foreground_regions_F, regions_F_iterable)
num_blocks_iterable = [100]
background_foreground_iterator_F_iterable = [tensor_scan_fxns.many_windows_iterator(num_blocks) for num_blocks in num_blocks_iterable]
raw_pattern_finder_F_iterable = itertools.starmap(tensor_scan_fxns.raw_pattern_finder_F, itertools.product(background_foreground_iterator_F_iterable, pattern_finder_regions_F_iterable, pattern_F_iterable))
scratch_oneshot_ranked_pattern_finder_F_iterable = itertools.imap(tensor_scan_fxns.oneshot_ranked_pattern_finder_F, raw_pattern_finder_F_iterable)
iterative_max_iter = 3
scratch_ss_pattern_finder_F_iterable = itertools.imap(tensor_scan_fxns.most_significant_pattern_finder_F, raw_pattern_finder_F_iterable)
scratch_iterative_ranked_pattern_finder_F_iterable = itertools.imap(functools.partial(tensor_scan_fxns.iterative_ranked_pattern_finder_F, iterative_max_iter), scratch_ss_pattern_finder_F_iterable)

"""
scratch baseline_method_iterable
"""
location_dist_F_iterable = [tensor_scan_fxns.location_dist_F('euclidean')]
time_dist_F_iterable = [tensor_scan_fxns.time_dist_F('cityblock')]
x_dist_F_iterable = [tensor_scan_fxns.x_dist_F('hamming')]
location_weight_iterable = np.linspace(0.2, 0.8, 4)
time_weight_iterable = np.linspace(0.2, 0.8, 4)
x_weight_iterable = np.linspace(0.2, 0.8, 4)
weights_iterable = itertools.starmap((lambda *args: (args[0]/sum(args), (args[1]/sum(args)), (args[2]/sum(args)))), itertools.product(location_weight_iterable, time_weight_iterable, x_weight_iterable))
datum_dist_F_iterable = itertools.starmap(tensor_scan_fxns.distance_F, itertools.imap(utils.flatten, itertools.product(weights_iterable, itertools.product(location_dist_F_iterable, time_dist_F_iterable, x_dist_F_iterable))))
linkage_iterable = ['single']
scratch_agglomerative_pattern_finder_f_iterable = itertools.starmap(tensor_scan_fxns.agglomerative_pattern_finder_F, itertools.product(datum_dist_F_iterable, linkage_iterable))
scratch pattern_finder
"""
lat_min, lat_max, lng_min, lng_max = crime_data.constants.cambridge_min_lat, crime_data.constants.cambridge_max_lat, crime_data.constants.cambridge_min_lng, crime_data.constants.cambridge_max_lng
num_lat, num_lng = 16, 16
regions_F = utils.latlng_grid_regions_F(num_lat, num_lng)
background_count_F = tensor_scan_fxns.region_x_independent_tensor_count_F(tensor_scan_fxns.bin_region_count_F(0.00001), tensor_scan_fxns.joint_x_distribution_F(utils.independent_categorical_joint_distribution_F()))
foreground_count_F = tensor_scan_fxns.empirical_tensor_count_F()
optimizer_F = utils.iterative_argmax_F(utils.get_initial_subset_x_random(1.0), utils.cycle_through_coord_iterative_step(), 10, 0.001)
p_value_F = tensor_scan_fxns.identity_test_stat_F()
pattern_F = tensor_scan_fxns.pattern_F(background_count_F, foreground_count_F, optimizer_F, tensor_scan_fxns.pattern_test_stat, p_value_F)
pattern_finder_regions_F = tensor_scan_fxns.background_and_foreground_regions_F(regions_F)
num_windows = 20
raw_pattern_finder_F = tensor_scan_fxns.raw_pattern_finder_F(tensor_scan_fxns.many_windows_iterator(num_windows), pattern_finder_regions_F, pattern_F)
scratch_oneshot_ranked_pattern_finder_F = tensor_scan_fxns.oneshot_ranked_pattern_finder_F(raw_pattern_finder_F)
scratch_pattern_finder_F = tensor_scan_fxns.most_significant_pattern_finder_F(raw_pattern_finder_F)
iterative_max_iter = 3
scratch_iterative_ranked_pattern_finder_F = tensor_scan_fxns.iterative_ranked_pattern_finder_F(iterative_max_iter, scratch_pattern_finder_F)

"""
scratch baseline_method
"""
location_dist_F = tensor_scan_fxns.location_dist_F('euclidean')
time_dist_F = tensor_scan_fxns.time_dist_F('cityblock')
x_dist_F = tensor_scan_fxns.x_dist_F('hamming')
location_weight = 0.05
time_weight = 0.9 
x_weight = 1.0 - (location_weight + time_weight)
datum_dist_F = tensor_scan_fxns.distance_F(location_weight, time_weight, x_weight, location_dist_F, time_dist_F, x_dist_F)
linkage = 'single'
scratch_agglomerative_pattern_finder_F = tensor_scan_fxns.agglomerative_pattern_finder_F(datum_dist_F, linkage)