コード例 #1
0
def test_kernel_2d_9():
    beta = Constant('beta')
    alpha = Constant('alpha')
    mu = Constant('mu')
    L = beta*dx(dx(u)) + alpha*dx(u) + mu*u

    # ...
    expected = alpha*Derivative(k, xi) + beta*Derivative(k, xi, xi) + mu*k(xi, yi)
    assert(evaluate(L, u, Kernel('K'), (Tuple(xi, yi),)) == expected)
    # ...

    # ...
    expected = alpha*Derivative(k, xj) + beta*Derivative(k, xj, xj) + mu*k(xj, yj)
    assert(evaluate(L, u, Kernel('K'), (Tuple(xj, yj),)) == expected)
    # ...

    # ...
    expected = (alpha**2*Derivative(k, xi, xj) +
                alpha*beta*Derivative(k, xi, xi, xj) +
                alpha*beta*Derivative(k, xi, xj, xj) +
                alpha*mu*Derivative(k, xi) +
                alpha*mu*Derivative(k, xj) +
                beta**2*Derivative(k, xi, xi, xj, xj) +
                beta*mu*Derivative(k, xi, xi) +
                beta*mu*Derivative(k, xj, xj) +
                mu**2*k(xi, yi, xj, yj))
    assert(evaluate(L, u, Kernel('K'), (Tuple(xi,yi), Tuple(xj,yj))) == expected)
コード例 #2
0
ファイル: test_rbf_1d.py プロジェクト: ratnania/symgp
def test_kernel_1d_1():
    L = u

    # ...
    K = evaluate(L, u, Kernel('K'), xi)
    K = update_kernel(K, RBF, (xi, xj))

    expected = theta_1*exp(-0.5*(xi - xj)**2)
    assert(K == expected)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), xj)
    K = update_kernel(K, RBF, (xi, xj))

    expected = theta_1*exp(-0.5*(xi - xj)**2)
    assert(K == expected)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), (xi, xj))
    K = update_kernel(K, RBF, (xi, xj))

    expected = theta_1*exp(-0.5*(xi - xj)**2)
    assert(K == expected)
コード例 #3
0
ファイル: test_rbf_1d.py プロジェクト: ratnania/symgp
def test_kernel_1d_2():
    L = dx(u) + alpha*u

    # ...
    K = evaluate(L, u, Kernel('K'), xi)
    K = update_kernel(K, RBF, (xi, xj))

    expected = theta_1*(1.0*alpha - 1.0*xi + 1.0*xj)*exp(-0.5*(xi - xj)**2)
    assert(K == expected)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), xj)
    K = update_kernel(K, RBF, (xi, xj))

    expected = theta_1*(1.0*alpha + 1.0*xi - 1.0*xj)*exp(-0.5*(xi - xj)**2)
    assert(K == expected)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), (xi, xj))
    K = update_kernel(K, RBF, (xi, xj))

    expected = theta_1*(alpha**2 - 1.0*(xi - xj)**2 + 1.0)*exp(-0.5*(xi - xj)**2)
    assert(K == expected)
コード例 #4
0
def test_kernel_2d_1():
    L = u

    # ...
    K = evaluate(L, u, Kernel('K'), (Tuple(xi, yi)))
    K = update_kernel(K, RBF, ((xi, yi), (xj, yj)))

    expected = theta_1 * theta_2 * exp(-0.5 * (xi - xj)**2) * exp(-0.5 *
                                                                  (yi - yj)**2)
    assert (K == expected)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), (Tuple(xj, yj)))
    K = update_kernel(K, RBF, ((xi, yi), (xj, yj)))

    expected = theta_1 * theta_2 * exp(-0.5 * (xi - xj)**2) * exp(-0.5 *
                                                                  (yi - yj)**2)
    assert (K == expected)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), (Tuple(xi, yi), Tuple(xj, yj)))
    K = update_kernel(K, RBF, ((xi, yi), (xj, yj)))

    expected = theta_1 * theta_2 * exp(-0.5 * (xi - xj)**2) * exp(-0.5 *
                                                                  (yi - yj)**2)
    assert (K == expected)
コード例 #5
0
ファイル: test_kernel_3d.py プロジェクト: ratnania/symgp
def test_kernel_2d_11():
    phi = Constant('phi')
    L = phi * u + dx(u) + dy(u) + dz(dz(u))

    # ...
    expected = phi * k(xi, yi, zi) + Derivative(k, xi) + Derivative(
        k, yi) + Derivative(k, zi, zi)
    assert (evaluate(L, u, Kernel('K'), (Tuple(xi, yi, zi), )) == expected)
    # ...

    # ...
    expected = phi * k(xj, yj, zj) + Derivative(k, xj) + Derivative(
        k, yj) + Derivative(k, zj, zj)
    assert (evaluate(L, u, Kernel('K'), (Tuple(xj, yj, zj), )) == expected)
    # ...

    # ...
    expected = (phi**2 * k(xi, yi, zi, xj, yj, zj) + phi * Derivative(k, xi) +
                phi * Derivative(k, xj) + phi * Derivative(k, yi) +
                phi * Derivative(k, yj) + phi * Derivative(k, zi, zi) +
                phi * Derivative(k, zj, zj) + Derivative(k, xi, xj) +
                Derivative(k, xi, yj) + Derivative(k, yi, xj) +
                Derivative(k, yi, yj) + Derivative(k, xi, zj, zj) +
                Derivative(k, yi, zj, zj) + Derivative(k, zi, zi, xj) +
                Derivative(k, zi, zi, yj) + Derivative(k, zi, zi, zj, zj))
    assert (evaluate(L, u, Kernel('K'),
                     (Tuple(xi, yi, zi), Tuple(xj, yj, zj))) == expected)
