Utopia  2
Framework for studying models of complex & adaptive systems.
Classes | Typedefs | Functions | Variables
Utopia::Models::SimpleFlocking Namespace Reference

Classes

class  SimpleFlocking
 The SimpleFlocking Model. More...
 
class  AgentState
 An agent's state. More...
 
struct  Infrastructure
 

Typedefs

using ModelTypes = Utopia::ModelTypes<>
 Type helper to define types used by the model. More...
 
using AgentTraits = Utopia::AgentTraits< AgentState, Update::sync >
 Agent traits specialization using the state type. More...
 

Functions

 BOOST_FIXTURE_TEST_CASE (test_state_interface, Infrastructure, *utf::tolerance(1.e-12))
 Test the AgentState interface. More...
 
 BOOST_FIXTURE_TEST_CASE (test_state_angles, Infrastructure, *utf::tolerance(1.e-12))
 Check angles are used according to convention. More...
 
 BOOST_AUTO_TEST_SUITE (test_angles)
 
 BOOST_TEST (constrain_angle(+1.)==+1.)
 Assert the basic working of the regularisation function for angles. More...
 
 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. More...
 
 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. More...
 
 BOOST_AUTO_TEST_CASE (test_circular_mean_and_std)
 Tests the circular_mean_and_std function. More...
 
template<class RNG , class T = double>
random_angle (const std::shared_ptr< RNG > &rng)
 Returns a uniformly random angle value in [-π, +π) More...
 
template<class T >
constrain_angle (T angle)
 Constrains an angle value to interval [-π, +π) More...
 
template<class Container >
void constrain_angles (Container &angles)
 In-place constrains all angles in a container to interval [-π, +π) More...
 
template<class Container >
double absolute_group_velocity (const Container &velocities)
 Computes the absolute group velocity from a container of velocity vectors. More...
 
template<class Container >
auto _circular_sin_cos_sum (const Container &angles)
 Compute sum of sine and cosine values from angles in a container. More...
 
template<class Container = std::vector<double>>
auto circular_mean (const Container &angles)
 Computes the circular mean from a sample of (constrained) angles. More...
 
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. More...
 

Variables

constexpr double TAU = 2*M_PI
 
constexpr double NaN = std::numeric_limits<double>::quiet_NaN()
 

Typedef Documentation

◆ AgentTraits

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.

◆ ModelTypes

Type helper to define types used by the model.

Function Documentation

◆ _circular_sin_cos_sum()

template<class Container >
auto Utopia::Models::SimpleFlocking::_circular_sin_cos_sum ( const Container &  angles)

Compute sum of sine and cosine values from angles in a container.

◆ absolute_group_velocity()

template<class Container >
double Utopia::Models::SimpleFlocking::absolute_group_velocity ( const Container &  velocities)

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.

◆ BOOST_AUTO_TEST_CASE() [1/3]

Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_CASE ( test_absolute_group_velocity  )

◆ BOOST_AUTO_TEST_CASE() [2/3]

Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_CASE ( test_circular_mean  )

Tests the circular_mean function.

◆ BOOST_AUTO_TEST_CASE() [3/3]

Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_CASE ( test_circular_mean_and_std  )

Tests the circular_mean_and_std function.

◆ BOOST_AUTO_TEST_SUITE() [1/3]

Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_SUITE ( test_angles  )

◆ BOOST_AUTO_TEST_SUITE() [2/3]

Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_SUITE ( test_circular_stats  )

◆ BOOST_AUTO_TEST_SUITE() [3/3]

Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_SUITE ( test_geometry  )

◆ BOOST_AUTO_TEST_SUITE_END()

Utopia::Models::SimpleFlocking::BOOST_AUTO_TEST_SUITE_END ( )

◆ BOOST_FIXTURE_TEST_CASE() [1/3]

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.

◆ BOOST_FIXTURE_TEST_CASE() [2/3]

Utopia::Models::SimpleFlocking::BOOST_FIXTURE_TEST_CASE ( test_state_angles  ,
Infrastructure  ,
utf::tolerance1.e-12 
)

Check angles are used according to convention.

◆ BOOST_FIXTURE_TEST_CASE() [3/3]

Utopia::Models::SimpleFlocking::BOOST_FIXTURE_TEST_CASE ( test_state_interface  ,
Infrastructure  ,
utf::tolerance1.e-12 
)

Test the AgentState interface.

◆ BOOST_TEST() [1/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(+1.)  = =+1.)

Assert the basic working of the regularisation function for angles.

Values should always be in [-π, +π)

◆ BOOST_TEST() [2/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(+2 *M_PI)  = =0.)

◆ BOOST_TEST() [3/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(+3 *M_PI)  = =-M_PI)

◆ BOOST_TEST() [4/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(+4 *M_PI)  = =0.)

◆ BOOST_TEST() [5/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(+40 *M_PI)  = =0.)

◆ BOOST_TEST() [6/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(+M_PI)  = =-M_PI)

◆ BOOST_TEST() [7/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(+M_PI+1.)  = =-M_PI+1.)

◆ BOOST_TEST() [8/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(-1.)  = =-1.)

◆ BOOST_TEST() [9/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(-2 *M_PI)  = =0.)

◆ BOOST_TEST() [10/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(-3 *M_PI)  = =-M_PI)

◆ BOOST_TEST() [11/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(-4 *M_PI)  = =0.)

◆ BOOST_TEST() [12/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(-40 *M_PI)  = =0.)

◆ BOOST_TEST() [13/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(-M_PI - 1.)  = =+M_PI - 1.)

◆ BOOST_TEST() [14/14]

Utopia::Models::SimpleFlocking::BOOST_TEST ( constrain_angle(-M_PI)  = =-M_PI)

◆ circular_mean()

template<class Container = std::vector<double>>
auto Utopia::Models::SimpleFlocking::circular_mean ( const Container &  angles)

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

◆ circular_mean_and_std()

template<class Container = std::vector<double>>
auto Utopia::Models::SimpleFlocking::circular_mean_and_std ( const Container &  angles)

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

◆ constrain_angle()

template<class T >
T Utopia::Models::SimpleFlocking::constrain_angle ( angle)

Constrains an angle value to interval [-π, +π)

◆ constrain_angles()

template<class Container >
void Utopia::Models::SimpleFlocking::constrain_angles ( Container &  angles)

In-place constrains all angles in a container to interval [-π, +π)

◆ random_angle()

template<class RNG , class T = double>
T Utopia::Models::SimpleFlocking::random_angle ( const std::shared_ptr< RNG > &  rng)

Returns a uniformly random angle value in [-π, +π)

Variable Documentation

◆ NaN

constexpr double Utopia::Models::SimpleFlocking::NaN = std::numeric_limits<double>::quiet_NaN()
constexpr

◆ TAU

constexpr double Utopia::Models::SimpleFlocking::TAU = 2*M_PI
constexpr