  Hierarchical matrices provide a powerful representation for significantly
reducing the computational complexity associated with dense kernel matrices.
For general kernel functions, interpolation-based methods are widely used for
the efficient construction of hierarchical matrices. In this paper, we present
a fast hierarchical data reduction (HiDR) procedure with $O(n)$ complexity for
the memory-efficient construction of hierarchical matrices with nested bases
where $n$ is the number of data points. HiDR aims to reduce the given data in a
hierarchical way so as to obtain $O(1)$ representations for all nearfield and
farfield interactions. Based on HiDR, a linear complexity $\mathcal{H}^2$
matrix construction algorithm is proposed. The use of data-driven methods
enables {better efficiency than other general-purpose methods} and flexible
computation without accessing the kernel function. Experiments demonstrate
significantly improved memory efficiency of the proposed data-driven method
compared to interpolation-based methods over a wide range of kernels. Though
the method is not optimized for any special kernel, benchmark experiments for
the Coulomb kernel show that the proposed general-purpose algorithm offers
competitive performance for hierarchical matrix construction compared to
several state-of-the-art algorithms for the Coulomb kernel.
