Home Machine Learning Differentiable and Accelerated Spherical Harmonic Transforms | by Jason McEwen | Mar, 2024

Differentiable and Accelerated Spherical Harmonic Transforms | by Jason McEwen | Mar, 2024

0
Differentiable and Accelerated Spherical Harmonic Transforms | by Jason McEwen | Mar, 2024

[ad_1]

In JAX and PyTorch

Many areas of science and engineering encounter knowledge outlined on the sphere. Modelling and evaluation of such knowledge usually requires the spherical counterpart to the Fourier remodel — the spherical harmonic remodel. We offer a short overview of the spherical harmonic remodel and current a brand new differentiable algorithm tailor-made in direction of acceleration on GPUs [1]. This algorithm is applied within the just lately launched S2FFT python bundle, which helps each JAX and PyTorch.

Picture by Szilvia Basso on Unsplash

Increasingly usually we’re excited about analysing knowledge that lives on the sphere. The range in purposes is exceptional, starting from quantum chemistry, biomedical imaging, local weather physics and geophysics, to the broader cosmos.

Probably the most well-known areas by which one encounters knowledge on the sphere are inside the bodily sciences, notably inside atmospheric science, geophysical modelling, and astrophysics.

Examples of probably the most broadly recognized instances of spherical knowledge, such because the Earth (left) and artist impression of astronomical observations (proper). [Earth image sourced from Wikipedia; astrophysics image sourced from Wikipedia.]

These issues are naturally spherical as observations are made at every level on the floor of a sphere: the floor of the Earth for geophysics and the sky for astrophysics. Different examples come from purposes like pc graphics and imaginative and prescient, the place 360° panoramic cameras seize the world round you in each course.

In lots of instances the spherical nature of the issue at hand is pretty straightforward to see; nevertheless, this isn’t at all times the case. Maybe surprisingly, spherical knowledge is kind of regularly encountered inside the organic disciplines, although the spherical facet is commonly a lot much less apparent! Since we are sometimes involved about native instructions in organic research, such because the course water diffuses inside the mind, we encounter spherical knowledge.

Diffusion tensor imaging of neuronal connections within the human mind. Inside every voxel neurons are free to journey in any course, so the issue is of course spherical. [Animation by Alfred Anwander, CC-BY licence.]

Given the prevalence of such knowledge, it isn’t stunning that many spherical evaluation strategies have been developed. A frequency evaluation of the info will be insightful, usually to afford a statistical abstract or an efficient illustration for additional evaluation or modelling. Not too long ago geometric deep studying strategies have confirmed extremely efficient for the evaluation of knowledge on advanced domains [2–6], notably for extremely advanced issues corresponding to molecular modelling and protein interactions (see our prior put up on A Temporary Introduction to Geometric Deep Studying).

So now we have knowledge on the sphere and quite a lot of strategies by which spherical knowledge could also be analysed, however we’d like mathematical instruments to take action. Particularly, we have to know the way to decompose spherical knowledge into frequencies effectively.

The Fourier transforms offers a frequency decomposition that’s usually used to calculate statistical correlations inside knowledge. Many bodily programs may additionally be described extra straightforwardly in frequency house, as every frequency might evolve independently.

To increase the usual Fourier remodel to the sphere, we’d like the assembly of minds of two seventeenth century French mathematicians: Joseph Fourier and Adrien-Marie Legendre.

Joseph Fourier (left) and Adrien-Marie Legendre (proper). Tragically, the caricature of Legendre is the one recognized picture of him. [Fourier image sourced from Wikipedia. Legendre image sourced from Wikipedia.]

First, let’s think about the way to decompose Euclidean knowledge into its varied frequencies. Such a change of the info was first derived by Joseph Fourier and is given by

which is discovered nearly in every single place and is a staple of undergraduate physics for a cause! This works by projecting our knowledge f(x) onto a set of trigonometric capabilities, referred to as a foundation. One can do successfully the identical factor on the sphere, however the foundation capabilities are actually given by the spherical harmonics Yₗₘ:

the place (θ, ϕ) are the standard spherical polar co-ordinates.

Spherical harmonic foundation capabilities (actual part). [Sourced from Wikipedia.]

The spherical harmonics (proven above) will be damaged down additional into the product of an exponential and Legendre polynomials — à la Adrien-Marie Legendre — as

And so the spherical harmonic remodel will be written as a Fourier remodel adopted by an related Legendre remodel. The actual issue is available in evaluating the Legendre a part of the remodel: it’s both computationally costly or reminiscence hungry, relying on the tactic one chooses.

