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.12.tar.gz
.
File metadata
- Download URL: influencediffusion-0.0.12.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f45de22ebb685613d43efbadc5bdd6911284e7fefb5a25f0f98c0b6b746de770 |
|
MD5 | c542290168cbc1c0e7a3cae8a34a8b90 |
|
BLAKE2b-256 | 3258622ac218ab795bfb05e91336885ff942c05941dc5a3af8fd9b8a7d0f73cb |
File details
Details for the file InfluenceDiffusion-0.0.12-py3-none-any.whl
.
File metadata
- Download URL: InfluenceDiffusion-0.0.12-py3-none-any.whl
- Upload date:
- Size: 23.5 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 | b4ea3eede6fd43c6616c8135984cc5311366d8ed727777bebd756ea68ea4ba2a |
|
MD5 | 5a6e924b379cf24873030f97d7060f1f |
|
BLAKE2b-256 | 0af4c91105aae4874d7072f5d9e578f9c47fd7b031c44506348a3dbc9752f679 |