コード例 #1
0
ファイル: test_array.py プロジェクト: pombredanne/old-cogent
 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))
コード例 #2
0
ファイル: test_array.py プロジェクト: pombredanne/old-cogent
    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)
コード例 #3
0
ファイル: usage.py プロジェクト: pombredanne/old-cogent
    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()))