コード例 #6
0
def test_kernel_2d_5():
    L = dx(dx(u))

    # ...
    expected = Derivative(k, xi, xi)
    assert(evaluate(L, u, Kernel('K'), (Tuple(xi, yi),)) == expected)
    # ...

    # ...
    expected = Derivative(k, xj, xj)
    assert(evaluate(L, u, Kernel('K'), (Tuple(xj, yj),)) == expected)
    # ...

    # ...
    expected = Derivative(k, xi, xi, xj, xj)
    assert(evaluate(L, u, Kernel('K'), (Tuple(xi,yi), Tuple(xj,yj))) == expected)
コード例 #7
0
def test_kernel_2d_1():
    L = u

    # ...
    expected = k(xi, yi)
    assert(evaluate(L, u, Kernel('K'), (Tuple(xi, yi),)) == expected)
    # ...

    # ...
    expected = k(xj, yj)
    assert(evaluate(L, u, Kernel('K'), (Tuple(xj, yj),)) == expected)
    # ...

    # ...
    expected = k(xi, yi, xj, yj)
    assert(evaluate(L, u, Kernel('K'), (Tuple(xi,yi), Tuple(xj,yj))) == expected)
コード例 #8
0
def test_kernel_1d_2():
    L = dx(dx(u))

    # ...
    expected = Derivative(k, xi, xi)
    assert (evaluate(L, u, Kernel('K'), xi) == expected)
    # ...

    # ...
    expected = Derivative(k, xj, xj)
    assert (evaluate(L, u, Kernel('K'), xj) == expected)
    # ...

    # ...
    expected = Derivative(k, xi, xi, xj, xj)
    assert (evaluate(L, u, Kernel('K'), (xi, xj)) == expected)
コード例 #9
0
def test_kernel_1d_3():
    L = dx(u) + u

    # ...
    expected = k(xi) + Derivative(k, xi)
    assert (evaluate(L, u, Kernel('K'), xi) == expected)
    # ...

    # ...
    expected = k(xj) + Derivative(k, xj)
    assert (evaluate(L, u, Kernel('K'), xj) == expected)
    # ...

    # ...
    expected = (k(xi, xj) + Derivative(k, xi) + Derivative(k, xj) +
                Derivative(k, xi, xj))
    assert (evaluate(L, u, Kernel('K'), (xi, xj)) == expected)
コード例 #10
0
ファイル: test_kernel_3d.py プロジェクト: ratnania/symgp
def test_kernel_2d_4():
    L = dz(u)

    # ...
    expected = Derivative(k, zi)
    assert (evaluate(L, u, Kernel('K'), (Tuple(xi, yi, zi), )) == expected)
    # ...

    # ...
    expected = Derivative(k, zj)
    assert (evaluate(L, u, Kernel('K'), (Tuple(xj, yj, zj), )) == expected)
    # ...

    # ...
    expected = Derivative(k, zi, zj)
    assert (evaluate(L, u, Kernel('K'),
                     (Tuple(xi, yi, zi), Tuple(xj, yj, zj))) == expected)
コード例 #11
0
def test_kernel_3d_2():
    L = phi * u + dx(u) + dy(u) + dz(dz(u))

    # ...
    K = evaluate(L, u, Kernel('K'), (Tuple(xi, yi, zi)))
    K = update_kernel(K, RBF, ((xi, yi, zi), (xj, yj, zj)))

    expected = theta_1 * theta_2 * theta_3 * (
        phi**3 + 1.0 * phi**2 * (-xi + xj) + 1.0 * phi**2 *
        (-yi + yj) + 1.0 * phi**2 * (-zi + zj) + 1.0 * phi * (xi - xj) *
        (yi - yj) + 1.0 * phi * (xi - xj) * (zi - zj) + 1.0 * phi * (yi - yj) *
        (zi - zj) - 1.0 * (xi - xj) * (yi - yj) *
        (zi - zj)) * exp(-0.5 *
                         (xi - xj)**2) * exp(-0.5 *
                                             (yi - yj)**2) * exp(-0.5 *
                                                                 (zi - zj)**2)
    assert (simplify(K - expected) == 0)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), (Tuple(xj, yj, zj)))
    K = update_kernel(K, RBF, ((xi, yi, zi), (xj, yj, zj)))

    expected = theta_1 * theta_2 * theta_3 * (
        phi**3 + 1.0 * phi**2 * (xi - xj) + 1.0 * phi**2 *
        (yi - yj) + 1.0 * phi**2 * (zi - zj) + 1.0 * phi * (xi - xj) *
        (yi - yj) + 1.0 * phi * (xi - xj) * (zi - zj) + 1.0 * phi * (yi - yj) *
        (zi - zj) + 1.0 * (xi - xj) * (yi - yj) *
        (zi - zj)) * exp(-0.5 *
                         (xi - xj)**2) * exp(-0.5 *
                                             (yi - yj)**2) * exp(-0.5 *
                                                                 (zi - zj)**2)
    assert (simplify(K - expected) == 0)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), (Tuple(xi, yi, zi), Tuple(xj, yj, zj)))
    K = update_kernel(K, RBF, ((xi, yi, zi), (xj, yj, zj)))

    expected = theta_1 * theta_2 * theta_3 * (
        phi**2 + 2.0 * phi * ((zi - zj)**2 - 1) - 1.0 * (xi - xj)**2 - 2.0 *
        (xi - xj) * (yi - yj) - 1.0 * (yi - yj)**2 + 1.0 * (zi - zj)**4 - 6.0 *
        (zi - zj)**2 + 5.0) * exp(-0.5 * (xi - xj)**2) * exp(
            -0.5 * (yi - yj)**2) * exp(-0.5 * (zi - zj)**2)
    assert (simplify(K - expected) == 0)
