Skip to content

Commit

Permalink
Fixed nans in meanfield AD model
Browse files Browse the repository at this point in the history
  • Loading branch information
MSallermann committed Mar 1, 2024
1 parent 18a605f commit b5efc5d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/models/ActivityDrivenModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "util/math.hpp"
#include <cstddef>
#include <random>
#include <stdexcept>
#include <vector>

Seldon::ActivityAgentModel::ActivityAgentModel( int n_agents, Network & network, std::mt19937 & gen )
Expand Down Expand Up @@ -124,12 +123,12 @@ void Seldon::ActivityAgentModel::update_network_mean()
{
// Implement the weight for the probability of agent `idx_agent` contacting agent `j`
// Not normalised since this is taken care of by the reservoir sampling
auto weight_callback = [idx_agent, this]( size_t j )
{
if( idx_agent == j ) // The agent does not contact itself
auto weight_callback = [idx_agent, this]( size_t j ) {
constexpr double tolerance = 1e-16;
auto opinion_diff = std::abs( this->agents[idx_agent].data.opinion - this->agents[j].data.opinion );
if( opinion_diff < tolerance )
return 0.0;
return std::pow(
std::abs( this->agents[idx_agent].data.opinion - this->agents[j].data.opinion ), -this->homophily );
return std::pow( opinion_diff, -this->homophily );
};

double normalization = 0;
Expand Down

0 comments on commit b5efc5d

Please sign in to comment.