示例#1
0
 def convert_to_tuple(self, object, fields):
     values = []
     for field in fields:
         value = object
         for attr in field:
             value = getvalue(value, attr)
         values.append(value)
     return tuple(values)
示例#2
0
 def apply(self, objects):
     strings = []
     for object in objects:
         string = ""
         for distinct in self:
             string += getvalue(object, distinct.field, returnIfNone="")
             if string in strings:
                 objects.remove(object)
             else:
                 strings.append(string)
     return objects
示例#3
0
 def apply(self, objects):
     strings = []
     for object in objects:
         string = ''
         for distinct in self:
             string += getvalue(object, distinct.field, returnIfNone='')
             if string in strings:
                 objects.remove(object)
             else:
                 strings.append(string)
     return objects
示例#4
0
 def get(self, obj, sensitive=True):
     value = getvalue(obj, self.field_name, returnIfNone='')
     if not sensitive:
         return value.lower()
     return value
示例#5
0
 def apply(self, objects):
     return sorted(objects, key=lambda k: getvalue(k, self.field_name), reverse=self.reverse)
            "lines.linewidth": 2,
            'grid.linestyle': '--'
        })

fpr, tpr, thre = roc_curve(y_test, prepro)
tpr_e = [tpr]
fpr_e = [fpr]
label_e = ['ROC curve (AUC = %0.4f)']
roc_e = [roc_auc]
roc_plot(tpr_e, fpr_e, label_e, roc_e)

###optimal threshold based on entire dataset
opt_thre.append(threshold_youden(fpr, tpr, thre))

