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
Installation
Use the package manager pip to install InfluenceDiffusion.
pip install InfluenceDiffusion
Usage
# Imports
import matplotlib.pyplot as plt
from networkx import erdos_renyi_graph
from InfluenceDiffusion.Graph import Graph # class inheriting from nx.DiGraph
from InfluenceDiffusion.influence_models import LTM
from InfluenceDiffusion.estimation_models.EMEstimation import LTWeightEstimatorEM
from InfluenceDiffusion.weight_samplers import make_random_weights_with_indeg_constraint
# Sample an Erdos-Renyi graph
g_nx = erdos_renyi_graph(50, p=0.1, directed=True)
g = Graph(edge_list=g_nx.edges)
# Set ground-truth LT model edge weights (in-degree of each node is at most 1)
weights = make_random_weights_with_indeg_constraint(g, indeg_ub=1)
g.set_weights(weights)
# Sample traces from an LT model on this graph
ltm = LTM(g)
traces = ltm.sample_traces(1000)
# Estimate the weights using the traces
ltm_estimator = LTWeightEstimatorEM(g)
pred_weights = ltm_estimator.fit(traces)
# Compare with the ground-truth weights
plt.scatter(weights, pred_weights)
plt.plot([0, 1], [0, 1], linestyle='--', c='black')
plt.xlabel("True weights")
plt.ylabel("Predicted weights")
plt.show()
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file influencediffusion-0.0.13.tar.gz
.
File metadata
- Download URL: influencediffusion-0.0.13.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22728a6ca996c452dfc9c22c25e28713672bcd5b62c8d682676d8bbde1cddb18 |
|
MD5 | 91425d8bbcf7eebcd674f1299920cbf9 |
|
BLAKE2b-256 | 28497c4a4f535f79a221ff1084a3c5e13135b775918fca7d17b317785488638f |
File details
Details for the file InfluenceDiffusion-0.0.13-py3-none-any.whl
.
File metadata
- Download URL: InfluenceDiffusion-0.0.13-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6d7dc38aabf00b255a3e4de7b4be63f083f8551627c0e3159df8373e69644b7 |
|
MD5 | 342d13001e2bdc63342ed2603caef39d |
|
BLAKE2b-256 | 6aab65d9d514d956bd44df2a72c38d78873688f73373defc4cf573c1e2ef10b9 |