{ "info": { "author": "Benjamin F. Maier", "author_email": "bfmaier@physik.hu-berlin.de", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3" ], "description": "thresholdmodel\n==============\n\nSimulate a continuous-time threshold model on static networks using\nGillespie's stochastic simulation algorithm (SSA). The networks can be\ndirected and/or weighted.\n\nIn contrast to the original discrete-time model, nodes whose aggregated\ninputs exceed their respective thresholds will not flip after the \"next\ntime step\" because there are no time steps. Instead, a node whose\nthreshold has been exceeded will enter an alert state from which it will\nenter the activated state with rate $\\gamma = 1$.\n\nInstall\n-------\n\n::\n\n pip install thresholdmodel\n\nExample\n-------\n\nSimulate on an ER random graph.\n\n.. code:: python\n\n import numpy as np\n import networkx as nx\n import matplotlib.pyplot as plt\n\n from thresholdmodel import ThreshModel\n\n N = 1000\n k = 10\n\n thresholds = 0.1\n initially_activated = np.arange(100)\n\n G = nx.fast_gnp_random_graph(N, k/(N-1.0))\n\n Thresh = ThreshModel(G,initially_activated,thresholds)\n t, cascade_size = Thresh.simulate()\n\n plt.plot(t,cascade_size)\n plt.show()\n\n|trajectory|\n\nAPI\n---\n\nSimulate\n~~~~~~~~\n\nGiven a networkx-Graph object ``G`` (can be a ``networkx.DiGraph``,\ntoo), and values for ``initially_activated`` and ``thresholds``,\nsimulate like this\n\n.. code:: python\n\n Thresh = ThreshModel(G,initially_activated,thresholds)\n t, a = Thresh.simulate()\n\n``t`` is a ``numpy.ndarray`` containing the times at which node\nactivations happened. ``a`` is a ``numpy.ndarray`` containing the\nrelative cascade size at the corresponding time in ``t``. Note that the\nwhole process is modeled as a Poisson process such that the time ``t``\nwill be given in units of the node activation rate ``gamma = 1.0``. If\nyou want to simulate for another node activation rate, simply rescale\ntime as ``t /= gamma``.\n\nWhen the simulation is started with the ``save_activated_nodes=True``\nflag, a list of activated nodes per time leap is saved in\n``ThreshModel.activated_nodes``.\n\n.. code:: python\n\n t, a = Thresh.simulate(save_activated_nodes=True)\n print(Thresh.activated_nodes)\n\nYou can repeat a simulation with the same initial conditions by simply\ncalling ``Thresh.simulate()`` again, all the necessary things will be\nreset automatically.\n\nSet initially activated nodes\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nSet nodes 3, 5, and 8 to be activated initially.\n\n.. code:: python\n\n initially_activated = [3, 5, 8] # this could also be a numpy array\n\nChoose 20% of all nodes randomly to be activated initially. When the\nsimulation is restarted, the same nodes will be chosen as initial\nconditions.\n\n.. code:: python\n\n initially_activated = 0.2\n\nChoose 35 randomly selected nodes to be activated initially. When the\nsimulation is restarted, the same nodes will be chosen as initial\nconditions.\n\n.. code:: python\n\n initially_activated = 35\n\nSet thresholds\n~~~~~~~~~~~~~~\n\nActivation thresholds can be set for all nodes\n\n.. code:: python\n\n thresholds = np.random.rand(G.number_of_nodes()) \n\nNote that thresholds need to lie in the domain ``[0,1]``.\n\nYou can also set a universal threshold\n\n.. code:: python\n\n thresholds = 0.1\n\nHere, 10% of a node's neighbors need to be activated in order for the\nnode to become active, too.\n\nDirected networks\n~~~~~~~~~~~~~~~~~\n\nA node will become active if the sufficient number of nodes pointing\n*towards* the node are active. This means that a node's in-degree will\nbe the important measure to determine wether this particular node will\nbecome active.\n\nWeighted networks\n~~~~~~~~~~~~~~~~~\n\nIf you want to simulate on a weighted network, provide the ``weight``\nkeyword\n\n.. code:: python\n\n Thresh = ThreshModel(G,initially_activated,thresholds,weight='weight')\n\nSimilar to the networkx-documentation: ``weight`` (string, optional\n(default=\\ ``None``)) - The attribute name to obtain the edge weights.\nE.g.: ``G.edges[0,1]['weight']``.\n\nA focal node will become active when the cumulative edge weights of all\nactivated nodes pointing towards the focal node will reach\n``> threshold*in_degree``.\n\nDocstring\n---------\n\nThis is the model's docstring.\n\n::\n\n >>> help(ThreshModel)\n Help on class ThreshModel in module thresholdmodel.model:\n\n class ThreshModel(builtins.object)\n | ThreshModel(G, initially_activated, thresholds, weight=None)\n |\n | A simple simulation class that runs\n | a threshold-model activation process\n | on a static network (potentially weighted and directed)\n | in continuous time using Gillespie's\n | stochastic simulation algorithm.\n |\n | The temporal dimension is fixed by assuming\n | that every node whose activation threshold\n | has been exceeded by neighboring inputs\n | is activated with constant and uniform\n | rate :math:`\\gamma = 1`.\n |\n | Parameters\n | ==========\n | G : networkx.Graph, networkx.DiGraph\n | The network on which to simulate.\n | Nodes must be integers in the range\n | of ``[0, N-1]``.\n | initially_activated: float, int, or list of ints\n | Can be either of three things:\n |\n | 1. float of value ``0 < initially_activated < 1``.\n | In this case, ``initially_activated`` is\n | interpreted to represent a fraction of nodes\n | that will be randomly selected from the\n | set of nodes and set to be activated.\n | 2. int of value ``1 <= initially_activated < N-1``.\n | In this case, ``initially_activated`` nodes\n | will be randomly sampled from the node set\n | and set to be activated.\n | 3. list of ints. In this case, ``initially_activated``\n | is interpreted to contain indices of nodes\n | that will be activated initially.\n | thresholds: float or iterable of floats\n | Can be either of two things:\n |\n | 1. float of value ``0 < thresholds <= 1``.\n | In this case, every node will have the same\n | activation threshold.\n | 2. iterable of values ``0 < thresholds <=1``.\n | In this case, the function expectes a list,\n | tuple, or array with length equal to the\n | number of nodes. Each entry `m` of this list\n | will be interpreted to be node `m`'s activation\n | threshold.\n | weight: str, default = None\n | A string that represents the weight keyword of a link.\n | If `None`, the network is assumed to be unweighted.\n |\n | Example\n | =======\n |\n | >>> G = nx.fast_gnp_random_graph(1000,20/(1000-1))\n | >>> model = TreshModel(G, 100, 0.1)\n | >>> t, cascade_size = model.simulate()\n |\n | Attributes\n | ==========\n | G : nx.Graph or nx.DiGraph\n | The network on which to simulate.\n | Nodes must be integers in the range\n | of ``[0, N-1]``.\n | N : int\n | The number of nodes in the network\n | weight: str\n | A string that represents the weight keyword of a link.\n | If `None`, the network is assumed to be unweighted.\n | in_deg : numpy.ndarray\n | Contains the in-degree of every node.\n | thresholds: numpy.ndarray\n | Each entry `m` of this array\n | represents node `m`'s activation\n | threshold.\n | initially_activated: numpy.ndarray\n | Each entry of this array contains\n | a node that will be activated initially.\n | time: numpy.ndarray\n | Contains every time point at which a node was\n | activates (after ``simulation()`` was called).\n | The temporal dimension is given by assuming\n | that every node whose activation threshold\n | has been exceeded by activation inputs\n | is activated with constant and uniform\n | rate :math:`\\gamma = 1`.\n | cascade_size: numpy.ndarray\n | The relative size of the activation cascade\n | at the corrsponding time value in ``time``\n | (relative to the size of the node set).\n | Only available after ``simulation()`` was called.\n | activated_nodes: list\n | A list of lists.\n | Each entry contains a list of integers representing\n | the nodes that have been activated\n | at the corrsponding time value in ``time``.\n | Each list entry will contain only a single node\n | for every other time than the initial time.\n | Only available after ``simulation()`` was called.\n |\n | Methods defined here:\n |\n | __init__(self, G, initially_activated, thresholds, weight=None)\n | Initialize self. See help(type(self)) for accurate signature.\n |\n | reset(self)\n | Reset the simulation.\n |\n | set_initially_activated(self, initially_activated)\n | Set the process's initial activation state.\n |\n | Parameters\n | ==========\n | initially_activated: float, int, or list of ints\n | Can be either of three things:\n |\n | 1. float of value ``0 < initially_activated < 1``.\n | In this case, ``initially_activated`` is\n | interpreted to represent a fraction of nodes\n | that will be randomly selected from the\n | set of nodes and set to be activated.\n | 2. int of value ``1 <= initially_activated < N-1``.\n | In this case, ``initially_activated`` nodes\n | will be randomly sampled from the node set\n | and set to be activated.\n | 3. list of ints. In this case, ``initially_activated``\n | is interpreted to contain indices of nodes\n | that will be activated initially.\n |\n | set_thresholds(self, thresholds)\n | Set node activation thresholds.\n |\n | Parameters\n | ==========\n | thresholds: float or iterable of floats\n | Can be either of two things:\n |\n | 1. float of value ``0 < thresholds <= 1``.\n | In this case, every node will have the same\n | activation threshold.\n | 2. iterable of values ``0 < thresholds <=1``.\n | In this case, the function expectes a list,\n | tuple, or array with length equal to the\n | number of nodes. Each entry `m` of this list\n | will be interpreted to be node `m`'s activation\n | threshold.\n |\n | simulate(self, save_activated_nodes=False)\n | Simulate until all nodes that can be activated\n | have been activated.\n |\n | Parameters\n | ==========\n | save_activated_nodes: bool, default = False\n | If ``True``, write a list of activated nodes\n | to the class attribute ``activated_nodes``\n | every time an activation event happens.\n | Such a list will contain only a single node\n | for every other time than the initial time.\n |\n | Returns\n | =======\n | time : numpy.ndarray\n | Time points at which nodes were activated.\n | cascade_size : numpy.ndarray\n | The relative size of the activation cascade\n | at the corrsponding time value in ``time``\n | (relative to the size of the node set).\n\n.. |trajectory| image:: https://github.com/benmaier/thresholdmodel/raw/master/sandbox/cascade_trajectory.png", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/benmaier/thresholdmodel", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "thresholdmodel", "package_url": "https://pypi.org/project/thresholdmodel/", "platform": "", "project_url": "https://pypi.org/project/thresholdmodel/", "project_urls": { "Homepage": "https://github.com/benmaier/thresholdmodel" }, "release_url": "https://pypi.org/project/thresholdmodel/0.0.3/", "requires_dist": null, "requires_python": "", "summary": "Simulate a continuous-time threshold model on static networks.", "version": "0.0.3", "yanked": false, "yanked_reason": null }, "last_serial": 8940595, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "4147578474a335572500c1ce4016ab40", "sha256": "535834a241c78ddc9b9b1fe3acfba68281a30b0fa86f7ca1de68e1d2a9fe5938" }, "downloads": -1, "filename": "thresholdmodel-0.0.0.tar.gz", "has_sig": false, "md5_digest": "4147578474a335572500c1ce4016ab40", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5126, "upload_time": "2019-10-23T18:04:05", "upload_time_iso_8601": "2019-10-23T18:04:05.585512Z", "url": "https://files.pythonhosted.org/packages/01/2c/bb81acc8a32bb8e36d8c15dc6d89b1cfa8346a5077a025608e0d1f604b8f/thresholdmodel-0.0.0.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.1": [ { "comment_text": "", "digests": { "md5": "f2e911a7966daf38f8e6267caee8485f", "sha256": "e43a4e9a2811084ec562dd09816259131b1faf7d36d58d46863d92fc3b8af272" }, "downloads": -1, "filename": "thresholdmodel-0.0.1.tar.gz", "has_sig": false, "md5_digest": "f2e911a7966daf38f8e6267caee8485f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9144, "upload_time": "2020-10-13T19:09:55", "upload_time_iso_8601": "2020-10-13T19:09:55.278819Z", "url": "https://files.pythonhosted.org/packages/3f/17/5bea27d833460148c43afd852bddcd437320921bd9f1edf3259636c87ca9/thresholdmodel-0.0.1.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "b2bbc793a74c8a48f1553a8fb58e47aa", "sha256": "7622708c193d6750f7b1353c3e9e38366ef9fc3081e37b5671e066fcd9a5fa8a" }, "downloads": -1, "filename": "thresholdmodel-0.0.2.tar.gz", "has_sig": false, "md5_digest": "b2bbc793a74c8a48f1553a8fb58e47aa", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9150, "upload_time": "2020-10-13T19:14:40", "upload_time_iso_8601": "2020-10-13T19:14:40.695049Z", "url": "https://files.pythonhosted.org/packages/9f/97/929d6dc7f74b01215bad144601d39842784250a1d0643719caddea1a3ed8/thresholdmodel-0.0.2.tar.gz", "yanked": false, "yanked_reason": null } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "af330af066cb674a659529384ec08fbd", "sha256": "2d65e6966f0c528bccea80c2e92a6e524f64b0321026606653b03def42067f60" }, "downloads": -1, "filename": "thresholdmodel-0.0.3.tar.gz", "has_sig": false, "md5_digest": "af330af066cb674a659529384ec08fbd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32116, "upload_time": "2020-12-19T12:09:46", "upload_time_iso_8601": "2020-12-19T12:09:46.490933Z", "url": "https://files.pythonhosted.org/packages/c2/c1/f5e6cb2516e66ebb851e2d1e9f4a826ce2fc5d3103f668c6d95595526f78/thresholdmodel-0.0.3.tar.gz", "yanked": false, "yanked_reason": null } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "af330af066cb674a659529384ec08fbd", "sha256": "2d65e6966f0c528bccea80c2e92a6e524f64b0321026606653b03def42067f60" }, "downloads": -1, "filename": "thresholdmodel-0.0.3.tar.gz", "has_sig": false, "md5_digest": "af330af066cb674a659529384ec08fbd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32116, "upload_time": "2020-12-19T12:09:46", "upload_time_iso_8601": "2020-12-19T12:09:46.490933Z", "url": "https://files.pythonhosted.org/packages/c2/c1/f5e6cb2516e66ebb851e2d1e9f4a826ce2fc5d3103f668c6d95595526f78/thresholdmodel-0.0.3.tar.gz", "yanked": false, "yanked_reason": null } ], "vulnerabilities": [] }