###------threshold curves
(precision, recall, f1score, thresholds) = getvalue(y_test, prepro)
legend_e = ('precision', 'recall', 'f1score')
title_e = 'thresholds: entire dataset'
thresholds_e = [thresholds, thresholds, thresholds]
para_e = [precision, recall, f1score]
thre_plot(thresholds_e, para_e, legend_e, title_e)
print("\n")
print("\n")
'''
###age: XX~40, 41~60, 61~XX
group_test, age_pre, age_prepro, group_X = [[[] for _ in range(3)] for _ in range(4)]
for i in range(len(X_test)):
    if X_test.loc[i, 'age'] < 41:
        group_(age_pre[0], pre[i], group_test[0], y_test[i], age_prepro[0], prepro[i], group_X[0], X_test.loc[i])
    elif X_test.loc[i, 'age'] < 71:
        group_(age_pre[1], pre[i], group_test[1], y_test[i], age_prepro[1], prepro[i], group_X[1], X_test.loc[i])
示例#7
0
 def apply(self, objects):
     return sorted(objects,
                   key=lambda k: getvalue(k, self.field_name),
                   reverse=self.reverse)
示例#8
0
def control_car_process(data, status, run, start):
    max_num = 2100
    min_num = 700
    turn_ratio = 337  #转弯率
    turn_ratio_1 = 337  #一档转弯
    turn_ratio_2 = 335  #二档转弯
    turn_ratio_3 = 305  #三档转弯
    turn_ratio_4 = 298  #四档转弯
    sharp_turn = 800  #急转弯率
    speed_offset = 20  #速度偏移量
    while run.value:
        speed_car = data[0]
        angle_car = 1500
        fn = '/dev/input/js0'
        jsdev = open(fn, 'rb')
        car = serial.value
        axis_map, axis_states, button_map, button_states = getvalue()
        lib_path = path + "/lib" + "/libart_driver.so"
        so = cdll.LoadLibrary
        lib = so(lib_path)

        try:
            if (lib.art_racecar_init(38400, car.encode("utf-8")) < 0):
                raise
                pass
            lib.send_cmd(1500, 1500)
            while run.value:
                evbuf = jsdev.read(8)
                if evbuf:
                    time, value, type, number = struct.unpack('IhBB', evbuf)
                    if type & 0x01:
                        button = button_map[number]
                        if button:
                            button_states[button] = value
                            #启动键设置为tl
                            if (button == "tl"
                                    and button_states[button] == True):
                                start.value = True
                                print("START")
                                lib.send_cmd(speed_car, angle_car)
                            #停止按键
                            if ((button == "tr"
                                 and button_states[button] == True)):
                                # Stop
                                print("Stop")
                                status.value = False
                                data[0] = 1500
                                data[1] = 1500
                                lib.send_cmd(1500, 1500)
                            #切换一档转向
                            if (button == "a"
                                    and button_states[button] == True):
                                turn_ratio = turn_ratio_1
                            # 切换二档转向
                            if (button == "b"
                                    and button_states[button] == True):
                                turn_ratio = turn_ratio_2
                            # 切换三档转向
                            if (button == "x"
                                    and button_states[button] == True):
                                turn_ratio = turn_ratio_3
                            # 切换四档转向
                            if (button == "y"
                                    and button_states[button] == True):
                                turn_ratio = turn_ratio_4
                            # 速度增加
                            if (button == "y"
                                    and button_states[button] == True):
                                turn_ratio = turn_ratio_4
                            # 速度减小
                            if (button == "y"
                                    and button_states[button] == True):
                                turn_ratio = turn_ratio_4

                    if (start.value == True
                        ):  # PS2 control speed and angle start
                        if type & 0x02:
                            axis = axis_map[number]
                            if axis:
                                #左滑轮x轴
                                if axis == "x":
                                    fvalue = value / 32767
                                    axis_states[axis] = fvalue
                                    angle1 = 1500 - (fvalue * turn_ratio)
                                    if angle1 <= min_num:
                                        angle1 = min_num
                                    if angle1 >= max_num:
                                        angle1 = max_num
                                    angle_car = int(angle1)

                                    data[0] = speed_car
                                    data[1] = angle_car
                                    lib.send_cmd(speed_car, angle_car)
                                #右滑钮x轴,控制急转弯
                                if axis == "z":
                                    fvalue = value / 32767
                                    axis_states[axis] = fvalue
                                    angle1 = 1500 - (fvalue * sharp_turn)
                                    if angle1 <= min_num:
                                        angle1 = min_num
                                    if angle1 >= max_num:
                                        angle1 = max_num
                                    angle_car = int(angle1)

                                    data[0] = speed_car
                                    data[1] = angle_car
                                    lib.send_cmd(speed_car, angle_car)

                                if axis == "rz":  #右滑钮上下控制加速减速
                                    fvalue = value / 32767
                                    axis_states[axis] = fvalue
                                    speed1 = args.speed - (fvalue *
                                                           speed_offset)
                                    speed_car = int(speed1)
                                    data[0] = speed_car
                                    data[1] = angle_car
                                    lib.send_cmd(speed_car, angle_car)
                                #左滑钮y轴为y,右滑钮y轴为rz

        except:
            print("car run error")
        finally:
            lib.send_cmd(1500, 1500)
            print("car run finally")
示例#9
0
    def medication_processor(paths,
                             num_epochs,
                             num_embedding=500,
                             batch_size=256):
        medication_info = {}
        for path in paths:
            with open(path, 'r') as fl:
                js_data = ast.literal_eval(fl.read())
                js_data = ast.literal_eval(js_data['data'].replace("'", "\""))

                for data in js_data:
                    subject_id = data["subject"]
                    hospital_id = data["context"]
                    if subject_id not in medication_info:
                        medication_info[subject_id] = {}
                    if hospital_id not in medication_info[subject_id]:
                        medication_info[subject_id][hospital_id] = {}
                    drug = str(data["medicationCodeableConcept"]).lower()
                    quantity = "".join(data["quantity"].split())
                    quantity_value = getvalue(quantity)

                    # equating to string false because 0 is a valid value but is considered false
                    if quantity_value != "false":
                        quantity = quantity_value
                    elif len(re.findall("\d*\.?\d*-\d*\.?\d*", quantity)) > 0:
                        quantity = re.findall("\d*\.?\d*-\d*\.?\d*",
                                              quantity)[0]
                        quantity = quantity.split("-")
                        quantity = list(map(getvalue, quantity))
                        quantity = sum(quantity) / len(quantity)
                    else:
                        quantity = 1
                    unit = ""
                    if data["note"] is not None:
                        unit = str(data["note"].split()[-1]).lower()
                    feature_name = drug + "_" + unit
                    if feature_name not in medication_info[subject_id][
                            hospital_id]:
                        medication_info[subject_id][hospital_id][
                            feature_name] = 0
                    medication_info[subject_id][hospital_id][
                        feature_name] += quantity

        feature_dict = {}
        row = []
        columns = []
        data = []
        feature_index = 0
        row_index = 0
        medication_info_row_mapping = {}

        for subject_id in medication_info:
            medication_info_row_mapping[subject_id] = {}
            for hospital_id in medication_info[subject_id]:
                for feature in medication_info[subject_id][hospital_id]:

                    if feature not in feature_dict:
                        feature_dict[feature] = feature_index
                        feature_index = feature_index + 1

                    row.append(row_index)
                    columns.append(feature_dict[feature])
                    data.append(
                        medication_info[subject_id][hospital_id][feature])

                medication_info_row_mapping[subject_id][
                    hospital_id] = row_index
                row_index += 1

        sparse_matrix = csr_matrix((data, (row, columns)),
                                   shape=(row_index, feature_index))

        inp_shape = sparse_matrix.shape[1]
        textAutoEncoder = Autoencoder(inputshape=inp_shape,
                                      encoding_dim=num_embedding)
        autoencoder, encoder, decoder = textAutoEncoder.Model()

        print("training model")
        X_train, X_test = train_test_split(sparse_matrix,
                                           test_size=0.33,
                                           random_state=42)
        autoencoder.fit(X_train,
                        X_train,
                        epochs=num_epochs,
                        batch_size=batch_size,
                        shuffle=True,
                        validation_data=(X_test, X_test),
                        verbose=False)

        print("model fit finished")

        medication_auto_encoder_data = {}
        for subject_id in medication_info_row_mapping:
            medication_auto_encoder_data[subject_id] = {}
            for hospital_id in medication_info_row_mapping[subject_id]:
                index = medication_info_row_mapping[subject_id][hospital_id]
                encoded_ouput = encoder.predict(sparse_matrix[index])[0]
                encoded_ouput = [float(a) for a in encoded_ouput]
                medication_auto_encoder_data[subject_id][
                    hospital_id] = encoded_ouput
        print("saving model data")

        return medication_auto_encoder_data