Esempio n. 1
0
def test_euclid_simetric():
    # Distancia a-->b = b-->a (metric='euclid')
    dist1 = distances.euclid(c0=np.array([1, 1]),
                             centres=np.array([[2, 2]]),
                             dim=2)
    dist2 = distances.euclid(c0=np.array([2, 2]),
                             centres=np.array([[1, 1]]),
                             dim=2)
    np.testing.assert_almost_equal(dist1, dist2, decimal=16)
Esempio n. 2
0
def test_euclid_decomposition():
    # Distancia a-->c <= a-->b + b-->c (metric='euclid')
    p_a = [1, 1]
    p_b = [2, 2]
    p_c = [1, 2]
    dist_ab = distances.euclid(np.array(p_a), np.array([p_b]), 2)
    dist_ac = distances.euclid(np.array(p_a), np.array([p_c]), 2)
    dist_bc = distances.euclid(np.array(p_b), np.array([p_c]), 2)
    assert dist_ac <= dist_ab + dist_bc
Esempio n. 3
0
def test_euclid_gt0():
    # Distancias >= 0 (metric='euclid')
    random = np.random.RandomState(42)
    data = random.uniform(-10, 10, size=(10, 2))
    centre_0 = random.uniform(-10, 10, size=(2, ))
    dist = distances.euclid(centre_0, data, 2)
    assert (dist >= 0).all()
Esempio n. 4
0
def test_euclid_not_nan():
    # Distancias != NaN (metric='euclid')
    random = np.random.RandomState(42)
    data = random.uniform(-10, 10, size=(10, 2))
    centre_0 = random.uniform(-10, 10, size=(2, ))
    dist = distances.euclid(centre_0, data, 2)
    assert not np.isnan(dist).any()