コード例 #1
0
ファイル: wnn_test.py プロジェクト: jack2200/models
def test_fwdwnn_kpoints_group():
    """Test FwdWNN with group of k same points provided : all request should return
     point of the dataset."""
    result = True

    size = 30

    for i in range(20):
        n = random.randint(1, size)
        m = random.randint(1, size)
        k = random.randint(1, size)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNForwardModel(n, m, sigma=sigma, k=k)

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

        for i in range(10):
            x = np.random.rand(n)
            yp = model.predict_y(x)

            check = min([tools.dist(yp, y) for y in ygroup]) < 1e-10
            if not check:
                print('Error:', n, m, k,
                      min([tools.dist(yp, y) for y in ygroup]), yp)
            result = result and check

    return result
コード例 #2
0
ファイル: wnn_test.py プロジェクト: jack2200/models
def test_fwdwnn_samepoint():
    """Test FwdWNN with one point provided multiple times."""
    result = True

    for i in range(25):
        n = random.randint(1, 3)
        m = random.randint(1, 3)
        k = random.randint(1, 20)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNForwardModel(n, m, sigma=sigma, k=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):
            x = np.random.rand(n)
            ye = y
            yp = model.predict_y(x)
            check = np.allclose(ye, yp, rtol=1e-5, atol=1e-5)
            if not check:
                print('Error:', x, ye, yp)
            result = result and check

    return result
コード例 #3
0
ファイル: wnn_test.py プロジェクト: jack2200/models
def test_fwdwnn_onepoint():
    """Test FwdWNN with only one point provided."""
    result = True

    max_dim = 5
    for i in range(5):
        n = random.randint(1, max_dim)
        m = random.randint(1, max_dim)
        k = random.randint(1, max_dim)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNForwardModel(n, m, sigma=sigma, k=k)

        x = np.random.rand(n)
        y = np.random.rand(m)
        model.add_xy(x, y)

        for i in range(10):
            x = np.random.rand(n)
            ye = y
            yp = model.predict_y(x)
            check = np.allclose(ye, yp, rtol=1e-10, atol=1e-10)
            if not check:
                print('Error:', x, ye, yp)
            result = result and check

    return result
コード例 #4
0
ファイル: wnn_test.py プロジェクト: humm/models
def test_fwdwnn_kpoints_group():
    """Test FwdWNN with group of k same points provided : all request should return
     point of the dataset."""
    result = True

    size = 30

    for i in range(20):
        n = random.randint(1, size)
        m = random.randint(1, size)
        k = random.randint(1, size)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNForwardModel(n, m, sigma = sigma, k = k)

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

        for i in range(10):
            x = np.random.rand(n)
            yp = model.predict_y(x)

            check = min([tools.dist(yp, y) for y in ygroup]) < 1e-10
            if not check:
                print('Error:', n, m, k, min([tools.dist(yp, y) for y in ygroup]), yp)
            result = result and check

    return result
コード例 #5
0
ファイル: wnn_test.py プロジェクト: humm/models
def test_fwdwnn_samepoint():
    """Test FwdWNN with one point provided multiple times."""
    result = True

    for i in range(25):
        n = random.randint(1, 3)
        m = random.randint(1, 3)
        k = random.randint(1, 20)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNForwardModel(n, m, sigma = sigma, k = 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):
            x = np.random.rand(n)
            ye = y
            yp = model.predict_y(x)
            check = np.allclose(ye, yp, rtol = 1e-5, atol = 1e-5)
            if not check:
                print('Error:', x, ye, yp)
            result = result and check

    return result
コード例 #6
0
ファイル: wnn_test.py プロジェクト: humm/models
def test_fwdwnn_onepoint():
    """Test FwdWNN with only one point provided."""
    result = True

    max_dim = 5
    for i in range(5):
        n = random.randint(1, max_dim)
        m = random.randint(1, max_dim)
        k = random.randint(1, max_dim)
        sigma = random.uniform(0.1, 10)
        model = WeightedNNForwardModel(n, m, sigma = sigma, k = k)

        x = np.random.rand(n)
        y = np.random.rand(m)
        model.add_xy(x, y)

        for i in range(10):
            x = np.random.rand(n)
            ye = y
            yp = model.predict_y(x)
            check = np.allclose(ye, yp, rtol = 1e-10, atol = 1e-10)
            if not check:
                print('Error:', x, ye, yp)
            result = result and check

    return result