コード例 #1
0
    def __modify_acc_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
        acc_IMU = Processor.get_acc(virtual_marker, R_IMU_transform)

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

        changed_columns = []
        for acc_name in ['_acc_x', '_acc_y', '_acc_z']:
            column = self.__moved_segment + acc_name
            changed_columns.append(column)

        acc_IMU_df = pd.DataFrame(acc_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] = acc_IMU_df.loc[train_index]
        x_test_changed[changed_columns] = acc_IMU_df.loc[test_index]
        return x_train_changed, x_test_changed
コード例 #2
0
    def check_acc_difference(self, x, R_cylinder=[]):
        point_list, x_range, z_range = self.__get_plane_position()
        for point in point_list:
            simulated_marker = point[0]

            segment_data = SegmentData(self.__subject_data,
                                       self.__moved_segment)
            walking_data_1_df = segment_data.get_segment_walking_1_data(
                self.__speed)
            test_index = x.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
            acc_IMU = Processor.get_acc(virtual_marker, R_IMU_transform)

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

            changed_columns = []
            for acc_name in ['_acc_x', '_acc_y', '_acc_z']:
                column = self.__moved_segment + acc_name
                changed_columns.append(column)
            plt.plot(acc_IMU[:, 0])
            plt.plot(x[changed_columns].as_matrix()[:, 0])
            score = r2_score(acc_IMU[:, 0], x[changed_columns].as_matrix()[:,
                                                                           0])
            plt.title('pelvis, x += ' + str(point[1]) + ', z += ' +
                      str(point[2]) + ', score = ' + str(score))
            plt.show()
コード例 #3
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