Exemple #1
0
def test_invwnn_kpoints_group():
    """Test InvWNN with group of k same points provided : all request should return
     point of the dataset."""
    result = True

    for i in range(25):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNInverseModel(n, m, sigma, 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
Exemple #2
0
def test_invwnn_kpoints_group():
    """Test InvWNN with group of k same points provided : all request should return
     point of the dataset."""
    result = True

    for i in range(25):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNInverseModel(n, m, sigma, 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
Exemple #3
0
def test_invwnn_samepoint():
    """Test InvWNN with one point provided multiple times."""

    result = True

    for i in range(25):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNInverseModel(n, m, sigma, 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
Exemple #4
0
def test_invwnn_samepoint():
    """Test InvWNN with one point provided multiple times."""

    result = True

    for i in range(25):
        n = random.randint(1, 20)
        m = random.randint(1, 20)
        k = random.randint(1, 20)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNInverseModel(n, m, sigma, 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