You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mainly to park an old script for how to do gauss-hermite integration with scipy.
code is most likely outdated because scipy deprecated some of the orthogonal polynomial function.
related to numerical integration:
halton and similar quasi-random sequences are in master, for DOE
Stata uses adaptive quadrature for mixed models, which I haven't figured out (and I'm not sure we can do it in a computational efficient/vectorized way). #2516 PR for GSOC project for MixedGLM, uses Laplace IIRC
Bayesian Mixed GLM is in master
google search now also has an AI. Semi-random topic to try it out
asking for gauss hermite in python
the code uses numpy polynomial to get points and weights. (I'm not sure what the status in scipy is. Some parts changed and I have not used this in a long time.
Note: this does not include the sqrt(2 pi) term for integration w.r.t. normal distribution.
from numpy.polynomial.hermite_e import hermegauss
# This quadrature is for integrals of the form:
# I = integral(exp(-x^2/2) * f(x), -inf, inf)
def gauss_hermite_e_integration(func, n_points):
x, w = hermegauss(n_points)
integral_approx = np.sum(w * func(x))
return integral_approx
Aside:
google ai also shows the function to integrate a function w.r.t. Lebesque measure instead of normal distribution.
In this case we need to divide the function by the weight function to compensate for the gauss-hermite weights.
Maybe we never want to use that.
(Once upon a time, I went through the other orthogonal polynomials and the corresponding distribution functions, if applicable.
That's useful for integrating w.r.t. those distributions. (*))
def general_gauss_hermite_integration(g_func, n_points):
"""
Approximate the integral of a general function g(x) from -inf to inf.
"""
x, w = hermgauss(n_points)
# Define f(x) = g(x) / w(x) where w(x) = exp(-x^2).
# It is crucial to perform this division analytically if possible
# to avoid numerical instability.
f_func = lambda x: g_func(x) * np.exp(x**2)
integral_approx = np.sum(w * f_func(x))
return integral_approx
Activity
josef-pkt commentedon Feb 14, 2019
\josef\work-oth2\work-oth2_moved\try_hermite_quadrature.py
might be superseded by some MixedPoisson examples (if I find it)
josef-pkt commentedon Feb 19, 2020
just found by chance
https://github.com/nschloe/quadpy
includes adaptive quadrature, disadvantage: has sympy as listed requirement
also uses
https://github.com/nschloe/orthopy
more orthogonal polynomial features than numpy
quadpy docs say it can integrate vectorized function, which would be very useful in our case.
But I don't know if it fits our requirements.
update
looks like those are now closed source with license requirement.
josef-pkt commentedon Apr 7, 2023
_norm_pdf_C = math.sqrt(2*pi)old scipy distribution function, now removed from scipyexamples with updated code
josef-pkt commentedon Oct 31, 2025
google search now also has an AI. Semi-random topic to try it out
asking for gauss hermite in python
the code uses numpy polynomial to get points and weights. (I'm not sure what the status in scipy is. Some parts changed and I have not used this in a long time.
Note: this does not include the sqrt(2 pi) term for integration w.r.t. normal distribution.
Aside:
google ai also shows the function to integrate a function w.r.t. Lebesque measure instead of normal distribution.
In this case we need to divide the function by the weight function to compensate for the gauss-hermite weights.
Maybe we never want to use that.
(Once upon a time, I went through the other orthogonal polynomials and the corresponding distribution functions, if applicable.
That's useful for integrating w.r.t. those distributions. (*))
(*) Google AI can answer that (but copying the table produces html)
They reference https://openturns.github.io/openturns/latest/theory/meta_modeling/orthogonal_polynomials.html
which includes the following table (support didn't copy)
edit
current scipy: function
roots_hermitenormhttps://docs.scipy.org/doc/scipy-1.16.2/reference/generated/scipy.special.roots_hermitenorm.html