implementation of spectral clustering