{"id":29275254,"url":"https://github.com/vdutor/sphericalharmonics","last_synced_at":"2025-07-05T06:08:26.362Z","repository":{"id":42127437,"uuid":"379265502","full_name":"vdutor/SphericalHarmonics","owner":"vdutor","description":"Zonal Spherical Harmonics in d Dimensions in TensorFlow, PyTorch and Jax","archived":false,"fork":false,"pushed_at":"2024-05-17T20:25:43.000Z","size":3598,"stargazers_count":33,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-04T23:07:39.620Z","etag":null,"topics":["jax","pytorch","spherical-harmonics","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vdutor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-22T12:41:42.000Z","updated_at":"2025-07-01T16:46:14.000Z","dependencies_parsed_at":"2024-05-17T21:45:36.494Z","dependency_job_id":null,"html_url":"https://github.com/vdutor/SphericalHarmonics","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/vdutor/SphericalHarmonics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdutor%2FSphericalHarmonics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdutor%2FSphericalHarmonics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdutor%2FSphericalHarmonics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdutor%2FSphericalHarmonics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vdutor","download_url":"https://codeload.github.com/vdutor/SphericalHarmonics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vdutor%2FSphericalHarmonics/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263692913,"owners_count":23496944,"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":["jax","pytorch","spherical-harmonics","tensorflow"],"created_at":"2025-07-05T06:08:25.797Z","updated_at":"2025-07-05T06:08:26.355Z","avatar_url":"https://github.com/vdutor.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spherical Harmonics\n\nThis package implements spherical harmonics in d-dimensions in Python. The spherical harmonics are defined as zonal functions through the Gegenbauer polynomials and a fundamental system of points (see [Dai and Xu (2013)](https://arxiv.org/pdf/1304.2585.pdf), defintion 3.1). The spherical harmonics form a ortho-normal set on the hypersphere. This package implements a greedy algorithm to compute the fundamental set for dimensions up to 20.\n\nThe computations of this package can be carried out in either TensorFlow, Pytorch, Jax or NumPy.\nA specific backend can be chosen by simply importing it as follows\n```\nimport spherical_harmonics.tensorflow  # noqa\n```\n\n## Example\n\n### 3 Dimensional\n```python\nimport tensorflow as tf\nimport spherical_harmonics.tensorflow  # run computation in TensorFlow\n\nfrom spherical_harmonics import SphericalHarmonics\nfrom spherical_harmonics.utils import l2norm\n\ndimension = 3\nmax_degree = 10\n# Returns all the spherical harmonics in dimension 3 up to degree 10.\nPhi = SphericalHarmonics(dimension, max_degree)\n\nx = tf.random.normal((101, dimension))  # Create random points to evaluate Phi\nx = x / tf.norm(x, axis=1, keepdims=True)  # Normalize vectors\nout = Phi(x)  # Evaluate spherical harmonics at `x`\n\n# In 3D there are (2 * degree + 1) spherical harmonics per degree,\n# so in total we have 400 spherical harmonics of degree 20 and smaller.\nnum_harmonics = 0\nfor degree in range(max_degree):\n    num_harmonics += 2 * degree + 1\nassert num_harmonics == 100\n\nassert out.shape == (101, num_harmonics)\n```\n\n### 4 Dimensional\n\nThe setup for 4 dimensional spherical harmonics is very similar to the 3D case. Note that there are more spherical harmonics now of degree smaller than 20.\n\n```python\nimport numpy as np\nfrom spherical_harmonics import SphericalHarmonics\nfrom spherical_harmonics.utils import l2norm\n\ndimension = 4\nmax_degree = 10\n# Returns all the spherical harmonics of degree 4 up to degree 10.\nPhi = SphericalHarmonics(dimension, max_degree)\n\nx = np.random.randn(101, dimension)  # Create random points to evaluation Phi\nx = x / l2norm(x)  # normalize vectors\nout = Phi(x)  # Evaluate spherical harmonics at `x`\n\n# In 4D there are (degree + 1)**2 spherical harmonics per degree,\n# so in total we have 385 spherical harmonics of degree 20 and smaller.\nnum_harmonics = 0\nfor degree in range(max_degree):\n    num_harmonics += (degree + 1) ** 2\nassert num_harmonics == 385\n\nassert out.shape == (101, num_harmonics)\n```\n\n---\n**NOTE**\n\nThe fundamental systems up to dimensions 20 are precomputed and stored in `spherical_harmonics/fundamental_system`. For each dimension we precompute the first amount of spherical harmonics. This means that in each dimension we support a varying number of maximum degree (`max_degree`) and number of spherical harmonics:\n\n| Dimension | Max Degree | Number Harmonics |\n|----------:|-----------:|-----------------:|\n|         3 |         34 |             1156 |\n|         4 |         20 |             2870 |\n|         5 |         10 |             1210 |\n|         6 |          8 |             1254 |\n|         7 |          7 |             1386 |\n|         8 |          6 |             1122 |\n|         9 |          6 |             1782 |\n|        10 |          6 |             2717 |\n|        11 |          5 |             1287 |\n|        12 |          5 |             1729 |\n|        13 |          5 |             2275 |\n|        14 |          5 |             2940 |\n|        15 |          5 |             3740 |\n|        16 |          4 |              952 |\n|        17 |          4 |             1122 |\n|        18 |          4 |             1311 |\n|        19 |          4 |             1520 |\n|        20 |          4 |             1750 |\n\nTo precompute a larger fundamental system for a dimension run the following script\n```\ncd spherical_harmonics\npython fundament_set.py\n```\nafter specifying the desired options in the file.\n\n---\n\n## Installation\n\nThe package is now available on PyPI under the name of `spherical-harmonics-basis`.\n\nSimply run\n```\npip install spherical-harmonics-basis\n```\n\n\n## Citation\n\nIf this code was useful for your research, please consider citing the following [paper](http://proceedings.mlr.press/v119/dutordoir20a/dutordoir20a.pdf):\n```\n@inproceedings{Dutordoir2020spherical,\n  title     = {{Sparse Gaussian Processes with Spherical Harmonic Features}},\n  author    = {Dutordoir, Vincent and Durrande, Nicolas and Hensman, James},\n  booktitle = {Proceedings of the 37th International Conference on Machine Learning (ICML)},\n  date      = {2020},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvdutor%2Fsphericalharmonics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvdutor%2Fsphericalharmonics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvdutor%2Fsphericalharmonics/lists"}