示例#1
0
    def test_finiteMetricSpaceLP_uniform(self, exampleClusterArch):
        testSpace = exampleClusterArch
        testProdSpace = FiniteMetricSpaceLP(testSpace, d=3)

        result = testProdSpace.uniform()
        for value in result:
            assert (testProdSpace.dist([3, 2, 7],
                                       testProdSpace.int2Tuple(value)) <= 5)
示例#2
0
    def test_finiteMetricSpaceLP_uniformFromBall2(self, exampleClusterArch):
        testSpace = exampleClusterArch
        testProdSpace = FiniteMetricSpaceLP(testSpace, d=3)
        uniformFromFourBall = testProdSpace.uniformFromBall([3, 2, 7], 4, 10)

        result = list(map(testProdSpace.int2Tuple, uniformFromFourBall))
        result = list(map(testProdSpace.tuple2Int, result))
        assert result == uniformFromFourBall
示例#3
0
    def test_finiteMetricSpaceLP_uniformFromBall1(self, exampleClusterArch):
        testSpace = exampleClusterArch
        testProdSpace = FiniteMetricSpaceLP(testSpace, d=3)
        uniformFromFourBall = testProdSpace.uniformFromBall([3, 2, 7], 4, 10)

        assert len(uniformFromFourBall) == 10

        for value in uniformFromFourBall:
            assert (testProdSpace.dist(testProdSpace.tuple2Int([3, 2, 7]),
                                       value) <= 4.0)
示例#4
0
    def test_finiteMetricSpaceLP_dist(self, exampleClusterArch):
        testSpace = exampleClusterArch
        testProdSpace = FiniteMetricSpaceLP(testSpace, d=3)
        uniformFromFourBall = testProdSpace.uniformFromBall([3, 2, 7], 4, 10)

        result = []
        for j in uniformFromFourBall:
            result.append(
                testProdSpace.dist(testProdSpace.tuple2Int([3, 2, 7]), j))

        assert len(result) == 10

        for value in result:
            assert value <= 4.0
示例#5
0
    def test_finiteMetricSpaceLP_ball2(self, exampleClusterArch):
        testSpace = exampleClusterArch
        testProdSpace = FiniteMetricSpaceLP(testSpace, d=3)
        oneBall = testProdSpace.ball([3, 2, 7], 1)

        result = list(map(testProdSpace.int2Tuple, oneBall))
        assert result == [
            [3, 2, 4],
            [3, 2, 5],
            [3, 2, 6],
            [3, 0, 7],
            [3, 1, 7],
            [0, 2, 7],
            [1, 2, 7],
            [2, 2, 7],
            [3, 2, 7],
            [3, 3, 7],
        ]
示例#6
0
    def test_Evec(self, exampleClusterArch, dimension):
        M = exampleClusterArch
        MLP = FiniteMetricSpaceLP(M, dimension, p=2)
        Evec = MetricSpaceEmbedding(M, dimension)
        in1 = [1, 0, 1, 1, 3]
        in2 = [0, 0, 2, 1, 0]
        dist = MLP.dist(in1, in2)

        evec1 = Evec.i(in1)
        evec2 = Evec.i(in2)
        assert len(evec1) == dimension
        assert len(evec1[0]) == M.n
        dist_embedded = np.linalg.norm(
            np.array(evec1).flatten() - np.array(evec2).flatten()
        )
        assert (
            dist / Evec.distortion < dist_embedded
            and dist_embedded < dist * Evec.distortion
        )
示例#7
0
    def test_finiteMetricSpaceLP_ball1(self, exampleClusterArch):
        testSpace = exampleClusterArch
        testProdSpace = FiniteMetricSpaceLP(testSpace, d=3)

        result = len(testProdSpace.ball([3, 2, 7], 4))
        assert result == 1072
示例#8
0
    def test_finiteMetricSpaceLP_oneBall(self, exampleClusterArch):
        testSpace = exampleClusterArch
        testProdSpace = FiniteMetricSpaceLP(testSpace, d=3)
        oneBall = testProdSpace.ball([3, 2, 7], 1)

        assert len(oneBall) == 10
示例#9
0
    def test_finiteMetricSpaceLP_calc(self, exampleClusterArch):
        testSpace = exampleClusterArch
        testProdSpace = FiniteMetricSpaceLP(testSpace, d=3)

        result = testProdSpace._distCalc([3, 2, 7], [3, 0, 4])
        assert result == 2.0