Package to mollify a function?

Hi, I was searching in the web but I didn’t found something about how to mollify a mathematical function, using any custom mollifier, in Julia. So my question is: there is a package to do that?

If not, there is a way to implement it? Thank you.

What does “mollify” mean?

Apply a mollifier to a mathematical function. Take a look here.

Mollification is an integral, so in principle you could use any numerical integration package for this, e.g.

using QuadGK
mollify(f::Function, φ::Function, support::NTuple{2, Real}; kws...) =
    x -> quadgk(y -> f(x - y) * φ(y), support...; kws...)[1]

which returns a new mollified function smoothed by φ (given the support of φ). For example:

julia> ϕ(x) = exp(-inv(1-x^2)) / 0.44399381616807943782304892117
ϕ (generic function with 1 method)

julia> f̃ = mollify(sin, x -> ϕ(10x)*10, (-0.1, 0.1))
#2 (generic function with 1 method)

julia> f̃(3) - sin(3) # mollified - original
-0.00011153383927728355

where the mollifier is the standard bump function squeezed by a factor of 10.

This is relatively slow because it performs an integral for every evaluation of the new function. Also, the main utility of mollifiers is for smoothing functions with singularities/discontinuities (and singular distributions), and in this case it’s helpful to give quadgk additional endpoints at the locations of any singularities. So you might want to pass an additional keyword argument indicating the locations of any singularities of f and add these to the integration domain as needed.

Even better might be to define a specialized method that uses the ApproxFun.jl package to construct a Fun (a type of polynomial approximation) of the mollified function, so that it is subsequently quick to evaluate.

For particular classes of functions f(x), of course, there might be more efficient algorithms.
For example, people use the term “discrete mollification” for functions defined at a set of discrete data points, e.g. in this paper, which is equivalent to mollification of a piecewise constant function f(x), and in this case there seem to be a variety of specialized algorithms.

Did you have a particular application in mind?

8 Likes

The application is just for pedagogic reasons, not “real” work, just visualization of how a function looks when its mollified. Just to say: thank you very much for your time and your kindly help.

AFAICT mollification is just another word for convolution? In which case, you can use FFTs to compute the convolved/mollified function on an evenly spaced set of points - which is exactly what you need if you’re plotting it.

1 Like

It’s a convolution with a very special function: a “nascent delta function” that is also a C_\infty test function with compact support, via which the convolution can be applied to arbitrary distributions.

That’s not quite the same thing, because it computes a discrete convolution, and in particular it corresponds to approximating the convolution integral by a trapezoidal rule with equally spaced points. This is a poor approximation (very slowly converging) if you want to mollify functions with discontinuities or other singularities.

3 Likes