def validation_test_features(self, data_set): output_list = [] for item in data_set: label = item[0] input = str(item[1]) local_feat_dict = {} discovered_features = [] discovered_features.extend(self.features_suffixes(input)) discovered_features.extend(self.features_words(input)) discovered_features.extend(self.features_special(input)) for f in discovered_features: if f in self.feature_dict: # if feature in global feat dict if f not in local_feat_dict: local_feat_dict[f] = 1 else: local_feat_dict[f] += 1 data_point = Data_Point() if label != '': data_point.true_label_index = self.label_dict[label] data_point.features_dict = local_feat_dict output_list.append(data_point) return output_list
def move(self, Data_Point): t0 = self.drone.location() max_Location = Data_Point.get_Location() max_Signal = Data_Point.get_Signal() direction_of_travel = [ max_Location[0] - t0[0], max_Location[1] - t0[1], max_Location[2] - t0[2] ] print( "\n\nDrone will move in %s --> %s direction and it is in %s location relative to its starting position" % (Data_Point.id, direction_of_travel, self.drone.location())) self.drone.moveFr(direction_of_travel[0] * 2) self.drone.moveRi(direction_of_travel[1] * 2) self.drone.moveUp(direction_of_travel[2] * 2) while (Signal(self.drone).calcSS() > max_Signal): max_Signal = Signal(self.drone).calcSS() self.drone.moveFr(direction_of_travel[0]) self.drone.moveRi(direction_of_travel[1]) self.drone.moveUp(direction_of_travel[2]) self.drone.moveFr(direction_of_travel[0] * -1) self.drone.moveRi(direction_of_travel[1] * -1) self.drone.moveUp(direction_of_travel[2] * -1)
def validation_test_features(self, data_set): output_list = [] for item in data_set: # for each item... # get data label = item[0] input = str(item[1]) local_feat_dict = {} # local dict to store features for each item input_list = list(input) # convert string to list of characters # find all n-grams of the string for i in range(0, len(input_list) - self.N + 1): s = input_list[i] if s == ' ': continue for j in range(1, self.N): if input_list[ j] == ' ': # stop when whitespace encountered break s = s + '' + input_list[i + j] if s in self.feature_dict: if s not in local_feat_dict: local_feat_dict[s] = 1 else: local_feat_dict[s] += 1 data_point = Data_Point() if label != '': data_point.true_label_index = self.label_dict[label] data_point.features_dict = local_feat_dict output_list.append(data_point) return output_list
def find_features_and_labels(self): data = self.data # vars global_feat_dict = {} global_feat_index = 0 label_dict = {} label_index = 0 for item in data: # for each item... # get data label = item[0] input = str(item[1]) local_feat_dict = {} # local dict to store features for each item input_list = list(input) # convert string to list of characters # find all n-grams of the string for i in range(0, len(input_list) - self.N + 1): s = input_list[i] if s == ' ': continue for j in range(1, self.N): if input_list[ j] == ' ': # stop when whitespace encountered break s = s + '' + input_list[i + j] if s not in local_feat_dict: local_feat_dict[s] = 1 else: local_feat_dict[s] += 1 if s not in global_feat_dict: global_feat_dict[s] = global_feat_index global_feat_index += 1 if label not in label_dict: label_dict[label] = label_index label_index += 1 data_point = Data_Point() data_point.true_label_index = label_dict[label] data_point.features_dict = local_feat_dict self.data_points_list.append(data_point) self.feature_dict = global_feat_dict self.label_dict = label_dict
def find_features_and_labels(self): """ """ data = self.data char_dict = {} char_index = 0 label_dict = { } # stores label and their corresponding index (i.e. drugs:0, company:1, ...) label_count = 0 # parse each character into a set for item in data: input = str(item[1]) input = re.sub(r'[^\w]', '', input) # remove spaces input_l = list(input) label = str(item[0]) input_char_dict = {} data_point = Data_Point() for c in input_l: if c not in input_char_dict: input_char_dict[c] = 1 # add char to 'local' char dict else: input_char_dict[c] += 1 if c not in char_dict: char_dict[ c] = char_index # add character to 'global' char dict char_index += 1 if label not in label_dict.keys(): label_dict[label] = label_count # also add to label dict label_count += 1 data_point.true_label_index = label_dict[ label] # TODO changed label to label_index data_point.features_dict = input_char_dict self.data_points_list.append(data_point) self.feature_dict = char_dict self.label_dict = label_dict
def find_features_and_labels(self): data = self.data global_feat_dict = {} global_feat_index = 0 label_dict = {} label_index = 0 for item in data: label = item[0] input = str(item[1]) local_feat_dict = {} discovered_features = [] discovered_features.extend(self.features_suffixes(input)) discovered_features.extend(self.features_words(input)) discovered_features.extend(self.features_special(input)) for f in discovered_features: if f not in local_feat_dict: local_feat_dict[f] = 1 else: local_feat_dict[f] += 1 if f not in global_feat_dict: global_feat_dict[f] = global_feat_index global_feat_index += 1 if label not in label_dict: label_dict[label] = label_index label_index += 1 data_point = Data_Point() data_point.true_label_index = label_dict[label] data_point.features_dict = local_feat_dict self.data_points_list.append(data_point) self.feature_dict = global_feat_dict self.label_dict = label_dict
def validation_test_features(self, data_set): output_list = [] for item in data_set: input = str(item[1]) input = re.sub(r'[^\w]', '', input) # remove spaces input_l = list(input) label = str(item[0]) input_char_dict = {} data_point = Data_Point() for c in input_l: if c in self.feature_dict: if c not in input_char_dict: input_char_dict[c] = 1 else: input_char_dict[c] += 1 data_point.features_dict = input_char_dict if label != '': data_point.true_label_index = self.label_dict[label] output_list.append(data_point) return output_list
def Box_mission(self): box_plots = [] box_plots.append( Data_Point("T0", self.drone.x, self.drone.y, self.drone.z, Signal(self.drone).calcSS())) self.drone.moveFr(self.length_of_box / 2) box_plots.append( Data_Point("T1", self.drone.x, self.drone.y, self.drone.z, Signal(self.drone).calcSS())) self.drone.moveRi((self.length_of_box / 2) * -1) box_plots.append( Data_Point("T2", self.drone.x, self.drone.y, self.drone.z, Signal(self.drone).calcSS())) self.drone.moveFr((self.length_of_box / 2) * -1) box_plots.append( Data_Point("T3", self.drone.x, self.drone.y, self.drone.z, Signal(self.drone).calcSS())) self.drone.moveFr((self.length_of_box / 2) * -1) box_plots.append( Data_Point("T4", self.drone.x, self.drone.y, self.drone.z, Signal(self.drone).calcSS())) self.drone.moveRi(self.length_of_box / 2) box_plots.append( Data_Point("T5", self.drone.x, self.drone.y, self.drone.z, Signal(self.drone).calcSS())) self.drone.moveRi(self.length_of_box / 2) box_plots.append( Data_Point("T6", self.drone.x, self.drone.y, self.drone.z, Signal(self.drone).calcSS())) self.drone.moveFr(self.length_of_box / 2) box_plots.append( Data_Point("T7", self.drone.x, self.drone.y, self.drone.z, Signal(self.drone).calcSS())) self.drone.moveFr(self.length_of_box / 2) box_plots.append( Data_Point("T8", self.drone.x, self.drone.y, self.drone.z, Signal(self.drone).calcSS())) self.drone.moveRi((self.length_of_box / 2) * -1) self.drone.moveFr((self.length_of_box / 2) * -1) return box_plots
def __combine_data_points_list(self, data_point_list1, data_point_list2): """ combines 2 models' data_points_list's item parameters. """ output_list = [] # combine data point attributes for i in range(0, len(data_point_list1)): data_point = Data_Point() local_features_1 = data_point_list1[i].features_dict local_features_2 = data_point_list2[i].features_dict # populate local_features with {feature: count} for key1, val1 in local_features_1.items(): data_point.features_dict[key1] = val1 for key2, val2 in local_features_2.items(): if key2 not in data_point.features_dict: data_point.features_dict[key2] = val2 data_point.true_label_index = data_point_list1[i].true_label_index data_point.index = i output_list.append(data_point) return output_list