Discriminative Learning of Similarity and Group Equivariant Representations