Exemple #1
0
def test_lwr_linear():
    """Test LWLR on random linear models of dimensions from 1 to 20.
     It should return exact results, give of take floating point imprecisions."""
    result = True

    for i in range(20):
        n = random.randint(1, 20)
        m = random.randint(1, 5)
        f = random_linear(n, m)
        model = LWLRForwardModel(n, m, 1.0)

        for i in range(2*n):
            x = np.random.rand(n)
            y = f(x)
            model.add_xy(x, y)

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

    return result
Exemple #2
0
def test_lwr1D_linear():
    """Simplest test possible (well, not quite, but close)."""
    result = True

    f = lambda x : 2.0*x
    model = LWLRForwardModel(1, 1, k = 3, sigma = 0.1)

    for i in range(10):
        x = np.random.rand(1)
        y = f(x)
        #print x, y
        model.add_xy(x, y)

    for i in range(10):
        x = np.random.rand(1).ravel()
        y = f(x)
        yp = model.predict_y(x)
        #print 'y ', y
        #print 'yp', yp
        result = result and np.allclose(y, yp, rtol = 1e-5, atol = 1e-5)

    return result