Exemple #1
0
    def __modify_gyr_test(self,
                          simulated_marker,
                          x_train,
                          x_test,
                          R_cylinder=[]):
        segment_data = SegmentData(self.__subject_data, self.__moved_segment)
        walking_data_1_df = segment_data.get_segment_walking_1_data(
            self.__speed)
        train_index = x_train.index
        test_index = x_test.index
        R_standing_to_ground = segment_data.get_segment_R()
        marker_cali_matrix = segment_data.get_marker_cali_matrix(self.__speed)
        virtual_marker, R_IMU_transform = Processor.get_virtual_marker(
            simulated_marker, walking_data_1_df, marker_cali_matrix,
            R_standing_to_ground)
        # Processor.check_virtual_marker(virtual_marker, walking_data_1_df, self.__moved_segment)  # for check
        gyr_IMU = Processor.get_gyr(walking_data_1_df, R_IMU_transform)

        # if it was simulated on cylinder, a rotation around the cylinder surface is necessary
        if len(R_cylinder) != 0:
            gyr_IMU = np.matmul(R_cylinder, gyr_IMU.T).T

        changed_columns = []
        for gyr_name in ['_gyr_x', '_gyr_y', '_gyr_z']:
            column = self.__moved_segment + gyr_name
            changed_columns.append(column)

        gyr_IMU_df = pd.DataFrame(gyr_IMU)
        # x_test is just a quote of the original x_test, deep copy so that no warning will show up
        x_train_changed = x_train.copy()
        x_test_changed = x_test.copy()
        x_train_changed[changed_columns] = gyr_IMU_df.loc[train_index]
        x_test_changed[changed_columns] = gyr_IMU_df.loc[test_index]
        return x_train_changed, x_test_changed
Exemple #2
0
    def get_xy(self):
        speed = self.__speed
        walking_data_1_df = self.__subject_data.get_walking_1_data(speed)
        # for now we only use walking data 1
        data_len = walking_data_1_df.shape[0]
        # get x
        if self.__gyr_data:
            x = np.zeros([data_len, 48])
        else:
            x = np.zeros([data_len, 24])
        i_segment = 0
        for segment_name in SEGMENT_NAMES:
            segment_data = SegmentData(self.__subject_data, segment_name)
            segment_data_walking_1_df = segment_data.get_segment_walking_1_data(
                speed)
            center_marker = segment_data.get_center_point_mean(speed)
            R_standing_to_ground = segment_data.get_segment_R()
            marker_cali_matrix = segment_data.get_marker_cali_matrix(speed)
            virtual_marker, R_IMU_transform = Processor.get_virtual_marker(
                center_marker, segment_data_walking_1_df, marker_cali_matrix,
                R_standing_to_ground)
            # Processor.check_virtual_marker(virtual_marker, walking_data_1_df, segment_name)    # for check
            acc_IMU = Processor.get_acc(virtual_marker, R_IMU_transform)
            x[:, 3 * i_segment:3 * (i_segment + 1)] = acc_IMU

            if self.__gyr_data:
                gyr_IMU = Processor.get_gyr(segment_data_walking_1_df,
                                            R_IMU_transform)
                x[:, 24 + 3 * i_segment:24 + 3 * (i_segment + 1)] = gyr_IMU

            i_segment += 1
        x = pd.DataFrame(x)
        if self.__gyr_data:
            x.columns = ALL_ACC_GYR_NAMES
        else:
            x.columns = ALL_ACC_NAMES

        # get y
        y = walking_data_1_df[self.__output_names]

        return x, y