Exemplo n.º 1
0
def test_invavgnn_kpoints_group():
    """Test InvAvgNN with group of k same points provided : all request should return
     point of the dataset."""
    result = True

    for i in range(20):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        model = AverageNNInverseModel(n, m, k)

        xgroup = set()
        for i in range(random.randint(1, 20)):
            x = np.random.rand(n)
            y = np.random.rand(m)
            xgroup.add(tuple(x))
            for i in range(k):
                model.add_xy(x, y)

        for i in range(10):
            y   = np.random.rand(m)
            xp = model.infer_x(y)[0]
            check = min([tools.dist(xp, x) for x in xgroup]) < 1e-10
            if not check:
                print('Error:', n, m, y, xe, xp)
            result = result and check

    return result
Exemplo n.º 2
0
def test_invavgnn_kpoints():
    """Test InvAvgNN with k point provided : all request should get the same prediction."""

    result = True

    for i in range(20):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        model = AverageNNInverseModel(n, m, k)

        for i in range(k):
            x = np.random.rand(n)
            y = np.random.rand(m)
            model.add_xy(x, y)

        y   = np.random.rand(m)
        xpg = model.infer_x(y)

        for i in range(10):
            y   = np.random.rand(m)
            xe = xpg
            xp = model.infer_x(y)[0]
            check = np.allclose(xe, xp, rtol = 1e-10, atol = 1e-10)
            if not check:
                print('Error:', n, m, y, xe, xp)
            result = result and check

    return result
Exemplo n.º 3
0
def test_invavgnn_samepoint():
    """Test InvAvgNN with one point provided multiple times."""

    result = True

    for i in range(20):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        model = AverageNNInverseModel(n, m, k)

        x = np.random.rand(n)
        y = np.random.rand(m)

        for i in range(random.randint(1, 20)):
            model.add_xy(x, y)

        for i in range(10):
            y   = np.random.rand(m)
            xe = x
            xp = model.infer_x(y)[0]
            check = np.allclose(xe, xp, rtol = 1e-10, atol = 1e-10)
            if not check:
                print('Error:', n, m, y, xe, xp)
            result = result and check

    return result
Exemplo n.º 4
0
def test_invavgnn_kpoints_group():
    """Test InvAvgNN with group of k same points provided : all request should return
     point of the dataset."""
    result = True

    for i in range(20):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        model = AverageNNInverseModel(n, m, k)

        xgroup = set()
        for i in range(random.randint(1, 20)):
            x = np.random.rand(n)
            y = np.random.rand(m)
            xgroup.add(tuple(x))
            for i in range(k):
                model.add_xy(x, y)

        for i in range(10):
            y = np.random.rand(m)
            xp = model.infer_x(y)[0]
            check = min([tools.dist(xp, x) for x in xgroup]) < 1e-10
            if not check:
                print('Error:', n, m, y, xe, xp)
            result = result and check

    return result
Exemplo n.º 5
0
def test_invavgnn_samepoint():
    """Test InvAvgNN with one point provided multiple times."""

    result = True

    for i in range(20):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        model = AverageNNInverseModel(n, m, k)

        x = np.random.rand(n)
        y = np.random.rand(m)

        for i in range(random.randint(1, 20)):
            model.add_xy(x, y)

        for i in range(10):
            y = np.random.rand(m)
            xe = x
            xp = model.infer_x(y)[0]
            check = np.allclose(xe, xp, rtol=1e-10, atol=1e-10)
            if not check:
                print('Error:', n, m, y, xe, xp)
            result = result and check

    return result
Exemplo n.º 6
0
def test_invavgnn_kpoints():
    """Test InvAvgNN with k point provided : all request should get the same prediction."""

    result = True

    for i in range(20):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        model = AverageNNInverseModel(n, m, k)

        for i in range(k):
            x = np.random.rand(n)
            y = np.random.rand(m)
            model.add_xy(x, y)

        y = np.random.rand(m)
        xpg = model.infer_x(y)

        for i in range(10):
            y = np.random.rand(m)
            xe = xpg
            xp = model.infer_x(y)[0]
            check = np.allclose(xe, xp, rtol=1e-10, atol=1e-10)
            if not check:
                print('Error:', n, m, y, xe, xp)
            result = result and check

    return result