コード例 #1
0
def main():
    # loop over all experiments
    for expt in session.query(models.Experiment):

        print("In experiment '{}'".format(expt.id))

        dt = 1 / expt.sampling_frequency

        for traj in session.query(
                models.Trajectory).filter_by(experiment=expt):

            positions = traj.positions(session)
            velocities = traj.velocities(session)

            # calculate kinematic quantities
            velocities_a = kinematics.norm(velocities)

            accelerations = kinematics.acceleration(velocities, dt)
            accelerations_a = kinematics.norm(accelerations)

            headings = kinematics.heading(velocities)

            angular_velocities = kinematics.angular_velocity(velocities, dt)
            angular_velocities_a = kinematics.norm(angular_velocities)

            angular_accelerations = kinematics.acceleration(
                angular_velocities, dt)
            angular_accelerations_a = kinematics.norm(angular_accelerations)

            distance_from_wall = kinematics.distance_from_wall(
                positions, WALL_BOUNDS)

            # store kinematic quantities in timepoints
            for ctr, tp in enumerate(traj.timepoints(session)):

                tp.velocity_a = velocities_a[ctr]
                tp.acceleration_x, tp.acceleration_y, tp.acceleration_z = accelerations[
                    ctr]
                tp.acceleration_a = accelerations_a[ctr]

                tp.heading_xy, tp.heading_xz, tp.heading_xyz = headings[ctr]

                tp.angular_velocity_x, tp.angular_velocity_y, tp.angular_velocity_z = angular_velocities[
                    ctr]
                tp.angular_velocity_a = angular_velocities_a[ctr]

                tp.angular_acceleration_x, tp.angular_acceleration_y, tp.angular_acceleration_z = angular_accelerations[
                    ctr]
                tp.angular_acceleration_a = angular_accelerations_a[ctr]

                tp.distance_from_wall = distance_from_wall[ctr]

                session.add(tp)

            commit(session)
コード例 #2
0
def main():
    # loop over all experiments
    for expt in session.query(models.Experiment):

        print("In experiment '{}'".format(expt.id))

        dt = 1 / expt.sampling_frequency

        for traj in session.query(models.Trajectory).filter_by(experiment=expt):

            positions = traj.positions(session)
            velocities = traj.velocities(session)

            # calculate kinematic quantities
            velocities_a = kinematics.norm(velocities)

            accelerations = kinematics.acceleration(velocities, dt)
            accelerations_a = kinematics.norm(accelerations)

            headings = kinematics.heading(velocities)

            angular_velocities = kinematics.angular_velocity(velocities, dt)
            angular_velocities_a = kinematics.norm(angular_velocities)

            angular_accelerations = kinematics.acceleration(angular_velocities, dt)
            angular_accelerations_a = kinematics.norm(angular_accelerations)

            distance_from_wall = kinematics.distance_from_wall(positions, WALL_BOUNDS)

            # store kinematic quantities in timepoints
            for ctr, tp in enumerate(traj.timepoints(session)):

                tp.velocity_a = velocities_a[ctr]
                tp.acceleration_x, tp.acceleration_y, tp.acceleration_z = accelerations[ctr]
                tp.acceleration_a = accelerations_a[ctr]

                tp.heading_xy, tp.heading_xz, tp.heading_xyz = headings[ctr]

                tp.angular_velocity_x, tp.angular_velocity_y, tp.angular_velocity_z = angular_velocities[ctr]
                tp.angular_velocity_a = angular_velocities_a[ctr]

                tp.angular_acceleration_x, tp.angular_acceleration_y, tp.angular_acceleration_z = angular_accelerations[ctr]
                tp.angular_acceleration_a = angular_accelerations_a[ctr]

                tp.distance_from_wall = distance_from_wall[ctr]

                session.add(tp)

            commit(session)
コード例 #3
0
    def train(self, positives, negatives):
        """
        Train this ubersimple classifier.
        :param positives:
        :param negatives:
        :return:
        """
        speeds_pos = [kinematics.norm(positive).mean() for positive in positives]
        speeds_neg = [kinematics.norm(negative).mean() for negative in negatives]

        self.mean_pos = np.mean(speeds_pos)
        self.mean_neg = np.mean(speeds_neg)

        self.std_pos = np.std(speeds_pos)
        self.std_neg = np.std(speeds_neg)
コード例 #4
0
    def test_example_norm_calculated_and_ints_handled_correctly(self):
        v = np.array([[1, 1, 1],
                      [2, 3, 4],
                      [5, 1, -1]])

        n_correct = np.array([np.sqrt(3), 5.3851648071345037, 5.196152422706632])
        np.testing.assert_array_almost_equal(n_correct, kinematics.norm(v))
コード例 #5
0
    def train(self, positives, negatives):
        """
        Train this ubersimple classifier.
        :param positives:
        :param negatives:
        :return:
        """
        speeds_pos = [
            kinematics.norm(positive).mean() for positive in positives
        ]
        speeds_neg = [
            kinematics.norm(negative).mean() for negative in negatives
        ]

        self.mean_pos = np.mean(speeds_pos)
        self.mean_neg = np.mean(speeds_neg)

        self.std_pos = np.std(speeds_pos)
        self.std_neg = np.std(speeds_neg)
コード例 #6
0
    def predict(self, tss):
        """
        Make predictions on a set of time-series.
        :param tss:
        :return:
        """
        predictions = []

        for ts in tss:

            mean_speed = kinematics.norm(ts).mean()

            l_pos = stats.norm.pdf(mean_speed, self.mean_pos, self.std_pos)
            l_neg = stats.norm.pdf(mean_speed, self.mean_neg, self.std_neg)

            if l_pos > l_neg:
                predictions.append(1)
            else:
                predictions.append(-1)

        return predictions
コード例 #7
0
    def predict(self, tss):
        """
        Make predictions on a set of time-series.
        :param tss:
        :return:
        """
        predictions = []

        for ts in tss:

            mean_speed = kinematics.norm(ts).mean()

            l_pos = stats.norm.pdf(mean_speed, self.mean_pos, self.std_pos)
            l_neg = stats.norm.pdf(mean_speed, self.mean_neg, self.std_neg)

            if l_pos > l_neg:
                predictions.append(1)
            else:
                predictions.append(-1)

        return predictions
コード例 #8
0
    def test_tiling_works_correctly(self):
        v = np.random.normal(0, 1, (100, 5))

        self.assertEqual(v.shape, kinematics.norm(v, '2darray').shape)
コード例 #9
0
    def test_example_norm_calculated_and_ints_handled_correctly(self):
        v = np.array([[1, 1, 1], [2, 3, 4], [5, 1, -1]])

        n_correct = np.array(
            [np.sqrt(3), 5.3851648071345037, 5.196152422706632])
        np.testing.assert_array_almost_equal(n_correct, kinematics.norm(v))
コード例 #10
0
    def test_tiling_works_correctly(self):
        v = np.random.normal(0, 1, (100, 5))

        self.assertEqual(v.shape, kinematics.norm(v, '2darray').shape)