Learning Graphs from Data via Spectral Constraints for k-component, bipartite, and k-component bipartite graphs