distance function learning