Example #1
0
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)
Example #2
0
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)
Example #3
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)
Example #4
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)
Example #5
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)