def create_shot_list_tmp(original_shot,time_points,sigs=None): shot_list_tmp = ShotList() T = len(original_shot.ttd) t_range = np.linspace(0,T-1,time_points,dtype=np.int) for t in t_range: new_shot = copy.copy(original_shot) assert(new_shot.augmentation_fn == None) new_shot.augmentation_fn = partial(hide_signal_data,t = t,sigs_to_hide=sigs) #new_shot.number = original_shot.number shot_list_tmp.append(new_shot) return shot_list_tmp,t_range
def apply_bleed_in(conf,shot_list_train,shot_list_validate,shot_list_test): np.random.seed(2) num = conf['data']['bleed_in'] new_shots = [] if num > 0: shot_list_bleed = ShotList() print('applying bleed in with {} disruptive shots\n'.format(num)) num_total = len(shot_list_test) num_d = shot_list_test.num_disruptive() num_nd = num_total - num_d assert(num_d >= num), "Not enough disruptive shots {} to cover bleed in {}".format(num_d,num) num_sampled_d = 0 num_sampled_nd = 0 while num_sampled_d < num: s = shot_list_test.sample_shot() shot_list_bleed.append(s) if conf['data']['bleed_in_remove_from_test']: shot_list_test.remove(s) if s.is_disruptive: num_sampled_d += 1 else: num_sampled_nd += 1 print("Sampled {} shots, {} disruptive, {} nondisruptive".format(num_sampled_nd+num_sampled_d,num_sampled_d,num_sampled_nd)) print("Before adding: training shots: {} validation shots: {}".format(len(shot_list_train),len(shot_list_validate))) assert(num_sampled_d == num) if conf['data']['bleed_in_equalize_sets']:#add bleed-in shots to training and validation set repeatedly print("Applying equalized bleed in") for shot_list_curr in [shot_list_train,shot_list_validate]: for i in range(len(shot_list_curr)): s = shot_list_bleed.sample_shot() shot_list_curr.append(s) elif conf['data']['bleed_in_repeat_fac'] > 1: repeat_fac = conf['data']['bleed_in_repeat_fac'] print("Applying bleed in with repeat factor {}".format(repeat_fac)) num_to_sample = int(round(repeat_fac*len(shot_list_bleed))) for i in range(num_to_sample): s = shot_list_bleed.sample_shot() shot_list_train.append(s) shot_list_validate.append(s) else: #add each shot only once print("Applying bleed in without repetition") for s in shot_list_bleed: shot_list_train.append(s) shot_list_validate.append(s) print("After adding: training shots: {} validation shots: {}".format(len(shot_list_train),len(shot_list_validate))) print("Added bleed in shots to training and validation sets") # if num_d > 0: # for i in range(num): # s = shot_list_test.sample_single_class(True) # shot_list_train.append(s) # shot_list_validate.append(s) # if conf['data']['bleed_in_remove_from_test']: # shot_list_test.remove(s) # else: # print('No disruptive shots in test set, omitting bleed in') # if num_nd > 0: # for i in range(num): # s = shot_list_test.sample_single_class(False) # shot_list_train.append(s) # shot_list_validate.append(s) # if conf['data']['bleed_in_remove_from_test']: # shot_list_test.remove(s) # else: # print('No nondisruptive shots in test set, omitting bleed in') return shot_list_train,shot_list_validate,shot_list_test
def apply_bleed_in(conf, shot_list_train, shot_list_validate, shot_list_test): np.random.seed(2) num = conf['data']['bleed_in'] # new_shots = [] if num > 0: shot_list_bleed = ShotList() print('applying bleed in with {} disruptive shots\n'.format(num)) # num_total = len(shot_list_test) num_d = shot_list_test.num_disruptive() # num_nd = num_total - num_d assert num_d >= num, ( "Not enough disruptive shots {} to cover bleed in {}".format( num_d, num)) num_sampled_d = 0 num_sampled_nd = 0 while num_sampled_d < num: s = shot_list_test.sample_shot() shot_list_bleed.append(s) if conf['data']['bleed_in_remove_from_test']: shot_list_test.remove(s) if s.is_disruptive: num_sampled_d += 1 else: num_sampled_nd += 1 print("Sampled {} shots, {} disruptive, {} nondisruptive".format( num_sampled_nd + num_sampled_d, num_sampled_d, num_sampled_nd)) print("Before adding: training shots: {} validation shots: {}".format( len(shot_list_train), len(shot_list_validate))) assert (num_sampled_d == num) # add bleed-in shots to training and validation set repeatedly if conf['data']['bleed_in_equalize_sets']: print("Applying equalized bleed in") for shot_list_curr in [shot_list_train, shot_list_validate]: for i in range(len(shot_list_curr)): s = shot_list_bleed.sample_shot() shot_list_curr.append(s) elif conf['data']['bleed_in_repeat_fac'] > 1: repeat_fac = conf['data']['bleed_in_repeat_fac'] print("Applying bleed in with repeat factor {}".format(repeat_fac)) num_to_sample = int(round(repeat_fac * len(shot_list_bleed))) for i in range(num_to_sample): s = shot_list_bleed.sample_shot() shot_list_train.append(s) shot_list_validate.append(s) else: # add each shot only once print("Applying bleed in without repetition") for s in shot_list_bleed: shot_list_train.append(s) shot_list_validate.append(s) print("After adding: training shots: {} validation shots: {}".format( len(shot_list_train), len(shot_list_validate))) print("Added bleed in shots to training and validation sets") # if num_d > 0: # for i in range(num): # s = shot_list_test.sample_single_class(True) # shot_list_train.append(s) # shot_list_validate.append(s) # if conf['data']['bleed_in_remove_from_test']: # shot_list_test.remove(s) # else: # print('No disruptive shots in test set, omitting bleed in') # if num_nd > 0: # for i in range(num): # s = shot_list_test.sample_single_class(False) # shot_list_train.append(s) # shot_list_validate.append(s) # if conf['data']['bleed_in_remove_from_test']: # shot_list_test.remove(s) # else: # print('No nondisruptive shots in test set, omitting bleed in') return shot_list_train, shot_list_validate, shot_list_test