Skip to main content

InfluenceDiffusion package

Project description

InfluenceDiffusion

InfluenceDiffusion is a Python library that provides instruments for working with influence diffusion models on graphs. In particular, it contains implementations of

  • Popular diffusion models such as Independent Cascade, (General) Linear Threshold, etc.
  • Methods for estimating parameters of these models and constructing the corresponding confidence intervals.

Installation

Use the package manager pip to install InfluenceDiffusion.

pip install InfluenceDiffusion

Usage

# Imports
import matplotlib.pyplot as plt
from networkx import connected_watts_strogatz_graph
from scipy.stats import beta

from InfluenceDiffusion.Graph import Graph # class inheriting from nx.DiGraph
from InfluenceDiffusion.Inference import GLTInferenceModule
from InfluenceDiffusion.influence_models import LTM
from InfluenceDiffusion.estimation_models.OptimEstimation import GLTWeightEstimator
from InfluenceDiffusion.weight_samplers import make_random_weights_with_indeg_constraint
from InfluenceDiffusion.plot_utils import plot_with_conf_intervals


# Sample a connected Watts-Strogatz graph
random_state = 1
g = Graph(connected_watts_strogatz_graph(n=100, k=5, p=0.2, seed=random_state))

# Set ground-truth GLT model edge weights (in-degree of each node is at most 1)
weights = make_random_weights_with_indeg_constraint(g, indeg_ub=1, random_state=random_state)
g.set_weights(weights)

# Sample traces from the Beta(2, 1)-GLT model on this graph
threhsold_distrib = beta(2, 1)
gltm = LTM(g, threshold_generator=threhsold_distrib, random_state=random_state)
traces = gltm.sample_traces(1000)

# Estimate the weights using the traces
gltm_estimator = GLTWeightEstimator(g, threhsold_distrib)
pred_weights = gltm_estimator.fit(traces)

# Compute 95% confidence intervals
glt_inferencer = GLTInferenceModule(gltm_estimator)
conf_ints = glt_inferencer.compute_all_weight_conf_ints(alpha=0.05)

# Compare with the ground-truth weights
plot_with_conf_intervals(weights, pred_weights, conf_ints,
                         xlab="True weights", ylab="Predicted weights")

License

MIT License

Copyright (c) 2024 Alexander Kagan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

influencediffusion-0.0.15.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

influencediffusion-0.0.15-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file influencediffusion-0.0.15.tar.gz.

File metadata

  • Download URL: influencediffusion-0.0.15.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for influencediffusion-0.0.15.tar.gz
Algorithm Hash digest
SHA256 7e5fedb0510d186ea3c58af458e6e6a77162c9307a59c5e9f9b2ded3d47d97bb
MD5 e449078d1b2b6fd610a5ed5dbd2c8f84
BLAKE2b-256 0b7c600020da89c70930d6d115e873f6af990e32298c1518fd6dc83759d687d6

See more details on using hashes here.

File details

Details for the file influencediffusion-0.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for influencediffusion-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 cf7534b8b1cb359683b8d92d1b52af3b1340ad81c3162dc103a33adc5efecd88
MD5 149e18628d571c33169da4096c8d753e
BLAKE2b-256 86835a814a0612667f6c60126c9eb12bef1dc41c1a9c0c51a33fc0946bce129b

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