Metric learning algorithm for hierarchical clustering