Skip to content

Instantly share code, notes, and snippets.

@florisvanvugt
Last active April 29, 2023 18:46
Show Gist options
  • Save florisvanvugt/cf071f9b23e13a57cb74919ab45a6081 to your computer and use it in GitHub Desktop.
Save florisvanvugt/cf071f9b23e13a57cb74919ab45a6081 to your computer and use it in GitHub Desktop.
Generalized Normalized Laguerre Polynomials in Python (SciPy)
# Trying from here https://www.researchgate.net/journal/Multimedia-Tools-and-Applications-1573-7721/publication/345040403_A_fast_and_accurate_computation_of_2D_and_3D_generalized_Laguerre_moments_for_images_analysis/links/5f9cf2ce458515b7cfac9142/A-fast-and-accurate-computation-of-2D-and-3D-generalized-Laguerre-moments-for-images-analysis.pdf?origin=publicationDetail&_sg%5B0%5D=9VkiGQ9q0Og1tlOvVuIh6e4pKfM3X1dYLsb2oI3bdeI9LxeElUb0SPaebXqBlu7IiYKDAECpxcEHYarICYyRXA.yCd1i-NvkgjWbKWRFnVHHXYiIXNzqYbLdRrEv10u6VHfSfsU2eoTSL4Hl9pxLrS7_hoVBLIrkStQjuXxxK4guQ&_sg%5B1%5D=WQy30fJkrM2uQOdD5kWfQM10xjGfBPn73CMKwiAMGKLMtZpaRVDqLDY31RX7KHYpGQfk7ZK3Yf6KiZ0uF8fI5t7GBpIAl7QC-DDgtB_z0815.yCd1i-NvkgjWbKWRFnVHHXYiIXNzqYbLdRrEv10u6VHfSfsU2eoTSL4Hl9pxLrS7_hoVBLIrkStQjuXxxK4guQ&_iepl=&_rtd=eyJjb250ZW50SW50ZW50IjoibWFpbkl0ZW0ifQ%3D%3D
import math
import scipy.special
import numpy as np
from scipy.special import genlaguerre
def genlaguerrenorm(n,a):
# Generalized normalized Laguerre polynomial
# Essentially, these are the generalized laguerre polynomials but with
# a normalization factor (everything before l(x))
# Source: https://doi.org/10.1007/s11042-020-09921-3 equation (8)
# n : polynomial order
# a : regularization parameter (typically alpha)
# Returns: the polynomial (a function)
l = genlaguerre(n,a) # This is L_n^alpha(x) I think
sq = np.sqrt(math.factorial(n)/scipy.special.gamma(a+n+1))
return lambda x : sq*np.power(x,a/2)*np.exp(-x/2)*l(x)
# Demonstration
import matplotlib.pyplot as plt
a = .2
t = np.arange(0,40)
fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(5,5), sharex=True, sharey=True)
for order,ax in zip(range(9),axs.ravel()):
ax.set_ylabel("{}th".format(order))
l = genlaguerrenorm(order,a)
ax.plot(t,l(t))
plt.tight_layout()
@florisvanvugt
Copy link
Author

I had some trouble getting from the Laguerre polynomials in Scipy to the normalized versions (the ones that decay to zero). Here is what I came up with. Hope it may be helpful to some others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment