0

I need some help understanding this numpy function called "numpy.polynomial.hermite.hermfit(x, y, deg, rcond=None, full=False, w=None)":https://numpy.org/doc/stable/reference/generated/numpy.polynomial.hermite.hermfit.html#numpy.polynomial.hermite.hermfit

It says in the documentation that it takes data and does a fitting to Gauss-Hermite polynomial and then gives the values of the coefficients. I want to know the following:

  1. What is the actual expression of the Gauss-Hermite polynomial they are fitting the data to?
  2. The documents states that the coefficients are returned according to the degree that is input into the function. Does this mean that if deg=2, the returned answers are h1 and h2? or if deg=4, they are h1,h2,h3,h4? The worked example in the doc doesn't explicitly state that.

Thanks lots.

Jerome
  • 49
  • 8

1 Answers1

1

The Hermite polynomials are a series of polynomials. It can be used similar as for example Taylor polynoms in a Taylor series for approximating a function. On wikipedia you can also find a list of the exact expressions (numpy uses the "physicist's" definition of the Hermite polynomials).

The function returns the coefficients of the hermite series expansion. So for example in a fit with degree 3 the series expression is

c0*H0 + c1*H1 + c2*H2

and the fit function returns the list

[c0,c1,c2]

You can pass this list to the np.polynomial.hermite.hermval function to evaluate the whole expression.

Jakob Stark
  • 3,346
  • 6
  • 22
  • Thanks, @Jakob. I took a look at the physicist's hermite polynomial...this does not seem to match the polynomial expression I was looking for. I wanted Gauss-Hermite polynomial such as in this post https://mscipio.github.io/post/fitting-functions-to-data/ They use a particular expression in the post. Is there any numpy functions that fit automatically to this polynomial expression? – Jerome Feb 01 '22 at 11:23
  • 1
    If you want to use the function that is used in that post, you should follow the definition there. It is a modified gaussian with more degrees of freedom, so that the skew and kurtosis can also be fitted (they would be 0 for a unmodified normal distribution). I'm afraid, there is no function in numpy that corresponds to the "gauss-hermite" function in the post (which is, by the way no polynomial). – Jakob Stark Feb 01 '22 at 11:40
  • 1
    I just found the function from the post you mentioned. It is on the same wikipedia page further down [here](https://en.wikipedia.org/wiki/Hermite_polynomials#Hermite_functions). In the post, there is a linear combination of the first 4 hermite functions. – Jakob Stark Feb 01 '22 at 11:50