Skip to content

Commit 1c90d26

Browse files
author
Moritz Sallermann
committed
ActivityDrivenModel: implemented homophily
1 parent 1508ea6 commit 1c90d26

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/models/ActivityDrivenModel.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ void Seldon::ActivityAgentModel::iteration()
4747

4848
if( activated )
4949
{
50-
// Contact m_agents according to the homophily distribution
51-
// TODO: use homophily stuff instead of uniform
52-
Seldon::draw_unique_k_from_n(
53-
idx_agent, m, network.n_agents(), contacted_agents,
54-
gen ); // now contacted_agents contains the indices of the contacted agents
50+
51+
// Implement the weight for the probability of agent `idx_agent` contacting agent `j`
52+
// Not normalised since, this is taken care of by the reservoir sampling
53+
auto weight_callback = [idx_agent, this]( size_t j ) {
54+
if( idx_agent == j ) // The agent does not contact itself
55+
return 0.0;
56+
return std::pow(
57+
std::abs( this->agents[idx_agent].data.opinion - this->agents[j].data.opinion ), this->homophily );
58+
};
59+
60+
Seldon::reservoir_sampling_A_ExpJ( m, network.n_agents(), weight_callback, contacted_agents, gen );
5561

5662
// Fill the outgoing edges into the reciprocal edge buffer
5763
for( const auto & idx_outgoing : contacted_agents )

0 commit comments

Comments
 (0)