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

Classes

struct  Infrastructure
 
struct  TestNetworkU
 
struct  TestNetworkD
 
struct  TestNetworkD_small
 

Functions

 BOOST_FIXTURE_TEST_CASE (test_get_rand, Infrastructure)
 
 BOOST_AUTO_TEST_CASE (test_is_directed)
 
 BOOST_FIXTURE_TEST_CASE (test_get_rand_neighbor, TestNetworkU)
 
 BOOST_FIXTURE_TEST_CASE (test_set_and_normalize_weights, TestNetworkD, *boost::unit_test::tolerance(1e-12))
 
 BOOST_FIXTURE_TEST_CASE (test_select_neighbour, TestNetworkD_small, *boost::unit_test::tolerance(1.0))
 
template<typename RT , typename T , typename RNGType >
RT get_rand (std::pair< T, T > range, RNGType &rng)
 Generate a random number within the given range. More...
 
template<typename NWType >
constexpr bool is_directed ()
 Check whether the network type allows for directed edges. More...
 
template<typename NWType , typename VertexDescType , typename RNGType >
auto get_rand_neighbor (const VertexDescType v, NWType &nw, RNGType &rng)
 
template<typename NWType , typename RNGType , typename VertexDescType >
VertexDescType select_neighbor (const VertexDescType v, NWType &nw, std::uniform_real_distribution< double > &prob_distr, RNGType &rng)
 
template<typename NWType , typename VertexDescType >
double opinion_difference (VertexDescType v, VertexDescType w, NWType &nw)
 Calculate the absolute opinion difference of two vertices. More...
 
template<typename NWType , typename VertexDescType >
void set_and_normalize_weights (const VertexDescType v, NWType &nw, const double weighting)
 Set and normalize weights according to opinion difference. More...
 

Variables

std::uniform_real_distribution< double > uniform_prob_distr
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

Utopia::Models::Opinionet::Utils::BOOST_AUTO_TEST_CASE ( test_is_directed  )

◆ BOOST_FIXTURE_TEST_CASE() [1/4]

Utopia::Models::Opinionet::Utils::BOOST_FIXTURE_TEST_CASE ( test_get_rand  ,
Infrastructure   
)

◆ BOOST_FIXTURE_TEST_CASE() [2/4]

Utopia::Models::Opinionet::Utils::BOOST_FIXTURE_TEST_CASE ( test_get_rand_neighbor  ,
TestNetworkU   
)

◆ BOOST_FIXTURE_TEST_CASE() [3/4]

Utopia::Models::Opinionet::Utils::BOOST_FIXTURE_TEST_CASE ( test_select_neighbour  ,
TestNetworkD_small  ,
boost::unit_test::tolerance1.0 
)

◆ BOOST_FIXTURE_TEST_CASE() [4/4]

Utopia::Models::Opinionet::Utils::BOOST_FIXTURE_TEST_CASE ( test_set_and_normalize_weights  ,
TestNetworkD  ,
boost::unit_test::tolerance1e-12 
)

◆ get_rand()

template<typename RT , typename T , typename RNGType >
RT Utopia::Models::Opinionet::Utils::get_rand ( std::pair< T, T >  range,
RNGType &  rng 
)

Generate a random number within the given range.

◆ get_rand_neighbor()

template<typename NWType , typename VertexDescType , typename RNGType >
auto Utopia::Models::Opinionet::Utils::get_rand_neighbor ( const VertexDescType  v,
NWType &  nw,
RNGType &  rng 
)

Get random neighbour of vertex v (for directed and undirected graphs). Only appliable to vertices with degree > 0

◆ is_directed()

template<typename NWType >
constexpr bool Utopia::Models::Opinionet::Utils::is_directed ( )
constexpr

Check whether the network type allows for directed edges.

◆ opinion_difference()

template<typename NWType , typename VertexDescType >
double Utopia::Models::Opinionet::Utils::opinion_difference ( VertexDescType  v,
VertexDescType  w,
NWType &  nw 
)

Calculate the absolute opinion difference of two vertices.

◆ select_neighbor()

template<typename NWType , typename RNGType , typename VertexDescType >
VertexDescType Utopia::Models::Opinionet::Utils::select_neighbor ( const VertexDescType  v,
NWType &  nw,
std::uniform_real_distribution< double > &  prob_distr,
RNGType &  rng 
)

Select random neighbor with probability proportional to edge weight. Only applicable to vertices with degree > 0

◆ set_and_normalize_weights()

template<typename NWType , typename VertexDescType >
void Utopia::Models::Opinionet::Utils::set_and_normalize_weights ( const VertexDescType  v,
NWType &  nw,
const double  weighting 
)

Set and normalize weights according to opinion difference.

Iterates over a vertex' out-edges and sets the weights to exp(- weighting * abs(opinion difference)), then normalizes them (softmax).

Warning
This assumes that the vertex has at least one out-edge. Make sure to check this in the calling scope, otherwise this will lead to a zero division error during normalisation.

Variable Documentation

◆ uniform_prob_distr

std::uniform_real_distribution<double> Utopia::Models::Opinionet::Utils::uniform_prob_distr