hypercontagion.sim.opinions

Opinion formation models on hypergraphs.

Functions

hypercontagion.sim.opinions.simulate_random_group_continuous_state_1D(H, initial_states, function=<function deffuant_weisbuch>, tmin=0, tmax=100, dt=1, **args)[source]

Simulate an opinion formation process where states are continuous and random groups are chosen.

Parameters
  • H (xgi.Hypergraph) – the hypergraph of interest

  • initial_states (numpy array) – initial node states

  • function (update function, default: deffuant_weisbuch) – node update function

  • tmin (int, default: 0) – the time at which the simulation starts

  • tmax (int, default: 100) – the time at which the simulation terminates

  • dt (float > 0, default: 1) – the time step to take.

Returns

a 1D array of the times and a 2D array of the states.

Return type

numpy array, numpy array

hypercontagion.sim.opinions.simulate_random_node_and_group_discrete_state(H, initial_states, function=<function voter_model>, tmin=0, tmax=100, dt=1, **args)[source]

Simulate an opinion formation process where states are discrete and states are updated synchronously.

Parameters
  • H (xgi.Hypergraph) – the hypergraph of interest

  • initial_states (numpy array) – initial node states

  • function (update function, default: deffuant_weisbuch) – node update function

  • tmin (int, default: 0) – the time at which the simulation starts

  • tmax (int, default: 100) – the time at which the simulation terminates

  • dt (float > 0, default: 1) – the time step to take.

Returns

a 1D array of the times and a 2D array of the states.

Return type

numpy array, numpy array

hypercontagion.sim.opinions.synchronous_update_continuous_state_1D(H, initial_states, function=<function hegselmann_krause>, tmin=0, tmax=100, dt=1, **args)[source]

Simulate an opinion formation process where states are continuous and states are updated synchronously.

Parameters
  • H (xgi.Hypergraph) – the hypergraph of interest

  • initial_states (numpy array) – initial node states

  • function (update function, default: deffuant_weisbuch) – node update function

  • tmin (int, default: 0) – the time at which the simulation starts

  • tmax (int, default: 100) – the time at which the simulation terminates

  • dt (float > 0, default: 1) – the time step to take.

Returns

a 1D array of the times and a 2D array of the states.

Return type

numpy array, numpy array

hypercontagion.sim.opinions.hegselmann_krause(H, status, epsilon=0.1)[source]

The Hegselmann-Krause model.

Parameters
  • H (xgi.Hypergraph) – the hypergraph of interest

  • status (iterable) – statuses of the nodes.

  • epsilon (float, default: 0.1) – confidence bound

Returns

new opinions

Return type

iterable

hypercontagion.sim.opinions.deffuant_weisbuch(edge, status, epsilon=0.5, update='average', m=0.1)[source]

the deffuant weisbuch model for updating the statuses of nodes in an edge

Parameters
  • edge (iterable) – list of nodes

  • status (numpy array) – node statuses

  • epsilon (float, default) – confidence bound

  • update (str, default: "average") – if “average” the opinions of all nodes in the hyperedge are updated to the average. If “cautious”, the nodes are moved toward the average.

  • m (float between 0 and 1, default: 0.1) – the fraction of the possible distance to move the node opinions to the centroid.

Returns

the updated statuses

Return type

iterable

hypercontagion.sim.opinions.discordance(edge, status)[source]

Computes the discordance of a hyperedge.

Parameters
  • edge (tuple) – a list of an edge’s members

  • status (numpy array) – opinions of the nodes

Returns

discordance of the hyperedge

Return type

float

hypercontagion.sim.opinions.voter_model(node, edge, status, p_adoption=1)[source]

the voter model given a hyperedge

Parameters
  • node (hashable) – node whose opinion may change

  • edge (iterable) – a list of the members of a hyperedge. must include the node.

  • status (dict) – keys are node IDs, statuses are values

  • p_adoption (float, default: 1) – probability that the node will adopt the consensus.

Returns

new node status

Return type

str