Пример #1
0
 def testCanberraDistance(self):
     assertion.eq(0.0, metric.canberra_distance([0], [0]))
     assertion.eq(
         0.0,
         metric.canberra_distance_numpy(numpy.array([0]), numpy.array([0])))
     assertion.eq(2.0, metric.canberra_distance([0.0, 0.0], [1.0, 1.0]))
     assertion.eq(
         2.0,
         metric.canberra_distance_numpy(numpy.array([0.0, 0.0]),
                                        numpy.array([1.0, 1.0])))
     assertion.eq(1.0, metric.canberra_distance([0.75, 0.75], [0.25, 0.25]))
     assertion.eq(
         1.0,
         metric.canberra_distance_numpy(numpy.array([0.75, 0.75]),
                                        numpy.array([0.25, 0.25])))
     assertion.eq(0.0, metric.canberra_distance([-1.0, -1.0], [-1.0, -1.0]))
     assertion.eq(
         0.0,
         metric.canberra_distance_numpy(numpy.array([-1.0, -1.0]),
                                        numpy.array([-1.0, -1.0])))
     assertion.eq(0.4, metric.canberra_distance([-2.0, -2.0], [-3.0, -3.0]))
     assertion.eq(
         0.4,
         metric.canberra_distance_numpy(numpy.array([-2.0, -2.0]),
                                        numpy.array([-3.0, -3.0])))
Пример #2
0
 def testCanberraDistance(self):
     assertion.eq(0.0, metric.canberra_distance([0], [0]))
     assertion.eq(0.0, metric.canberra_distance_numpy(numpy.array([0]), numpy.array([0])))
     assertion.eq(2.0, metric.canberra_distance([0.0, 0.0], [1.0, 1.0]))
     assertion.eq(2.0, metric.canberra_distance_numpy(numpy.array([0.0, 0.0]), numpy.array([1.0, 1.0])))
     assertion.eq(1.0, metric.canberra_distance([0.75, 0.75], [0.25, 0.25]))
     assertion.eq(1.0, metric.canberra_distance_numpy(numpy.array([0.75, 0.75]), numpy.array([0.25, 0.25])))
     assertion.eq(0.0, metric.canberra_distance([-1.0, -1.0], [-1.0, -1.0]))
     assertion.eq(0.0, metric.canberra_distance_numpy(numpy.array([-1.0, -1.0]), numpy.array([-1.0, -1.0])))
     assertion.eq(0.4, metric.canberra_distance([-2.0, -2.0], [-3.0, -3.0]))
     assertion.eq(0.4, metric.canberra_distance_numpy(numpy.array([-2.0, -2.0]), numpy.array([-3.0, -3.0])))
Пример #3
0
    def testCommonAndNumPyMetricsTwoDimension(self):
        a = [1.2, 3.4]
        b = [5.4, -7.1]
        npa = numpy.array(a)
        npb = numpy.array(b)

        assertion.eq(metric.euclidean_distance(a, b),
                     metric.euclidean_distance_numpy(npa, npb))
        assertion.eq(metric.euclidean_distance_square(a, b),
                     metric.euclidean_distance_square_numpy(npa, npb))
        assertion.eq(metric.manhattan_distance(a, b),
                     metric.manhattan_distance_numpy(npa, npb))
        assertion.eq(metric.chebyshev_distance(a, b),
                     metric.chebyshev_distance_numpy(npa, npb))
        assertion.eq(metric.minkowski_distance(a, b, 2),
                     metric.minkowski_distance_numpy(npa, npb, 2))
        assertion.eq(metric.minkowski_distance(a, b, 4),
                     metric.minkowski_distance_numpy(npa, npb, 4))
        assertion.eq(metric.canberra_distance(a, b),
                     metric.canberra_distance_numpy(npa, npb))
        assertion.eq(metric.chi_square_distance(a, b),
                     metric.chi_square_distance_numpy(npa, npb))
        assertion.eq(metric.chi_square_distance(a, b),
                     metric.chi_square_distance_numpy(npa, npb))

        gower = metric.distance_metric(metric.type_metric.GOWER,
                                       data=[a, b],
                                       numpy_usage=False)
        gower_numpy = metric.distance_metric(metric.type_metric.GOWER,
                                             data=[a, b],
                                             numpy_usage=True)
        assertion.eq(gower(a, b), gower_numpy(npa, npb))