def test_euclidean_distance(self): """euclidean_distance: should return dist between 2 vectors or matrices """ a = array([3,4]) b = array([8,5]) c = array([[2,3],[4,5]]) d = array([[1,5],[8,2]]) self.assertFloatEqual(euclidean_distance(a,b),sqrt(26)) self.assertFloatEqual(euclidean_distance(c,d),sqrt(30))
def test_euclidean_distance_unexpected(self): """euclidean_distance: works always when frames are aligned. UNEXPECTED! """ a = array([3,4]) b = array([8,5]) c = array([[2,3],[4,5]]) d = array([[1,5],[8,2]]) e = array([[4,5],[4,5],[4,5]]) f = array([1,1,1,1,1]) self.assertFloatEqual(euclidean_distance(a,c),sqrt(4)) self.assertFloatEqual(euclidean_distance(c,a),sqrt(4)) self.assertFloatEqual(euclidean_distance(a,e),sqrt(6)) #IT DOES RAISE AN ERROR WHEN THE FRAMES ARE NOT ALIGNED self.assertRaises(ValueError,euclidean_distance,c,e) self.assertRaises(ValueError,euclidean_distance,c,f)
def distance(self,other): """Calculates the distance between two BaseUsages. Distance is measured in three directions, CG-content, CU-content, and GU-content. """ return euclidean_distance(array(self.toCartesian()),\ array(other.toCartesian()))