-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from seldon-code/develop
Inertial model
- Loading branch information
Showing
19 changed files
with
1,054 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[simulation] | ||
model = "ActivityDrivenInertial" | ||
# rng_seed = 120 # Leaving this empty will pick a random seed | ||
|
||
[io] | ||
n_output_network = 20 # Write the network every 20 iterations | ||
n_output_agents = 1 # Write the opinions of agents after every iteration | ||
print_progress = true # Print the iteration time ; if not set, then does not print | ||
|
||
[model] | ||
max_iterations = 500 # If not set, max iterations is infinite | ||
|
||
[ActivityDrivenInertial] | ||
dt = 0.01 # Timestep for the integration of the coupled ODEs | ||
m = 10 # Number of agents contacted, when the agent is active | ||
eps = 0.01 # Minimum activity epsilon; a_i belongs to [epsilon,1] | ||
gamma = 2.1 # Exponent of activity power law distribution of activities | ||
reciprocity = 0.65 # 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 = 1.0 # aka beta. if zero, agents pick their interaction partners at random | ||
alpha = 3.0 # Controversialness of the issue, must be greater than 0. | ||
K = 2.0 | ||
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.0 # Mean of distribution before drawing from a truncated normal distribution (default set to 1.0) | ||
reluctance_sigma = 0.25 # Width of normal distribution (before truncating) | ||
reluctance_eps = 0.01 # Minimum such that the normal distribution is truncated at this value | ||
|
||
friction_coefficient = 1.0 # Friction coefficient, making agents tend to go to rest without acceleration | ||
|
||
[network] | ||
number_of_agents = 1000 | ||
connections_per_agent = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
#include "agent.hpp" | ||
#include "agent_io.hpp" | ||
#include <util/misc.hpp> | ||
|
||
namespace Seldon | ||
{ | ||
|
||
struct InertialAgentData | ||
{ | ||
double opinion = 0; // x_i | ||
double activity = 0; // alpha_i | ||
double reluctance = 1.0; // m_i | ||
double velocity = 0.0; // d(x_i)/dt | ||
}; | ||
|
||
using InertialAgent = Agent<InertialAgentData>; | ||
|
||
template<> | ||
inline std::string agent_to_string<InertialAgent>( const InertialAgent & agent ) | ||
{ | ||
return fmt::format( | ||
"{}, {}, {}, {}", agent.data.opinion, agent.data.velocity, agent.data.activity, agent.data.reluctance ); | ||
} | ||
|
||
template<> | ||
inline std::string opinion_to_string<InertialAgent>( const InertialAgent & agent ) | ||
{ | ||
return fmt::format( "{}", agent.data.opinion ); | ||
} | ||
|
||
template<> | ||
inline InertialAgent agent_from_string<InertialAgent>( const std::string & str ) | ||
{ | ||
InertialAgent res{}; | ||
|
||
auto callback = [&]( int idx_list, std::string & substr ) | ||
{ | ||
if( idx_list == 0 ) | ||
{ | ||
res.data.opinion = std::stod( substr ); | ||
} | ||
else if( idx_list == 1 ) | ||
{ | ||
res.data.velocity = std::stod( substr ); | ||
} | ||
else if( idx_list == 2 ) | ||
{ | ||
res.data.activity = std::stod( substr ); | ||
} | ||
else if( idx_list == 3 ) | ||
{ | ||
res.data.reluctance = std::stod( substr ); | ||
} | ||
}; | ||
|
||
Seldon::parse_comma_separated_list( str, callback ); | ||
|
||
return res; | ||
}; | ||
|
||
template<> | ||
inline std::vector<std::string> agent_to_string_column_names<InertialAgent>() | ||
{ | ||
return { "opinion", "velocity", "activity", "reluctance" }; | ||
} | ||
} // namespace Seldon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.