The expansion of differentiable programming is opening up many new varieties of evaluation. Particularly, many purposes require spherical transforms which can be differentiable.

Machine studying fashions on the sphere require differentiable transforms in order that fashions could also be educated by gradient-based optimisation algorithms, i.e. by way of back-propagation.

Rising physics-enhanced machine studying approaches [7] for hybrid data-driven and model-based approaches [8] additionally require differentiable physics fashions, which in lots of instances themselves require differentiable spherical transforms.

With this in thoughts it’s clear that for contemporary purposes an environment friendly algorithm for the spherical harmonic remodel is important however not sufficient. Differentiability is essential.

That is all nicely and good, however how does one effectively consider the spherical harmonic remodel? Quite a lot of algorithms have been developed, with some nice software program packages. Nonetheless for contemporary purposes we’d like one that’s differentiable, can run on {hardware} accelerators like GPUs, and is computationally scalable.

By redesigning the core algorithms from the bottom up (as described in depth in our corresponding paper [1]), we just lately developed a python bundle referred to as S2FFT that ought to match the invoice.

S2FFT is applied in JAX, a differentiable programming language developed by Google, and in addition features a PyTorch frontend.

S2FFT is a Python bundle implementing differentiable and accelerated spherical harmonic transforms, with interfaces in JAX and PyTorch. [Image created by authors.]

S2FFT offers two working modes: precompute the related Legendre capabilities, that are then accessed at run time; or compute them on-the-fly throughout the remodel. The pre-compute strategy is nearly as quick as you may get, however the reminiscence required to retailer all Legendre operate values scales cubicly with decision, which is usually a drawback! The second strategy we offer as an alternative recursively computes Legendre phrases on-the-fly, and so will be scaled to very excessive resolutions.

As well as, S2FFT additionally helps a hybrid computerized and guide differentiation strategy in order that gradients will be computed effectively.

The bundle is designed to help a number of totally different sampling schemes on the sphere. At launch, equiangular (McEwen & Wiaux [9], Driscoll & Healy [10]), Gauss-Legendre, and HEALPix [11] sampling schemes are supported, though others might simply be added in future.

Totally different sampling schemes on the sphere supported by S2FFT. [Original figure created by authors.]

The S2FFT bundle is out there on PyPi so anybody can set up it straightforwardly by working:

pip set up s2fft

Or to choose up PyTorch help by working:

pip set up "s2fft[torch]"

From right here the top-level transforms will be referred to as just by

import s2fft

# Compute ahead spherical harmonic remodel
flm = s2fft.forward_jax(f, L)

# Compute inverse spherical harmonic remodel
f = s2fft.inverse_jax(flm, L)

These capabilities will be picked up out of the field and built-in as layers inside present fashions, each in JAX and PyTorch, with full help for each ahead and reverse mode differentiation.

With researchers turning into more and more excited about differentiable programming for scientific purposes, there’s a important want for contemporary software program packages that implement the foundational mathematical strategies on which science is commonly based mostly, just like the spherical harmonic remodel.

We hope S2FFT will likely be of nice use in coming years and are excited to see what individuals will use it for!

[1] Value & McEwen, Differentiable and accelerated spherical harmonic and Wigner transforms, arxiv:2311.14670 (2023).

[2] Bronstein, Bruna, Cohen, Velickovic, Geometric Deep Studying: Grids, Teams, Graphs, Geodesics, and Gauges, arXix:2104.13478 (2021).

[3] Ocampo, Value & McEwen, Scalable and equivariant spherical CNNs by discrete-continuous (DISCO) convolutions, ICLR (2023).

[4] Cobb, Wallis, Mavor-Parker, Marignier, Value, d’Avezac, McEwen, Environment friendly Generalised Spherical CNNs, ICLR (2021).

[5] Cohen, Geiger, Koehler, Welling, Spherical CNNs, ICLR (2018).

[6] Jumper et al., Extremely correct protein construction prediction with AlphaFold, Nature (2021).

[7] Karniadakis et al, Physics-informed machine studying, Nature Opinions Physics (2021).

[8] Campagne et al., Jax-cosmo: An end-to-end differentiable and GPU accelerated cosmology library, arXiv:2302.05163 (2023).

[9] McEwen & Wiaux, A novel sampling theorem on the sphere, IEEE TSP (2012).

[10] Driscoll & Healy, Computing Fourier Transforms and Convolutions on the 2-Sphere, AAM (1994).

[11] Gorski et al., HEALPix: a Framework for Excessive Decision Discretization, and Quick Evaluation of Information Distributed on the Sphere, ApJ (2005).

[ad_2]