# 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](https://pip.pypa.io/en/stable/) to install InfluenceDiffusion.
```bash
pip install InfluenceDiffusion
```
## Usage
```python
# 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.
Raw data
{
"_id": null,
"home_page": null,
"name": "InfluenceDiffusion",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python, Influence Maximization, Network diffusion models, General Linear Threshold model, Social Networks, Independent Cascade model",
"author": "Alexander Kagan",
"author_email": "<amkagan@umich.edu>",
"download_url": "https://files.pythonhosted.org/packages/28/49/7c4a4f535f79a221ff1084a3c5e13135b775918fca7d17b317785488638f/influencediffusion-0.0.13.tar.gz",
"platform": null,
"description": "\n# InfluenceDiffusion\n\nInfluenceDiffusion is a Python library that provides instruments for working with influence diffusion models on graphs. In particular, it contains implementations of\n- Popular diffusion models such as Independent Cascade, (General) Linear Threshold, etc. \n- Methods for estimating parameters of these models\n\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install InfluenceDiffusion.\n\n```bash\npip install InfluenceDiffusion\n```\n\n## Usage\n\n```python\n# Imports\nimport matplotlib.pyplot as plt\nfrom networkx import erdos_renyi_graph\n\nfrom InfluenceDiffusion.Graph import Graph # class inheriting from nx.DiGraph\nfrom InfluenceDiffusion.influence_models import LTM \nfrom InfluenceDiffusion.estimation_models.EMEstimation import LTWeightEstimatorEM \nfrom InfluenceDiffusion.weight_samplers import make_random_weights_with_indeg_constraint\n\n# Sample an Erdos-Renyi graph \ng_nx = erdos_renyi_graph(50, p=0.1, directed=True)\ng = Graph(edge_list=g_nx.edges)\n\n# Set ground-truth LT model edge weights (in-degree of each node is at most 1)\nweights = make_random_weights_with_indeg_constraint(g, indeg_ub=1)\ng.set_weights(weights)\n\n# Sample traces from an LT model on this graph\nltm = LTM(g)\ntraces = ltm.sample_traces(1000)\n\n# Estimate the weights using the traces\nltm_estimator = LTWeightEstimatorEM(g)\npred_weights = ltm_estimator.fit(traces)\n\n# Compare with the ground-truth weights\nplt.scatter(weights, pred_weights)\nplt.plot([0, 1], [0, 1], linestyle='--', c='black')\nplt.xlabel(\"True weights\")\nplt.ylabel(\"Predicted weights\")\nplt.show()\n```\n\n## License\n\nMIT License\n\nCopyright (c) 2024 Alexander Kagan\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
"bugtrack_url": null,
"license": null,
"summary": "InfluenceDiffusion package",
"version": "0.0.13",
"project_urls": null,
"split_keywords": [
"python",
" influence maximization",
" network diffusion models",
" general linear threshold model",
" social networks",
" independent cascade model"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6aab65d9d514d956bd44df2a72c38d78873688f73373defc4cf573c1e2ef10b9",
"md5": "342d13001e2bdc63342ed2603caef39d",
"sha256": "a6d7dc38aabf00b255a3e4de7b4be63f083f8551627c0e3159df8373e69644b7"
},
"downloads": -1,
"filename": "InfluenceDiffusion-0.0.13-py3-none-any.whl",
"has_sig": false,
"md5_digest": "342d13001e2bdc63342ed2603caef39d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 22917,
"upload_time": "2024-11-14T22:45:05",
"upload_time_iso_8601": "2024-11-14T22:45:05.803274Z",
"url": "https://files.pythonhosted.org/packages/6a/ab/65d9d514d956bd44df2a72c38d78873688f73373defc4cf573c1e2ef10b9/InfluenceDiffusion-0.0.13-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "28497c4a4f535f79a221ff1084a3c5e13135b775918fca7d17b317785488638f",
"md5": "91425d8bbcf7eebcd674f1299920cbf9",
"sha256": "22728a6ca996c452dfc9c22c25e28713672bcd5b62c8d682676d8bbde1cddb18"
},
"downloads": -1,
"filename": "influencediffusion-0.0.13.tar.gz",
"has_sig": false,
"md5_digest": "91425d8bbcf7eebcd674f1299920cbf9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17585,
"upload_time": "2024-11-14T22:45:07",
"upload_time_iso_8601": "2024-11-14T22:45:07.466648Z",
"url": "https://files.pythonhosted.org/packages/28/49/7c4a4f535f79a221ff1084a3c5e13135b775918fca7d17b317785488638f/influencediffusion-0.0.13.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-14 22:45:07",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "influencediffusion"
}