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.0.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.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fjsim-1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 2bb6b1ef173f95fa1e6601620884a329ee40f4332d10dc39e37d019f03c1f318
MD5 711de9d5d8886cd558b9676f95c85f18
BLAKE2b-256 a3c465ea958ea321927d7f4dca11391e8a50e80c8ea64412d1805814286b4504

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fjsim-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d20f8bc762fb5df425a56f51570d61c1b009e3581c26e8031ab7db2a838ddaf8
MD5 624d9031677431868e3c4c8f4b07247a
BLAKE2b-256 8b910dc3041b1e33e4444cdde176e062361266c76fec0fe133b8116de7009dbe

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