コード例 #12
0
def test_kernel_1d_5():
    alpha = Constant('alpha')
    L = dx(u) + alpha * u

    # ...
    expected = alpha * k(xi) + Derivative(k, xi)
    assert (evaluate(L, u, Kernel('K'), xi) == expected)
    # ...

    # ...
    expected = alpha * k(xj) + Derivative(k, xj)
    assert (evaluate(L, u, Kernel('K'), xj) == expected)
    # ...

    # ...
    expected = (alpha**2 * k(xi, xj) + alpha * Derivative(k, xi) +
                alpha * Derivative(k, xj) + Derivative(k, xi, xj))
    assert (evaluate(L, u, Kernel('K'), (xi, xj)) == expected)
コード例 #13
0
def test_kernel_2d_2():
    L = phi * u + dx(u) + dy(dy(u))

    # ...
    K = evaluate(L, u, Kernel('K'), (Tuple(xi, yi)))
    K = update_kernel(K, RBF, ((xi, yi), (xj, yj)))

    expected = theta_1 * theta_2 * (phi**2 - 1.0 * phi *
                                    (xi - xj) - 1.0 * phi * (yi - yj) + 1.0 *
                                    (xi - xj) * (yi - yj)) * exp(
                                        -0.5 *
                                        (xi - xj)**2) * exp(-0.5 *
                                                            (yi - yj)**2)
    assert (simplify(K - expected) == 0)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), (Tuple(xj, yj)))
    K = update_kernel(K, RBF, ((xi, yi), (xj, yj)))

    expected = theta_1 * theta_2 * (phi**2 + 1.0 * phi *
                                    (xi - xj) + 1.0 * phi * (yi - yj) + 1.0 *
                                    (xi - xj) * (yi - yj)) * exp(
                                        -0.5 *
                                        (xi - xj)**2) * exp(-0.5 *
                                                            (yi - yj)**2)
    assert (simplify(K - expected) == 0)
    # ...

    # ...
    K = evaluate(L, u, Kernel('K'), (Tuple(xi, yi), Tuple(xj, yj)))
    K = update_kernel(K, RBF, ((xi, yi), (xj, yj)))

    expected = theta_1 * theta_2 * (phi**2 + 2.0 * phi *
                                    ((yi - yj)**2 - 1) - 1.0 *
                                    (xi - xj)**2 + 1.0 * (yi - yj)**4 - 6.0 *
                                    (yi - yj)**2 + 4.0) * exp(
                                        -0.5 *
                                        (xi - xj)**2) * exp(-0.5 *
                                                            (yi - yj)**2)
    assert (simplify(K - expected) == 0)
コード例 #14
0
ファイル: test_kernel_3d.py プロジェクト: ratnania/symgp
def test_kernel_2d_5():
    L = dx(u) + dy(u) + dz(u)

    # ...
    expected = Derivative(k, xi) + Derivative(k, yi) + Derivative(k, zi)
    assert (evaluate(L, u, Kernel('K'), (Tuple(xi, yi, zi), )) == expected)
    # ...

    # ...
    expected = Derivative(k, xj) + Derivative(k, yj) + Derivative(k, zj)
    assert (evaluate(L, u, Kernel('K'), (Tuple(xj, yj, zj), )) == expected)
    # ...

    # ...
    expected = (Derivative(k, xi, xj) + Derivative(k, xi, yj) +
                Derivative(k, xi, zj) + Derivative(k, yi, xj) +
                Derivative(k, yi, yj) + Derivative(k, yi, zj) +
                Derivative(k, zi, xj) + Derivative(k, zi, yj) +
                Derivative(k, zi, zj))
    assert (evaluate(L, u, Kernel('K'),
                     (Tuple(xi, yi, zi), Tuple(xj, yj, zj))) == expected)