Skip to main content

A module capable of simulating the spreading of an opinon in a given network using the Friedkin-Johnsen model.

Project description

Friedkin-Johnsen-model-simulator

A module capable of simulating the spreading of an opinon in a given network using the Friedkin-Johnsen model.

Table of contents

Requirements

  • Python 3.9.10 or higher
  • Numpy 1.25.0 or higher

Installation

Clone the repository:

git clone https://github.com/Giorgio-ctrl/Friedkin-Johnsen-model-simulator.git

or install via pip:

python -m pip install FJsim

Usage

model = Friedkin_Johnsen(weight, influence)
  • weight is the stochastic weighed adjacency matrix of the network (each element aij is the influence of node j on node i)
  • influence is the matrix where each diagonal element is how much a node is influenced by others and all the other entries are 0
model.simulate(initial)
  • initial is the nx1 vector of the original opions of each node

This code altogether returns the opinions that the system converges to or -1 if they don't converge.

Example

weight = numpy.array([
              [0.220, 0.120, 0.360, 0.300],
              [0.147, 0.215, 0.344, 0.294],
              [0.000, 0.000, 1.000, 0.000],
              [0.090, 0.178, 0.446, 0.286]
              ])
influence = numpy.diag([0.780, 0.785, 0, 0.714])
initial = numpy.transpose([25, 25, 75, 85])

model = Friedkin_Johnsen(weight, influence)
print(model.simulate(initial)

This code will print:

[60.02084883 59.98396594 75.         74.98620494]

Which is exactly the vector of the opinions once they converge.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fjsim-1.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fjsim-1.1-py3-none-any.whl (2.5 kB view details)

Uploaded Python 3

File details

Details for the file fjsim-1.1.tar.gz.

File metadata

  • Download URL: fjsim-1.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.13

File hashes

Hashes for fjsim-1.1.tar.gz
Algorithm Hash digest
SHA256 04bc793b4d5adb0bbf37f39dc65b3be3fad9b2b863d4e928d889cb6e0ac3ad18
MD5 24e36f1b1eccdaff0f954a1cede847fd
BLAKE2b-256 cbd89edbf4e51b3f822ef0e42f28c5e4a5ec2bb9959b69dd9a59f1003fcbebf3

See more details on using hashes here.

File details

Details for the file fjsim-1.1-py3-none-any.whl.

File metadata

  • Download URL: fjsim-1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.13

File hashes

Hashes for fjsim-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2eb4e82f29c2b7da609b3ee3665d98ec426342d6c6b416d32a94b5ca53a90813
MD5 d6b50d6f629313667301d7e38e1e37e2
BLAKE2b-256 dd8bec9d8b4896af6edb5ba9f7fa1d48c6bcbcd89e515f1b165b85b3bc5b6612

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page