Skip to content

Commit

Permalink
Tests: Activity driven model test WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
amritagos committed Mar 12, 2024
1 parent 2a3503d commit fa088f7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
27 changes: 27 additions & 0 deletions test/res/2_agents_activity_prob.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[simulation]
model = "ActivityDriven"
rng_seed = 120 # Leaving this empty will pick a random seed

[io]
n_output_network = 1 # Write the network every 20 iterations
n_output_agents = 1
print_progress = true # Print the iteration time ; if not set, then always print

[model]
max_iterations = 2 # If not set, max iterations is infinite

[ActivityDriven]
dt = 0.01 # Timestep for the integration of the coupled ODEs
m = 1 # Number of agents contacted, when the agent is active
eps = 1 # Minimum activity epsilon; a_i belongs to [epsilon,1]
gamma = 2.1 # Exponent of activity power law distribution of activities
reciprocity = 1 # probability that when agent i contacts j via weighted reservoir sampling, j also sends feedback to i. So every agent can have more than m incoming connections
homophily = 0.5 # aka beta. if zero, agents pick their interaction partners at random
alpha = 3.0 # Controversialness of the issue, must be greater than 0.
K = 3.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

[network]
number_of_agents = 2
connections_per_agent = 1
26 changes: 24 additions & 2 deletions test/test_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#include <simulation.hpp>
namespace fs = std::filesystem;

#include <fmt/format.h>
#include <fmt/ostream.h>
#include <util/io.hpp>

TEST_CASE(
"Test that you can produce output for the probabilistic acitivity driven model, from a conf file",
Expand Down Expand Up @@ -39,4 +38,27 @@ TEST_CASE(

// Cleanup
fs::remove_all( output_dir_path );
}

TEST_CASE( "Test the probabilistic activity driven model for two agents", "[activityProbTwoAgents]" )
{
using namespace Seldon;
using namespace Catch::Matchers;

auto proj_root_path = fs::current_path();
auto input_file = proj_root_path / fs::path( "test/res/2_agents_activity_prob.toml" );

auto options = Config::parse_config_file( input_file.string() );

auto simulation = Simulation( options, std::nullopt, std::nullopt );

// We need an output path for Simulation, but we won't write anything out there?
fs::path output_dir_path = proj_root_path / fs::path( "test/output" );
fs::create_directories( output_dir_path );

// Zero step
auto filename = fmt::format( "opinions_{}.txt", 0 );
Seldon::IO::opinions_to_file( simulation, ( output_dir_path / fs::path( filename ) ).string() );

simulation.run( output_dir_path );
}

0 comments on commit fa088f7

Please sign in to comment.