Physics based supervised and unsupervised learning of graph structure