Persistent homology for functionals