Ejemplo n.º 1
0
        def second_moments(i, j, M2, beta, R, logk_c, logk_r, z_, Sx, *args):
            # This comes from Deisenroth's thesis ( Eqs 2.51- 2.54 )
            Rij = R[i, j]
            n2 = logk_c[i] + logk_r[j]
            n2 += utils.maha(z_[i], -z_[j], 0.5 * solve(Rij, Sx))
            Q = tt.exp(n2) / tt.sqrt(det(Rij))

            # Eq 2.55
            m2 = matrix_dot(beta[i], Q, beta[j])

            m2 = theano.ifelse.ifelse(tt.eq(i, j), m2 + 1e-6, m2)
            M2 = tt.set_subtensor(M2[i, j], m2)
            return M2
Ejemplo n.º 2
0
def SEard(hyp, X1, X2=None, all_pairs=True):
    ''' Squard exponential kernel with diagonal scaling matrix
        (one lengthscale per dimension)'''
    n = 1
    idims = 1
    if X1.ndim == 2:
        n, idims = X1.shape
    elif X2.ndim == 2:
        n, idims = X2.shape
    else:
        idims = X1.shape[0]

    sf2 = hyp[idims]**2
    if (not all_pairs) and (X1 is X2 or X2 is None):
        # all the distances are going to be zero
        K = tt.tile(sf2, (n,))
        return K

    ls2 = hyp[:idims]**2
    D = utils.maha(X1, X2, tt.diag(1.0/ls2),
                   all_pairs=all_pairs)
    K = sf2*tt.exp(-0.5*D)
    return K