I want to compute the functional norm of a function. My use case is the distance of two function but that is not as important as computing this in a correct manner in python. Looking at the docs I did:
import numpy as np
import scipy.integrate as integrate
def functional_diff_norm(f1, f2, lb, ub, p=2):
"""
Computes norm:
||f||_p = (int_S |f|^p dmu)^1/p
https://en.wikipedia.org/wiki/Lp_space
"""
norm = integrate.quad(lambda x: abs(f1(x) - f2(x))**p, lb, ub)[0]**(1/p)
return norm
but want to make sure it's correct.
Also, I'd like to generalize it to higher dimensions. Is that tractable? If yes up to what dimension (and accuracy?)
crossposted: https://discuss.pytorch.org/t/how-does-one-compute-the-norm-of-a-function-in-python/91527