def from_function(cls, function: Function): dy = function.dy if dy is None: return function value = numpy.random.normal(function.eval().real, dy.eval().real) if function.is_complex(): value = value + 1j * numpy.random.normal(function.eval().imag, dy.eval().imag) return Function.to_function(function.get_dom(), value)
def get_kernel(cls, fun: Function, **kwargs): r""" Returns the gaussian kernel, centered at \mu = 0 and variance = sigma :param fun: Function to apply the gaussian kernel (needed for spacing purposes) :param kwargs: possible variable: sigma :return: """ sigma = kwargs.get('sigma', 1.0) dx = Domain.get_dx(fun.get_dom()) width = numpy.arange(-5 * sigma, 5 * sigma, dx) kernel = 1.0 / numpy.sqrt(2 * numpy.pi * sigma**2) * numpy.exp( -numpy.square(width / sigma) / 2.0) * dx return kernel