Utopia 2
Framework for studying models of complex & adaptive systems.
|
Classes | |
class | AgentState |
An agent's state. More... | |
struct | Infrastructure |
class | SimpleFlocking |
The SimpleFlocking Model. More... | |
Typedefs | |
using | ModelTypes = Utopia::ModelTypes<> |
Type helper to define types used by the model. | |
using | AgentTraits = Utopia::AgentTraits< AgentState, Update::sync > |
Agent traits specialization using the state type. | |
Functions | |
BOOST_FIXTURE_TEST_CASE (test_state_interface, Infrastructure, *utf::tolerance(1.e-12)) | |
Test the AgentState interface. | |
BOOST_FIXTURE_TEST_CASE (test_state_angles, Infrastructure, *utf::tolerance(1.e-12)) | |
Check angles are used according to convention. | |
BOOST_AUTO_TEST_SUITE (test_angles) | |
BOOST_TEST (constrain_angle(+1.)==+1.) | |
Assert the basic working of the regularisation function for angles. | |
BOOST_TEST (constrain_angle(-1.)==-1.) | |
BOOST_TEST (constrain_angle(+M_PI)==-M_PI) | |
BOOST_TEST (constrain_angle(-M_PI)==-M_PI) | |
BOOST_TEST (constrain_angle(+3 *M_PI)==-M_PI) | |
BOOST_TEST (constrain_angle(-3 *M_PI)==-M_PI) | |
BOOST_TEST (constrain_angle(+2 *M_PI)==0.) | |
BOOST_TEST (constrain_angle(+4 *M_PI)==0.) | |
BOOST_TEST (constrain_angle(+40 *M_PI)==0.) | |
BOOST_TEST (constrain_angle(-2 *M_PI)==0.) | |
BOOST_TEST (constrain_angle(-4 *M_PI)==0.) | |
BOOST_TEST (constrain_angle(-40 *M_PI)==0.) | |
BOOST_TEST (constrain_angle(+M_PI+1.)==-M_PI+1.) | |
BOOST_TEST (constrain_angle(-M_PI - 1.)==+M_PI - 1.) | |
BOOST_FIXTURE_TEST_CASE (test_random_angle, Infrastructure) | |
Assert that there is no bias in the random angle function. | |
BOOST_AUTO_TEST_SUITE_END () | |
BOOST_AUTO_TEST_SUITE (test_geometry) | |
BOOST_AUTO_TEST_CASE (test_absolute_group_velocity) | |
BOOST_AUTO_TEST_SUITE (test_circular_stats) | |
BOOST_AUTO_TEST_CASE (test_circular_mean) | |
Tests the circular_mean function. | |
BOOST_AUTO_TEST_CASE (test_circular_mean_and_std) | |
Tests the circular_mean_and_std function. | |
template<class RNG , class T = double> | |
T | random_angle (const std::shared_ptr< RNG > &rng) |
Returns a uniformly random angle value in [-π, +π) | |
template<class T > | |
T | constrain_angle (T angle) |
Constrains an angle value to interval [-π, +π) | |
template<class Container > | |
void | constrain_angles (Container &angles) |
In-place constrains all angles in a container to interval [-π, +π) | |
template<class Container > | |
double | absolute_group_velocity (const Container &velocities) |
Computes the absolute group velocity from a container of velocity vectors. | |
template<class Container > | |
auto | _circular_sin_cos_sum (const Container &angles) |
Compute sum of sine and cosine values from angles in a container. | |
template<class Container = std::vector<double>> | |
auto | circular_mean (const Container &angles) |
Computes the circular mean from a sample of (constrained) angles. | |
template<class Container = std::vector<double>> | |
auto | circular_mean_and_std (const Container &angles) |
Computes the circular mean and std from a sample of (constrained) angles. | |
Variables | |
constexpr double | TAU = 2*M_PI |
constexpr double | NaN = std::numeric_limits<double>::quiet_NaN() |
using Utopia::Models::SimpleFlocking::AgentTraits = typedef Utopia::AgentTraits<AgentState, Update::sync> |
Agent traits specialization using the state type.
The first template parameter specifies the type of the cell state, the second sets them to be synchronously updated.
Type helper to define types used by the model.
Compute sum of sine and cosine values from angles in a container.
Computes the absolute group velocity from a container of velocity vectors.
Essentially: the 2-norm of the sum of all velocity vectors, divided by the number of vectors. Returns NaN if the given container is empty.
Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_CASE | ( | test_absolute_group_velocity | ) |
Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_CASE | ( | test_circular_mean | ) |
Tests the circular_mean function.
Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_CASE | ( | test_circular_mean_and_std | ) |
Tests the circular_mean_and_std function.
Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_SUITE | ( | test_angles | ) |
Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_SUITE | ( | test_circular_stats | ) |
Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_SUITE | ( | test_geometry | ) |
Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_SUITE_END | ( | ) |
Utopia::Models::SimpleFlocking::BOOST_FIXTURE_TEST_CASE | ( | test_random_angle | , |
Infrastructure | |||
) |
Assert that there is no bias in the random angle function.
This is not to test the properties of uniform_real_distribution or the RNG but of the hard-coded interval in the random_angle function, which should for consistency's sake be symmetric around zero.
Utopia::Models::SimpleFlocking::BOOST_FIXTURE_TEST_CASE | ( | test_state_angles | , |
Infrastructure | , | ||
* | utf::tolerance1.e-12 | ||
) |
Check angles are used according to convention.
Utopia::Models::SimpleFlocking::BOOST_FIXTURE_TEST_CASE | ( | test_state_interface | , |
Infrastructure | , | ||
* | utf::tolerance1.e-12 | ||
) |
Test the AgentState interface.
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(+1.) | = =+1. | ) |
Assert the basic working of the regularisation function for angles.
Values should always be in [-π, +π)
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(+2 *M_PI) | = =0. | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(+3 *M_PI) | = =-M_PI | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(+4 *M_PI) | = =0. | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(+40 *M_PI) | = =0. | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(+M_PI) | = =-M_PI | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(+M_PI+1.) | = =-M_PI+1. | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(-1.) | = =-1. | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(-2 *M_PI) | = =0. | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(-3 *M_PI) | = =-M_PI | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(-4 *M_PI) | = =0. | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(-40 *M_PI) | = =0. | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(-M_PI - 1.) | = =+M_PI - 1. | ) |
Utopia::Models::SimpleFlocking::BOOST_TEST | ( | constrain_angle(-M_PI) | = =-M_PI | ) |
Computes the circular mean from a sample of (constrained) angles.
Uses circular statistics to compute the mean. Assumes angles to be in radians. While it does not matter in which interval they are, the resulting mean value will be in [-π, +π).
Returns NaN if the given container is empty.
See scipy implementation for reference: https://github.com/scipy/scipy/blob/v1.7.1/scipy/stats/morestats.py#L3474
Computes the circular mean and std from a sample of (constrained) angles.
Uses circular statistics to compute the mean and standard deviation. Assumes angles to be in radians. While it does not matter in which interval they are, the resulting mean value will be in [-π, +π).
Returns NaN if the given container is empty.
See scipy implementation for reference: https://github.com/scipy/scipy/blob/v1.7.1/scipy/stats/morestats.py#L3595
T Utopia::Models::SimpleFlocking::constrain_angle | ( | T | angle | ) |
Constrains an angle value to interval [-π, +π)
In-place constrains all angles in a container to interval [-π, +π)
T Utopia::Models::SimpleFlocking::random_angle | ( | const std::shared_ptr< RNG > & | rng | ) |
Returns a uniformly random angle value in [-π, +π)
|
constexpr |