{"id":22680116,"url":"https://github.com/stdogpkg/stdog","last_synced_at":"2025-04-12T15:52:52.310Z","repository":{"id":57471310,"uuid":"140448116","full_name":"stdogpkg/stdog","owner":"stdogpkg","description":"The main goal of StDoG is to provide a package which can be used to study dynamical and structural properties (like spectra) on graphs with a large number of vertices. ","archived":false,"fork":false,"pushed_at":"2019-09-17T15:23:59.000Z","size":6302,"stargazers_count":8,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T17:52:45.538Z","etag":null,"topics":["complex-networks","eigenvalues","gpu","graph","kuramoto-model","spectral-analysis","tensorflow"],"latest_commit_sha":null,"homepage":"https://stdog.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stdogpkg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-10T14:54:25.000Z","updated_at":"2024-03-03T01:52:22.000Z","dependencies_parsed_at":"2022-09-10T02:11:42.946Z","dependency_job_id":null,"html_url":"https://github.com/stdogpkg/stdog","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stdogpkg%2Fstdog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stdogpkg%2Fstdog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stdogpkg%2Fstdog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stdogpkg%2Fstdog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stdogpkg","download_url":"https://codeload.github.com/stdogpkg/stdog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248592081,"owners_count":21130174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["complex-networks","eigenvalues","gpu","graph","kuramoto-model","spectral-analysis","tensorflow"],"created_at":"2024-12-09T19:12:17.953Z","updated_at":"2025-04-12T15:52:52.291Z","avatar_url":"https://github.com/stdogpkg.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![](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/source/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 estimate 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/source/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 \u003e 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., \u0026 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élica 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)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstdogpkg%2Fstdog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstdogpkg%2Fstdog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstdogpkg%2Fstdog/lists"}