{"id":22680118,"url":"https://github.com/stdogpkg/emate","last_synced_at":"2025-04-12T15:52:53.712Z","repository":{"id":35097009,"uuid":"168193479","full_name":"stdogpkg/emate","owner":"stdogpkg","description":"eMaTe can estimate the spectral density and  trace functions even in matrices or graphs (undirected or directed)  with million of nodes. (kernel polynomial method and SLQ)","archived":false,"fork":false,"pushed_at":"2023-03-24T23:40:08.000Z","size":268,"stargazers_count":10,"open_issues_count":4,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T06:04:53.508Z","etag":null,"topics":["complex-networks","eigenvalues","graphs","kernel-polynomial-method","matrices","spectra","sthocastic-lanczos-quadrature"],"latest_commit_sha":null,"homepage":"https://emate.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,"governance":null}},"created_at":"2019-01-29T17:05:39.000Z","updated_at":"2023-08-19T20:45:48.000Z","dependencies_parsed_at":"2023-01-15T13:46:53.594Z","dependency_job_id":null,"html_url":"https://github.com/stdogpkg/emate","commit_stats":{"total_commits":98,"total_committers":1,"mean_commits":98.0,"dds":0.0,"last_synced_commit":"97965001e14d2c8689df99393036179cfec1124b"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stdogpkg%2Femate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stdogpkg%2Femate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stdogpkg%2Femate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stdogpkg%2Femate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stdogpkg","download_url":"https://codeload.github.com/stdogpkg/emate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248592085,"owners_count":21130175,"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","graphs","kernel-polynomial-method","matrices","spectra","sthocastic-lanczos-quadrature"],"created_at":"2024-12-09T19:12:20.076Z","updated_at":"2025-04-12T15:52:53.689Z","avatar_url":"https://github.com/stdogpkg.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ![eMaTe](emate.png)\n\neMaTe it is a python package which the main goal is to provide  methods capable of estimating the spectral densities and trace \nfunctions of large sparse matrices. eMaTe can run in both CPU and GPU and can estimate the spectral density and related trace functions, such as entropy and Estrada index, even in directed or undirected networks with million of nodes.\n\n\n## CITE\n\n[Characterization and comparison of large directed graphs through the spectra of the magnetic Laplacian](https://arxiv.org/abs/2007.03466)\n\n```\n@article{FdeResende2020,\n  doi = {10.1063/5.0006891},\n  url = {https://doi.org/10.1063/5.0006891},\n  year = {2020},\n  month = jul,\n  publisher = {{AIP} Publishing},\n  volume = {30},\n  number = {7},\n  pages = {073141},\n  author = {Bruno Messias F. de Resende and Luciano da F. Costa},\n  title = {Characterization and comparison of large directed networks through the spectra of the magnetic Laplacian},\n  journal = {Chaos: An Interdisciplinary Journal of Nonlinear Science}\n}\n```\n\n## Install                                                                                                              \n```\npip install emate\n```\n\nIf you a have a GPU you should also install cupy.\n## Kernel Polynomial Method (KPM)\n\nThe Kernel Polynomial Method 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 + kernel smoothing.\n\n\n### Example\n\n```python\nimport networkx as nx\nimport numpy as np\n\nn = 3000\ng = nx.erdos_renyi_graph(n , 3/n)\nW = nx.adjacency_matrix(g)\n\nvals  = np.linalg.eigvals(W.todense()).real\n```\n\n```python\nfrom emate.hermitian import tfkpm\n\n\nnum_moments = 40\nnum_vecs = 40\nextra_points = 10\nek, rho = tfkpm(W, num_moments, num_vecs, extra_points)\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\")\n\n```\nIf the CUPY package it is available in your machine, you can also use the cupy implementation. When compared to tf-kpm, the\nCupy-kpm is slower for median matrices (100k) and faster for larger matrices (\u003e 10^6). The main reason it's because the tf-kpm was implemented in order to calc all te moments in a single step. \n\n```python\nimport matplotlib.pyplot as plt\nfrom emate.hermitian import cupykpm\n\nnum_moments = 40\nnum_vecs = 40\nextra_points = 10\nek, rho = cupykpm(W.tocsr(), num_moments, num_vecs, extra_points)\nplt.hist(vals, density=True, bins=100, alpha=.9, color=\"steelblue\")\nplt.scatter(ek.get(), rho.get(), c=\"tomato\", zorder=999, alpha=0.9, marker=\"d\")\n```\n\n\n![](docs/source/imgs/kpm.png)\n\n## Stochastic Lanczos Quadrature (SLQ)\n\n\n\u003eThe problem of estimating the trace of matrix functions appears in applications ranging from machine learning and scientific computing, to computational biology.[2] \n\n### Example\n\n#### Computing the Estrada index\n\n```python\nfrom emate.symmetric.slq import pyslq\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, _ = pyslq(L_sparse, num_vecs, num_steps,  trace_function)\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\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\n\ndef trace_function(eig_vals):\n  def entropy(val):\n    return tf.cond(val\u003e0, lambda:-val*tf.log(val), lambda: 0.)\n  \n  return tf.map_fn(entropy, eig_vals)\n \nL_sparse = scipy.sparse.coo_matrix(L)\n    \nnum_vecs = 100\nnum_steps = 50\napproximated_entropy, _ = pyslq(L_sparse, num_vecs, num_steps,  trace_function)\n\napproximated_entropy, exact_entropy\n```\n```\n(-509.46283, -512.5283224633046)\n```\n[[1] Hutchinson, M. F. (1990). A stochastic estimator of the trace of the influence matrix for laplacian smoothing splines. Communications in Statistics-Simulation and Computation, 19(2), 433-450.](https://www.tandfonline.com/doi/abs/10.1080/03610919008812866)\n\n[[2] Ubaru, S., Chen, J., \u0026 Saad, Y. (2017). Fast Estimation of tr(f(A)) via Stochastic Lanczos Quadrature. SIAM Journal on Matrix Analysis and Applications, 38(4), 1075-1099.](https://epubs.siam.org/doi/abs/10.1137/16M1104974)\n\n[[3] The Kernel Polynomial Method applied to\ntight binding systems with\ntime-dependence]()\n\n\n \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstdogpkg%2Femate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstdogpkg%2Femate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstdogpkg%2Femate/lists"}