Skip to content

Commit

Permalink
ActivityDrivenModel: Unit test includes reluctance
Browse files Browse the repository at this point in the history
We modified the unit test with one bot and one agent to now include
the reluctance (of the agent).

Co-authored-by: Moritz Sallermann <[email protected]>
  • Loading branch information
amritagos and MSallermann committed Mar 16, 2024
1 parent 20d7eac commit 01f3af7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions test/res/1bot_1agent_activity_prob.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ K = 2.0 # Social interaction strength
mean_activities = false # Use the mean value of the powerlaw distribution for the activities of all agents
mean_weights = false # Use the meanfield approximation of the network edges

reluctances = true # Assigns a "reluctance" (m_i) to each agent. By default; false and every agent has a reluctance of 1
reluctance_mean = 1.5 # Mean of distribution before drawing from a truncated normal distribution (default set to 1.0)
reluctance_sigma = 2.5 # Width of normal distribution (before truncating)
reluctance_eps = 0.01 # Minimum such that the normal distribution is truncated at this value
covariance_factor = 0.25 # Determines whether activities and reluctances will be correlated. If set to 0.0 (default) then they will not be correlated.

n_bots = 1 # The number of bots to be used; if not specified defaults to 0 (which means bots are deactivated)
# Bots are agents with fixed opinions and different parameters, the parameters are specified in the following lists
# If n_bots is smaller than the length of any of the lists, the first n_bots entries are used. If n_bots is greater the code will throw an exception.
Expand Down
14 changes: 10 additions & 4 deletions test/test_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ TEST_CASE( "Test the probabilistic activity driven model for two agents", "[acti
}
}

TEST_CASE( "Test the probabilistic activity driven model with one bot and one agent", "[activity1Bot1Agent]" )
TEST_CASE(
"Test the probabilistic activity driven model with one bot and one (reluctant) agent",
"[activity1Bot1AgentReluctance]" )
{
using namespace Seldon;
using namespace Catch::Matchers;
Expand Down Expand Up @@ -122,16 +124,20 @@ TEST_CASE( "Test the probabilistic activity driven model with one bot and one ag
auto time_elapsed = iterations * dt;

// Final agent and bot opinions after the simulation run
auto x_t = agent.data.opinion;
auto x_t_bot = bot.data.opinion;
auto x_t = agent.data.opinion;
auto x_t_bot = bot.data.opinion;
auto reluctance = agent.data.reluctance;

fmt::print( "Agent reluctance is = {}\n", reluctance );

// The bot opinion should not change during the simulation
REQUIRE_THAT( x_t_bot, WithinAbs( x_bot, 1e-16 ) );

// Test that the agent opinion matches the analytical solution for an agent with a bot
// Analytical solution is:
// x_t = [x(0) - Ktanh(alpha*x_bot)]e^(-t) + Ktanh(alpha*x_bot)
auto x_t_analytical = ( x_0 - K * tanh( alpha * x_bot ) ) * exp( -time_elapsed ) + K * tanh( alpha * x_bot );
auto x_t_analytical = ( x_0 - K / reluctance * tanh( alpha * x_bot ) ) * exp( -time_elapsed )
+ K / reluctance * tanh( alpha * x_bot );

REQUIRE_THAT( x_t, WithinAbs( x_t_analytical, 1e-5 ) );
}
Expand Down

0 comments on commit 01f3af7

Please sign in to comment.