def test_update_velocities_group_field_and_indexes_not_None( self, fixture_update_velocities): """ Comparison of the angles of the agents after applying update velocities through a Kolmogorov-smirnov test. `indexes` and `group_field` are set not None. """ distribution = pytest.distrib sample_indexes = 500 delta_angles = pytest.delta_angles df = DataFrame(pytest.data_large_sample) df["mobility_profile"] = "MG_1" mobility_group_slice = 300 df.loc[0:mobility_group_slice - 1, "mobility_profile"] = "MG_2" angles_before = AgentMovement.vector_angles(df, ['vx', 'vy']) indexes = [i for i in range(sample_indexes + 1)] df = AgentMovement.update_velocities(df, distribution, pytest.angle_variance, indexes, "mobility_profile", "MG_2") angles_after = AgentMovement.vector_angles(df, ['vx', 'vy']) angle_variation_1 = angles_after[:mobility_group_slice] - \ angles_before[:mobility_group_slice] k, p_1 = kstest(angle_variation_1.values, delta_angles) angle_variation_2 = angles_after[mobility_group_slice:] - \ angles_before[mobility_group_slice:] k, p_2 = kstest(angle_variation_2.values, delta_angles) cond_1 = True if p_1 > 0.05 else False cond_2 = True if p_2 < 0.05 else False assert cond_1 and cond_2
def test_update_velocities_under_field_indexes_None( self, fixture_update_velocities): """Updates velocities only for a group of agents under a field.""" df = DataFrame(pytest.data_field) df = AgentMovement.update_velocities(df, pytest.distrib, pytest.angle_variance_field, None, "field", "field_1") velocities_field_vx = df.loc[1, 'vx'] != 2.0 velocities_field_vy = df.loc[1, 'vy'] != 2.0 assert velocities_field_vx and velocities_field_vy
def test_update_velocities_raise_error_indexes_and_group_field_None( self, fixture_update_velocities): """ Raises an exception when the input DataFrame columns `vx` and `vy` does not exist. `indexes` and `group_field` is se to None. """ df = DataFrame(pytest.data_wrong_name_columns) with pytest.raises(ValueError): assert AgentMovement.update_velocities(df, pytest.distrib, pytest.angle_variance)
def test_update_velocities_comparison_angles_distribution( self, fixture_update_velocities): """ Comparison of the velocities magnitudes of agents after applying update velocities function through a Kolmogorov-smirnov. `indexes` and `group_field` is se to None. """ df = DataFrame(pytest.data_large_sample) df = AgentMovement.update_velocities(df, pytest.distrib, 0.0) velocities_magnitude = sqrt(df['vx']**2 + df['vy']**2) k, p = kstest(velocities_magnitude.values - 10, 'norm') cond = True if p > 0.05 else False assert cond
def test_update_velocities_angle_variance_zero_indexes_group_field_None( self, fixture_update_velocities): """ Verifies whether there are no changes in the velocities components when the standard deviation of the numpy normal distribution is set to zero `angle_variance=0.0`. `indexes` and `group_field` is se to None. """ df = DataFrame(pytest.data_large_sample) angles_before = AgentMovement.vector_angles(df, ['vx', 'vy']) df = AgentMovement.update_velocities(df, pytest.distrib, 0.0) angles_after = AgentMovement.vector_angles(df, ['vx', 'vy']) not_angle_variation = all( round(angles_before.head() - angles_after.head(), 7)) assert not_angle_variation == 0
def test_update_velocities_comparison_KS_test(self, fixture_update_velocities): """ Comparison of the angles of the agents after applying update velocities through a Kolmogorov-smirnov test. `indexes` and `group_field` are set to None. """ df = DataFrame(pytest.data_large_sample) angles_before = AgentMovement.vector_angles(df, ['vx', 'vy']) df = AgentMovement.update_velocities(df, pytest.distrib, pytest.angle_variance) angles_after = AgentMovement.vector_angles(df, ['vx', 'vy']) angle_variation = angles_after - angles_before k, p = kstest(angle_variation.values, pytest.delta_angles) cond = True if p > 0.05 else False assert cond
def test_update_velocities_group_field_None(self, fixture_update_velocities): """ Comparison of the angles of the agents after applying update velocities through a Kolmogorov-smirnov test. `group_field` is set to None. """ distribution = pytest.distrib sample_indexes = 400 df = DataFrame(pytest.data_large_sample) angles_before = AgentMovement.vector_angles( df, ['vx', 'vy'])[:sample_indexes] indexes = [i for i in range(sample_indexes + 1)] df = AgentMovement.update_velocities(df, distribution, pytest.angle_variance, indexes, None, None) angles_after = AgentMovement.vector_angles( df, ['vx', 'vy'])[:sample_indexes] angle_variation = angles_after - angles_before k, p = kstest(angle_variation.values, pytest.delta_angles) cond = True if p > 0.05 else False assert cond