{ "info": { "author": "Bruno Messias; Thomas K. Peron", "author_email": "messias.physics@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Topic :: Scientific/Engineering :: Information Analysis", "Topic :: Scientific/Engineering :: Mathematics", "Topic :: Scientific/Engineering :: Physics" ], "description": "# ![](docs/source/imgs/stdog.png) \n# Structure and Dynamics on Graphs (Beta)\n\nThe main goal of StDoG is to provide a package which can be used to study\ndynamical and structural properties (like spectra) on graphs with a large\nnumber of vertices. The modules of StDoG are being built by\ncombining codes written in *Tensorflow* + *CUDA* and *C++*.\n\n## 1 - Install\n\n```\npip install stdog\n```\n\n## 2 - Examples\n\n### 2.1 - Dynamics\n\n#### 2.1.1 - Kuramoto\n\n##### Tensorflow\n```python\nimport numpy as np\nimport igraph as ig\nfrom stdog.utils.misc import ig2sparse #Function to convert igraph format to sparse matrix\n\n\nnum_couplings = 40\nN = 20480\n\nG = ig.Graph.Erdos_Renyi(N, 3/N)\nadj = ig2sparse(G)\n\nomegas = np.random.normal(size= N).astype(\"float32\")\ncouplings = np.linspace(0.0,4.,num_couplings)\nphases = np.array([\n np.random.uniform(-np.pi,np.pi,N)\n for i_l in range(num_couplings)\n\n],dtype=np.float32)\n\n\nprecision =32\n\ndt = 0.01\nnum_temps = 50000\ntotal_time = dt*num_temps\ntotal_time_transient = total_time\ntransient = False\n```\n\n```python\nfrom stdog.dynamics.kuramoto import Heuns\n\nheuns_0 = Heuns(adj, phases, omegas, couplings, total_time, dt, \n device=\"/gpu:0\", # or /cpu:\n precision=precision, transient=transient)\n\nheuns_0.run()\nheuns_0.transient = True\nheuns_0.total_time = total_time_transient\nheuns_0.run()\norder_parameter_list = heuns_0.order_parameter_list # (num_couplings, total_time//dt)\n```\n```python\nimport matplotlib.pyplot as plt\n\nr = np.mean(order_parameter_list, axis=1)\nstdr = np.std(order_parameter_list, axis=1)\n\nplt.ion()\nfig, ax1 = plt.subplots()\nax1.plot(couplings,r,'.-')\nax2 = ax1.twinx()\nax2.plot(couplings,stdr,'r.-')\nplt.show()\n```\n![](docs/imgs/heuns_tf.png)\n\n#### CUDA - Faster than Tensorflow implementation\n\nIf CUDA is available. You can install our another package,\n[stdogpkg/cukuramoto](https://github.com/stdogpkg/cukuramoto) (C)\n```\npip install cukuramoto\n```\n\n```python\nfrom stdog.dynamics.kuramoto.cuheuns import CUHeuns as cuHeuns\n\nheuns_0 = cuHeuns(adj, phases, omegas, couplings,\n total_time, dt, block_size = 1024, transient = False)\n\nheuns_0.run()\n\nheuns_0.transient = True\nheuns_0.total_time = total_time_transient\nheuns_0.run()\norder_parameter_list = heuns_0.order_parameter_list #\n```\n### 2.2 Spectral \n\n#### Spectral Density\n\nThe Kernel Polynomial Method [1] can\u00a0estimate the spectral density of large sparse Hermitan matrices with a computational cost almost linear. This method combines three key ingredients: the Chebyshev expansion + the stochastic trace estimator [2] + kernel smoothing.\n\n```python\nimport igraph as ig\nimport numpy as np\n\nN = 3000\nG = ig.Graph.Erdos_Renyi(N, 3/N)\n\nW = np.array(G.get_adjacency().data, dtype=np.float64)\nvals = np.linalg.eigvalsh(W).real\n```\n\n```python\nimport stdog.spectra as spectra\nfrom stdog.utils.misc import ig2sparse \n\nW = ig2sparse(G)\nnum_moments = 300\nnum_vecs = 200\nextra_points = 10\nek, rho = spectra.dos.kpm(W, num_moments, num_vecs, extra_points, device=\"/gpu:0\")\n```\n\n```python\nimport matplotlib.pyplot as plt\nplt.hist(vals, density=True, bins=100, alpha=.9, color=\"steelblue\")\nplt.scatter(ek, rho, c=\"tomato\", zorder=999, alpha=0.9, marker=\"d\")\nplt.ylim(0, 1)\nplt.show()\n```\n![kpm](docs/imgs/kpm_dos.png)\n#### Trace Functions through Stochastic Lanczos Quadrature (SLQ)[3]\n\n\n##### Computing custom trace functions\n\n```python\nfrom stdog.spectra.trace_function import slq\nimport tensorflow as tf\n\ndef trace_function(eig_vals):\n return tf.exp(eig_vals)\n\nnum_vecs = 100\nnum_steps = 50\napproximated_estrada_index, _ = slq(L_sparse, num_vecs, num_steps, trace_function, device=\"/gpu:0\")\nexact_estrada_index = np.sum(np.exp(vals_laplacian))\napproximated_estrada_index, exact_estrada_index\n```\nThe above code returns\n\n```\n(3058.012, 3063.16457163222)\n```\n##### Entropy\n```python\nimport scipy\nimport scipy.sparse\nfrom stdog.spectra.trace_function import entropy as slq_entropy\n\ndef entropy(eig_vals):\n s = 0.\n for val in eig_vals:\n if val > 0:\n s += -val*np.log(val)\n return s\n\nL = np.array(G.laplacian(normalized=True), dtype=np.float64)\nvals_laplacian = np.linalg.eigvalsh(L).real\n\nexact_entropy = entropy(vals_laplacian)\n\nL_sparse = scipy.sparse.coo_matrix(L)\n \nnum_vecs = 100\nnum_steps = 50\napproximated_entropy = slq_entropy(\n L_sparse, num_vecs, num_steps, device=\"/cpu:0\")\n\napproximated_entropy, exact_entropy\n```\n```\n(-509.46283, -512.5283224633046)\n```\n\n## References\n\n1 - Wang, L.W., 1994. Calculating the density of states and\noptical-absorption spectra of large quantum systems by the plane-wave moments\nmethod. Physical Review B, 49(15), p.10154.\n\n2 - Hutchinson, M.F., 1990. A stochastic estimator of the trace of the\ninfluence matrix for laplacian smoothing splines. Communications in\nStatistics-Simulation and Computation, 19(2), pp.433-450.\n\n3 - Ubaru, S., Chen, J., & Saad, Y. (2017). Fast Estimation of tr(f(A)) via Stochastic Lanczos Quadrature. \nSIAM Journal on Matrix Analysis and Applications, 38(4), 1075-1099.\n\n\n## 3 - How to cite\n\n[Thomas Peron](https://tkdmperon.github.io/), [Bruno Messias](http://brunomessias.com/), Ang\u00e9lica S. Mata, [Francisco A. Rodrigues](http://conteudo.icmc.usp.br/pessoas/francisco/), and [Yamir Moreno](http://cosnet.bifi.es/people/yamir-moreno/). On the onset of synchronization of Kuramoto oscillators in scale-free networks. [arXiv:1905.02256](https://arxiv.org/abs/1905.02256) (2019).\n\n## 4 - Acknowledgements\n\nThis work has been supported also by FAPESP grants 11/50761-2 and 2015/22308-2. Research carriedout using the computational resources of the Center forMathematical Sciences Applied to Industry (CeMEAI)funded by FAPESP (grant 2013/07375-0).\n \n### Responsible authors\n\n[@devmessias](https://github.com/devmessias), [@tkdmperon](https://github.com/tkdmperon)", "description_content_type": "text/markdown", "docs_url": null, "download_url": "https://github.com/stdogpkg/stdog/archive/v1.0.4.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/stdogpkg/stdog", "keywords": "gpu,science,complex-networks,graphs,dynamics,tensorflow,kuramoto", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "stdog", "package_url": "https://pypi.org/project/stdog/", "platform": "", "project_url": "https://pypi.org/project/stdog/", "project_urls": { "Download": "https://github.com/stdogpkg/stdog/archive/v1.0.4.tar.gz", "Homepage": "https://github.com/stdogpkg/stdog" }, "release_url": "https://pypi.org/project/stdog/1.0.4/", "requires_dist": null, "requires_python": "", "summary": "Structure and Dynamics on Graphs", "version": "1.0.4" }, "last_serial": 5842052, "releases": { "1.0.1": [ { "comment_text": "", "digests": { "md5": "21e670ae4803d9d51cc226531c026da2", "sha256": "f7f5506aba23403eeab296302b19413b4e7597211f36d6c7f9cfdf8bf7e28888" }, "downloads": -1, "filename": "stdog-1.0.1.tar.gz", "has_sig": false, "md5_digest": "21e670ae4803d9d51cc226531c026da2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7812, "upload_time": "2019-09-02T22:38:22", "url": "https://files.pythonhosted.org/packages/d8/81/a50885522adc19d596920384354ce25e3a637a62501aee13b68973d7176c/stdog-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "a20aa01e4f16629b76f1a984cac938f0", "sha256": "3d72ce343d30886d6fb9cf52b9eb67997565580be0365072dbe7f27e4ab3116d" }, "downloads": -1, "filename": "stdog-1.0.2.tar.gz", "has_sig": false, "md5_digest": "a20aa01e4f16629b76f1a984cac938f0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8153, "upload_time": "2019-09-03T19:25:47", "url": "https://files.pythonhosted.org/packages/c2/01/1e1a4ce7cd6134c15f7904c7ad6f355617b58b38ef1ee112624514b974d3/stdog-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "44bb5de6e8a5a63df3ad20c5955100b3", "sha256": "05f9727eba7b1116a46568dc97bb94f5ca12f8c65d341b4be0a9e5bb9884e39d" }, "downloads": -1, "filename": "stdog-1.0.3.tar.gz", "has_sig": false, "md5_digest": "44bb5de6e8a5a63df3ad20c5955100b3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12318, "upload_time": "2019-09-11T23:42:32", "url": "https://files.pythonhosted.org/packages/ce/b0/c2a31688a2e9cfc3a3c5afdc0b81c98fc5b664599e7b21629c6ffb7f318b/stdog-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "6dca2e23cf209ae505326d9669788fdf", "sha256": "8cff1759ec437e8ec9ed4043c1fc6c874e8d2938d7234af8b5a9d4a72908cf21" }, "downloads": -1, "filename": "stdog-1.0.4.tar.gz", "has_sig": false, "md5_digest": "6dca2e23cf209ae505326d9669788fdf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35571, "upload_time": "2019-09-17T14:38:01", "url": "https://files.pythonhosted.org/packages/88/38/62d757768272ebab45689f1ac2565694bf734eca29fb8893d5d35e412c13/stdog-1.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6dca2e23cf209ae505326d9669788fdf", "sha256": "8cff1759ec437e8ec9ed4043c1fc6c874e8d2938d7234af8b5a9d4a72908cf21" }, "downloads": -1, "filename": "stdog-1.0.4.tar.gz", "has_sig": false, "md5_digest": "6dca2e23cf209ae505326d9669788fdf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 35571, "upload_time": "2019-09-17T14:38:01", "url": "https://files.pythonhosted.org/packages/88/38/62d757768272ebab45689f1ac2565694bf734eca29fb8893d5d35e412c13/stdog-1.0.4.tar.gz" } ] }