def load_data(self): # size_list = [] for data_file in self.click_data_files: data_handel = PickleUtil(data_file) click_dict = data_handel.safe_load() # size_list += [len(click_dict["click time list"])] self.rel_click_data += [click[0] for click in click_dict["click time list"]] self.rel_click_data = np.array(self.rel_click_data) # size_list_2 = [] for data_file in self.click_context_files: data_handel = PickleUtil(data_file) context_dict = data_handel.safe_load() self.abs_click_data += context_dict["press"] # size_list_2 += [len(flatten(context_dict["press"]))] self.speed_changes += context_dict["speed"] self.selection_data += context_dict["choice"] self.abs_click_data = np.array(flatten(self.abs_click_data)) self.speed_changes.sort(key=lambda x: x[0]) if self.preconfig_file is not None: preconfig_handel = PickleUtil(self.preconfig_file) preconfig = preconfig_handel.safe_load() self.kde_list = np.array(preconfig["li"])/np.sum(preconfig["li"]) if len(self.abs_click_data) != len(self.rel_click_data): raise ValueError("Click data length does not match context data length!") print("Loaded " + str(len(self.abs_click_data)) + " clicks")
def save_simulation_data(self, attribute=None): data_file = os.path.join(self.data_loc, "npred_"+str(self.N_pred)+"_nwords_"+str(self.num_words_total)+"_lcon_" +str(int(self.lm_left_context))+"_wdiff_"+str(round(np.exp(self.win_diff_base))) +"_rot_"+str(self.rotate_index)+"_cor_"+str(self.easy_phrase)+"_fp_" +str(self.false_positive_rate)+".p") data_handel = PickleUtil(data_file) dist_id_file = os.path.join(self.data_loc, "dist_id.p") dist_id_handel = PickleUtil(dist_id_file) dist_id_handel.safe_save(self.click_dist) data_dict = dict() data_dict["N_pred"] = self.N_pred data_dict["prob_thresh"] = self.prob_thres data_dict["win_diff"] = self.win_diff_base data_dict["num_words"] = self.num_words_total data_dict["time_rotate"] = self.time_rotate data_dict["false_positive"] = self.false_positive_rate data_dict["errors"] = self.error_rate_avg data_dict["selections"] = self.sel_per_min data_dict["characters"] = self.char_per_min data_dict["presses_sel"] = self.press_per_sel data_dict["presses_char"] = self.press_per_char data_dict["presses_word"] = self.press_per_word data_dict["kde_mses"] = self.kde_errors_avg data_dict["kde"] = self.bc.get_histogram() data_dict["kde"] = self.bc.get_histogram() if attribute is not None: data_dict["attribute"] = attribute data_handel.safe_save(data_dict)
def main(): click_dist = PickleUtil("simulations/param_opt/click_distributions/wwm_hist.p").safe_load() dp_dist = PickleUtil("simulations/param_opt/dp_distributions/wwm_dp_kernel.p").safe_load() # click_dist = click_dist(np.arange(80)) # click_dist /= np.sum(click_dist) # plt.plot(click_dist) # plt.show() sim = SimulatedUser() params = {"N_pred": 3, "num_words": 10, "time_rotate": 0, "click_dist": click_dist, "dp_dist": dp_dist} sim.parameter_metrics(params, num_clicks=500, trials=1)
def get_prev_data(self): if self.parent.is_write_data: self.prev_data_path = self.parent.data_handel + "\\preconfig.p" print("USER ID is" + str(self.parent.user_id)) load_dict = PickleUtil(self.prev_data_path).safe_load() if load_dict != None: self.clock_inf.kde.get_past_dens_li(load_dict)
def load_data(self): data_by_user = dict() for path, dir, files in os.walk(self.data_directory): user_dir = path[(len(self.data_directory) + 1):] if user_dir is not "": if len(files) > 0: user_data = dict() for file in files: file_data = PickleUtil(os.path.join(path, file)).safe_load() if "dist_id" in file: user_data["click_dist"] = file_data continue else: data_value_names = { 'errors', 'selections', 'characters', 'presses_sel', 'presses_char', 'presses_word', 'kde_mses', 'kde' } self.param_names = set( file_data.keys()) - data_value_names params = tuple(file_data[name] for name in self.param_names) # print(self.param_names) # print(params) user_data[params] = file_data data_by_user[int(user_dir)] = user_data return data_by_user
def save_hist(self): # kernel = stats.gaussian_kde(self.rel_click_data) # rel_click_data hist = self.kde_list time_rotate = self.speed_changes[-1][-1] x_range = (np.arange(80) - 40) / 80 * time_rotate print(os.path.join(self.data_dir, "user_histogram.p")) PickleUtil(os.path.join(self.data_dir, "user_histogram.p")).safe_save( (x_range, hist))
def __init__(self): self.click_dists = [PickleUtil(os.path.join("simulations/false_positive/click_distributions", file)).safe_load() for file in os.listdir("simulations/false_positive/click_distributions")] self.false_positives = np.arange(0, 0.2, 0.02) self.parameters_list = [] self.parameters_dict = dict()
def __init__(self): self.click_dists = [ PickleUtil( os.path.join("simulations/param_opt/click_distributions", file)).safe_load() for file in os.listdir("simulations/param_opt/click_distributions") ] self.dp_dists = [ PickleUtil( os.path.join("simulations/param_opt/dp_distributions", file)).safe_load() for file in os.listdir("simulations/param_opt/dp_distributions") ] self.period_li = np.arange(0, 21, 1) self.parameters_list = []
def __init__(self): print(os.listdir("simulations/param_opt/click_distributions")) self.click_dists = [ PickleUtil( os.path.join("simulations/param_opt/click_distributions", file)).safe_load() for file in os.listdir("simulations/param_opt/click_distributions") ] self.dp_dists = [ PickleUtil( os.path.join("simulations/param_opt/dp_distributions", file)).safe_load() for file in os.listdir("simulations/param_opt/dp_distributions") ] self.n_pred_range = [1, 2, 3] self.parameters_list = []
def save_data(self): user_preferences = [ self.key_config, self.speed, self.pause_index, self.is_write_data ] self.up_handel.safe_save(user_preferences) self.click_data_path = os.path.join( self.data_handel, 'click_time_log_' + str(self.use_num) + '.p') self.params_data_path = os.path.join( self.data_handel, 'params_data_use_num' + str(self.use_num) + '.p') print(self.params_data_path) PickleUtil(self.click_data_path).safe_save({ 'user id': self.user_id, 'use_num': self.use_num, 'click time list': self.click_time_list, 'rotate index': self.speed }) PickleUtil(self.params_data_path).safe_save(self.params_handle_dict)
def gen_handle(self): handle_name = "data\\" + str(self.user_num) if 'data' not in os.listdir(): os.mkdir("data") os.mkdir(handle_name) if str(self.user_num) not in os.listdir("data"): os.mkdir(handle_name) self.data_handel_rxn = PickleUtil(handle_name + "\\rxn_times.p") self.data_handel_dpt = PickleUtil(handle_name + "\\dp_times.p") self.reaction_times = self.data_handel_rxn.safe_load() if self.reaction_times is None: self.reaction_times = [] print("Loaded ", len(self.reaction_times), "rxn clicks") self.double_press_times = self.data_handel_dpt.safe_load() if self.double_press_times is None: self.double_press_times = [] print("Loaded ", len(self.double_press_times), "dpt clicks")
def save_when_quit_noconsent(self): if self.parent.is_write_data: PickleUtil(self.click_data_path).safe_save({ 'user id': self.parent.user_id, 'use_num': self.parent.use_num, 'click time list': [], 'rotate index': self.parent.rotate_index })
def save_when_quit(self): user_preferences = self.parent.clock_type, self.parent.font_scale, self.parent.high_contrast, \ self.parent.layout_preference, self.parent.pf_preference, self.parent.rotate_index, \ self.parent.is_write_data self.parent.up_handel.safe_save(user_preferences) self.prev_data_path = os.path.join(self.parent.data_handel, 'preconfig.p') self.click_data_path = os.path.join( self.parent.data_handel, 'click_time_log_' + str(self.parent.use_num) + '.p') self.params_data_path = os.path.join( self.parent.data_handel, 'params_data_use_num' + str(self.parent.use_num) + '.p') print(self.params_data_path) PickleUtil(self.click_data_path).safe_save({ 'user id': self.parent.user_id, 'use_num': self.parent.use_num, 'click time list': self.click_time_list, 'rotate index': self.parent.rotate_index }) PickleUtil(self.prev_data_path).safe_save({ 'li': self.clock_inf.kde.dens_li, 'z': self.clock_inf.kde.Z, 'opt_sig': self.clock_inf.kde.ksigma, 'y_li': self.clock_inf.kde.y_li, 'yksigma': self.clock_inf.kde.y_ksigma }) PickleUtil(self.params_data_path).safe_save( self.parent.params_handle_dict)
def order_data(dir): click_dists = [] if not os.path.exists(os.path.join(dir, "ordered_data")): os.mkdir(os.path.join(dir, "ordered_data")) for path, __, files in os.walk(dir): for file in files: if "dist_id" in file: click_dist = PickleUtil(os.path.join(path, file)).safe_load() if click_dist not in click_dists: click_dists += [click_dist] # os.mkdir(os.path.join(dir, os.path.join("ordered_data", str(click_dists.index(click_dist))))) print(path) plt.plot(click_dist) plt.show()
def plot_click_recovery(self): click_locations = [click[1] for click in self.full_click_data] # print(click_locations) click_pairs = [] abs_click_pairs = [] index = 0 while index < len(click_locations): cur_click = click_locations[index] abs_cur_click = self.abs_click_data[index] if cur_click[1] == -1: # row scan if len(click_pairs) == 0: click_pairs.append([cur_click]) abs_click_pairs.append([abs_cur_click]) elif len(click_pairs[-1]) == 1: click_pairs = click_pairs[:-1] abs_click_pairs = abs_click_pairs[:-1] else: click_pairs.append([cur_click]) abs_click_pairs.append([abs_cur_click]) else: if len(click_pairs[-1]) == 1: click_pairs[-1].append(cur_click) abs_click_pairs[-1].append(abs_cur_click) index += 1 click_diffs = np.array( [pair[1] - pair[0] for pair in abs_click_pairs if len(pair) == 2]) pair_orders = np.array( [pair[1][1] for pair in click_pairs if len(pair) == 2]) recovery_times = click_diffs[np.where(pair_orders == 0)] recovery_times = recovery_times[np.where(recovery_times <= 3)] plt.hist(recovery_times, bins=20) PickleUtil("recovery_time_951.p").safe_save(recovery_times) # plt.show() # plt.hist(pair_orders, bins=8) plt.xlabel("time (s)") plt.ylabel("count") plt.title("Recovery Time") plt.show()
def gen_data_dir(self): if self.job_num is not None: if not os.path.exists(os.path.join(self.working_dir, "sim_data")): try: os.mkdir(os.path.join(self.working_dir, "sim_data")) except FileExistsError: pass if not os.path.exists(os.path.join(os.path.join(self.working_dir, "sim_data"), str(self.job_num))): try: os.mkdir(os.path.join(os.path.join(self.working_dir, "sim_data"), str(self.job_num))) except FileExistsError: pass self.data_loc = os.path.join(os.path.join(self.working_dir, "sim_data"), str(self.job_num)) else: dist_found = False highest_user_num = 0 if not os.path.exists(os.path.join(self.working_dir, "sim_data")): try: os.mkdir(os.path.join(self.working_dir, "sim_data")) except FileExistsError: pass for path, dir, files in os.walk(os.path.join(self.working_dir, "sim_data")): highest_user_num = max(max([0]+[int(d) for d in dir]), highest_user_num) for file in files: if "dist_id" in file: file_handel = PickleUtil(os.path.join(path, file)) dist_id = file_handel.safe_load() if np.sum(np.array(dist_id) - np.array(self.click_dist)) == 0: dist_found = True self.data_loc = path if not dist_found: try: os.mkdir(os.path.join(os.path.join(self.working_dir, "sim_data"), str(highest_user_num+1))) except FileExistsError: pass self.data_loc = os.path.join(os.path.join(self.working_dir, "sim_data"), str(highest_user_num+1))
def save_simulation_data(self, attribute=None): if attribute is not None: data_file = os.path.join( self.data_loc, "sorted_" + str(int(self.key_config == "sorted")) + "_nwords_" + str(self.num_word_preds) + "_wf_" + str(int(self.words_first)) + "_delay_" + str(round(self.start_scan_delay, 2)) + "_scan_" + str(self.scanning_delay) + "_atr_" + str(attribute) + "_fp_" + str(self.false_positive_rate) + ".p") else: data_file = os.path.join( self.data_loc, "sorted_" + str(int(self.key_config == "sorted")) + "_nwords_" + str(self.num_word_preds) + "_wf_" + str(int(self.words_first)) + "_delay_" + str(round(self.start_scan_delay, 2)) + "_cor_" + str(self.easy_phrase) + "_scan_" + str(self.scanning_delay) + "_fp_" + str(self.false_positive_rate) + ".p") data_handel = PickleUtil(data_file) data_dict = dict() data_dict["order"] = self.key_config data_dict["words_first"] = self.words_first data_dict["num_words"] = self.num_word_preds data_dict["delay"] = self.start_scan_delay data_dict["scan_delay"] = self.scanning_delay data_dict["easy_corpus"] = self.easy_phrase data_dict["false_positive"] = self.false_positive_rate data_dict["errors"] = self.error_rate_avg data_dict["selections"] = self.sel_per_min data_dict["characters"] = self.char_per_min data_dict["presses_char"] = self.press_per_char data_dict["presses_word"] = self.press_per_word if attribute is not None: data_dict["attribute"] = attribute data_handel.safe_save(data_dict)
def get_click_data(self): if self.parent.is_write_data: self.click_data_path = self.parent.data_handel + "\\click_time_log_" + str( self.parent.use_num - 1) + ".p" load_click = PickleUtil(self.click_data_path).safe_load() self.click_time_list = [] if load_click != None: try: if load_click.has_key('user id') and load_click.has_key( 'use_num') and load_click.has_key('rotate index'): if load_click['user id'] == self.parent.user_id: self.click_time_list = load_click[ 'click time list'] # self.parent.use_num = load_click['use_num'] +1 self.parent.rotate_index = load_click[ 'rotate index'] return except: pass self.parent.rotate_index = config.default_rotate_ind return
def save_when_quit(self): if self.clock_inf.calc_density_called: if self.parent.sister.user_cal_num == 0 and self.parent.sister.use_num == 0: new_cal_dir = self.parent.sister.data_handel else: new_cal_dir = self.parent.sister.user_handel + "\\cal" + str( self.parent.sister.user_cal_num + 1) self.parent.sister.data_handel = new_cal_dir self.parent.sister.user_cal_num += 1 os.mkdir(new_cal_dir) self.parent.sister.use_num = 0 self.pretrain_data_path = new_cal_dir + "\\preconfig.p" PickleUtil(self.pretrain_data_path).safe_save({ 'li': self.clock_inf.kde.dens_li, 'z': self.clock_inf.kde.Z, 'opt_sig': self.clock_inf.kde.ksigma, 'y_li': [], 'yksigma': self.clock_inf.kde.y_ksigma })
sys.path.insert(0, parentdir) os.chdir(parentdir) from simulated_user import SimulatedUser, normal_hist from pickle_util import PickleUtil try: my_task_id = int(sys.argv[1]) num_tasks = int(sys.argv[2]) except IndexError: my_task_id = 4 num_tasks = 24 parameters_list = [] click_dists = [ PickleUtil(os.path.join("simulations/param_opt/click_distributions", file)).safe_load() for file in os.listdir("simulations/param_opt/click_distributions") ] wd_range = np.arange(10, 130, 5) print(wd_range) for click_dist in click_dists: click_dist = click_dist / np.sum(click_dist) param_dict = {} param_dict["click_dist"] = click_dist.tolist() for wd in wd_range: param_dict["N_pred"] = 3 param_dict["num_words"] = 17 param_dict["win_diff"] = np.log(wd) parameters_list += [param_dict.copy()]
def __init__(self, screen_res, app): super(Keyboard, self).__init__(screen_res) self.app = app self.is_simulation = False self.pretrain_window = False # 2 is turn fully on, 1 is turn on but reduce, 0 is turn off self.word_pred_on = 2 # Number of word clocks to display in case word prediction == 1 (reduced) self.reduce_display = 5 # get user data before initialization self.gen_data_handel() self.up_handel = PickleUtil( os.path.join(self.user_handel, 'user_preferences.p')) user_preferences = self.up_handel.safe_load() if user_preferences is None: first_load = True user_preferences = [ 'default', 1, False, 'alpha', 'off', config.default_rotate_ind, True ] self.up_handel.safe_save(user_preferences) else: first_load = False self.clock_type, self.font_scale, self.high_contrast, self.layout_preference, self.pf_preference, \ self.start_speed, self.is_write_data = user_preferences self.phrase_prompts = False # set to true for data collection mode if self.phrase_prompts: self.phrases = Phrases( "resources/twitter-phrases/watch-combined.txt") else: self.phrases = None if self.layout_preference == 'alpha': self.target_layout = kconfig.alpha_target_layout self.key_chars = kconfig.key_chars elif self.layout_preference == 'qwerty': self.target_layout = kconfig.qwerty_target_layout self.key_chars = kconfig.key_chars elif self.layout_preference == 'emoji': self.target_layout = kconfig.emoji_target_layout self.key_chars = kconfig.emoji_keys self.word_pred_on = 0 # set up dictionary tree # splash = StartWindow(screen_res, True) self.pause_animation = False self.output_manager = outputManager() self.is_output_text = False self.lm_prefix = "" self.left_context = "" self.cwd = os.getcwd() word_lm_path = os.path.join( os.path.join(self.cwd, 'resources'), 'mix4_opt_min_lower_100k_4gram_2.5e-9_prob8_bo4_compress255.kenlm') char_lm_path = os.path.join( os.path.join(self.cwd, 'resources'), 'mix4_opt_min_lower_12gram_6e-9_prob9_bo4_compress255.kenlm') vocab_path = os.path.join(os.path.join(self.cwd, 'resources'), 'vocab_lower_100k.txt') char_path = os.path.join(os.path.join(self.cwd, 'resources'), 'char_set.txt') self.lm = LanguageModel(word_lm_path, char_lm_path, vocab_path, char_path) # initialize pygame and joystick if kconfig.target_evt is kconfig.joy_evt: pygame.init() if pygame.joystick.get_count() < 1: # no joysticks found print("Please connect a joystick.\n") self.quit(None) else: # create a new joystick object from # ---the first joystick in the list of joysticks Joy0 = pygame.joystick.Joystick(0) # tell pygame to record joystick events Joy0.init() # start looking for events self.parent.after(0, self.find_events) # not in selection pause self.in_pause = False # determine keyboard positions self.init_locs() # get old data if there is such # Just for default. Loaded again when bc initializes self.rotate_index = config.default_rotate_ind # set up file handle for printing useful stuff self.undefined = False self.params_handle_dict = { 'speed': [], 'params': [], 'start': [], 'press': [], 'choice': [] } self.num_presses = 0 self.params_handle_dict['params'].append( [config.period_li[config.default_rotate_ind], config.theta0]) self.params_handle_dict['start'].append(time.time()) self.gen_scale() self.pause_set = True # set up "typed" text self.typed = "" self.btyped = "" self.context = "" self.old_context_li = [""] self.last_add_li = [0] # set up "talked" text # self.talk_file = "talk.txt" self.sound_set = True self.press_lock = False self.press_lock_status = False # check for speech # talk_fid = open(self.talk_file, 'wb') # write words self.init_words() self.bars = kconfig.bars self.bc_init = False self.previous_undo_text = '' self.previous_winner = 0 self.wpm_data = [] self.decay_avg_wpm = 0 self.wpm_time = 0 self.error_data = [] self.decay_avg_error = 1 self.clear_text = False self.pretrain = False self.emoji_box_highlight = [-1, -1] self.init_ui() self.mainWidget.clockgrid_widget.update_word_clocks(self.words_li) sound_file = "icons/bell.wav" self.sound_player = QtMultimedia.QSound(sound_file) self.time_rotate = config.period_li[self.start_speed] # get language model results self.gen_word_prior(False) self.clock_spaces = np.zeros((len(self.clock_centers), 2)) self.bc = BroderClocks(self) self.mainWidget.change_value(self.start_speed) self.bc.init_follow_up(self.word_score_prior) # draw histogram self.init_histogram() self.save_environment() self.consent = False if first_load: self.pretrain = True self.welcome = Pretraining(self, screen_res) # animate # record to prevent double tap self.last_key_press_time = time.time() self.last_release_time = time.time() self.update_radii = False self.on_timer()
def __init__(self, cwd=os.getcwd(), job_num=None, sub_call=False): self.job_num = job_num self.key_chars = kconfig.key_chars self.key_chars_sorted = kconfig.key_chars_sorted if not sub_call: self.key_config = "sorted" # self.key_config = "default" self.num_word_preds = 7 self.words_first = True # self.words_first = False self.speed = config.default_rotate_ind self.scanning_delay = config.period_li[self.speed] self.start_scan_delay = config.pause_li[config.default_pause_ind] self.reaction_delay = 0 self.kernel_handle = PickleUtil("resources/kde_kernel.p") self.kde_kernel = self.kernel_handle.safe_load() self.phrases = Phrases("resources/comm2.dev") self.false_positive_rate = 0.01 self.num_fp = 0 self.sound_set = True self.pause_set = True self.lm_prefix = "" self.left_context = "" self.typed_versions = [""] self.cwd = cwd self.working_dir = cwd self.gen_data_dir() self.time = Time(self) self.prev_time = 0 self.num_presses = 0 self.last_press_time = self.time.time() self.last_update_time = self.time.time() lm_path = os.path.join(os.path.join(self.cwd, 'resources'), 'lm_word_medium.kenlm') vocab_path = os.path.join(os.path.join(self.cwd, 'resources'), 'vocab_100k') self.lm = LanguageModel(lm_path, vocab_path) self.phrase_prompts = True # determine keyboard positions # set up file handle for printing useful stuff # set up "typed" text self.typed = "" self.context = "" self.old_context_li = [""] self.last_add_li = [0] # set up "talked" text # check for speech # talk_fid = open(self.talk_file, 'wb') # write words self.row_scan = True self.row_scan_num = -2 self.col_scan = False self.col_scan_num = -1 self.draw_words() self.generate_layout() self.update_layout() self.generate_timing_map()
def __init__(self, screen_res, app): super(Keyboard, self).__init__(screen_res) self.app = app self.font_scale = 1 self.key_chars = kconfig.key_chars self.key_chars_sorted = kconfig.key_chars_sorted self.key_config = "sorted" # self.key_config = "default" self.num_words = 7 self.words_first = True # self.words_first = False self.sound_set = True self.pause_set = True self.lm_prefix = "" self.left_context = "" self.typed_versions = [""] self.cwd = os.getcwd() self.gen_data_handel() self.up_handel = PickleUtil( os.path.join(self.user_handel, 'user_preferences.p')) user_preferences = self.up_handel.safe_load() if user_preferences is None: user_preferences = [ 'sorted', config.default_rotate_ind, config.default_pause_ind, True ] self.up_handel.safe_save(user_preferences) self.key_config, self.speed, self.pause_index, self.is_write_data = user_preferences self.scanning_delay = config.period_li[self.speed] self.extra_delay = config.pause_li[self.pause_index] self.params_handle_dict = { 'speed': [], 'extra_delay': [], 'params': [], 'start': [], 'press': [], 'choice': [] } self.num_presses = 0 self.last_press_time = time.time() self.last_update_time = time.time() self.next_frame_time = time.time() self.params_handle_dict['params'].append( [config.period_li[config.default_rotate_ind], config.theta0]) self.params_handle_dict['start'].append(time.time()) self.click_time_list = [] lm_path = os.path.join(os.path.join(self.cwd, 'resources'), 'lm_word_medium.kenlm') vocab_path = os.path.join(os.path.join(self.cwd, 'resources'), 'vocab_100k') self.lm = LanguageModel(lm_path, vocab_path) self.phrase_prompts = False if self.phrase_prompts: self.phrases = Phrases("resources/comm2.dev") else: self.phrases = None # determine keyboard positions # set up file handle for printing useful stuff # set up "typed" text self.typed = "" self.context = "" self.old_context_li = [""] self.last_add_li = [0] # set up "talked" text # check for speech # talk_fid = open(self.talk_file, 'wb') # write words self.generate_layout() self.draw_words() self.wpm_data = [] self.decay_avg_wpm = 0 self.wpm_time = 0 self.error_data = [] self.decay_avg_error = 1 self.row_scan = True self.row_scan_num = -2 self.col_scan = False self.col_scan_num = -1 self.init_ui() # animate self.on_timer()
parentdir = os.path.dirname(parentdir) os.chdir(parentdir) sys.path.append(parentdir) from simulated_user import SimulatedUser from pickle_util import PickleUtil try: my_task_id = int(sys.argv[1]) num_tasks = int(sys.argv[2]) except IndexError: my_task_id = 1 num_tasks = 20 click_dists = [ PickleUtil(os.path.join("simulations/scan_delay/click_distributions", file)).safe_load() for file in os.listdir("simulations/scan_delay/click_distributions") ] period_li = np.arange(21) period_li = 3 * np.exp((-period_li) / 12) parameters_list = [] parameters_dict = dict() for period_num, period in enumerate(period_li): param_dict = dict() parameters_dict["scan_delay"] = period_num parameters_dict["order"] = "sorted" parameters_dict["words_first"] = True parameters_dict["num_words"] = 7
def gen_kernel(self): kernel = stats.gaussian_kde(self.rel_click_data) kernel_handle = PickleUtil("resources\\kde_kernel.p") kernel_handle.safe_save(kernel)
os.chdir(parentdir) sys.path.append(parentdir) from simulated_user import SimulatedUser from pickle_util import PickleUtil try: my_task_id = int(sys.argv[1]) num_tasks = int(sys.argv[2]) except IndexError: my_task_id = 1 num_tasks = 1 click_dists = [ PickleUtil( os.path.join("simulations/phrase_corpus/click_distributions", file)).safe_load() for file in os.listdir("simulations/phrase_corpus/click_distributions") ] parameters_list = [] parameters_dict = dict() corpora = ["resources/twitter-phrases/twitter-oov.txt", "resources/comm2.dev"] for dist in click_dists: for corpus in corpora: param_dict = dict() parameters_dict["scan_delay"] = 16 parameters_dict["order"] = "sorted" parameters_dict["words_first"] = True parameters_dict["num_words"] = 7
from matplotlib import pyplot as plt from pickle_util import PickleUtil import seaborn as sns import numpy as np from scipy import stats data_file = "data/2001/rxn_times.p" reaction_data = PickleUtil(data_file).safe_load() reaction_data = np.array(reaction_data) * 1000 reaction_data = reaction_data[np.where(reaction_data < 2000)] palette = sns.cubehelix_palette(2, start=-4.5, rot=2.4, dark=0.6, light=0.7, reverse=True) sns.set_palette(palette) sns.distplot(reaction_data, kde=False, fit=stats.exponnorm, label="High SRT") mean = np.mean(reaction_data) plt.axvline(mean, color="steelblue", label="High Mean SRT ("+str(int(mean))+"ms)") data_file = "data/0/rxn_times.p" reaction_data = PickleUtil(data_file).safe_load() reaction_data = np.array(reaction_data) * 1000 reaction_data = reaction_data[np.where(reaction_data < 2000)] sns.distplot(reaction_data, kde=False, fit=stats.exponnorm, label="Not High") mean = np.mean(reaction_data) plt.axvline(mean, color="rosybrown", label="Not High Mean SRT ("+str(int(mean))+"ms)") plt.legend() plt.show()