human
Complete this python program:
def loglikehood_coefficient(n_items, X, Y):
assistant
#Here is the Python program you requested.

    """Considering the rows of X (and Y=X) as vectors, compute the
    distance matrix between each pair of vectors.
    Parameters
    n_items: int
    Number of items in the model.
    X: array of shape (n_samples_1, n_features)
    Y: array of shape (n_samples_2, n_features)
    Returns
    distances: array of shape (n_samples_1, n_samples_2)
    Examples
    >>> from scikits.crab.metrics.pairwise import loglikehood_coefficient
    >>> X = [[\a\, \b\, \c\, \d\],  [\e\, \f\,\g\, \h\]]
    >>> # distance between rows of X
    >>> n_items = 7
    >>> loglikehood_coefficient(n_items,X, X)
    array([[ 1.,  0.],
    [ 0.,  1.]])
    >>> n_items = 8
    >>> loglikehood_coefficient(n_items, X, [[\a\, \b\, \c\, \k\]])
    array([[ 0.67668852],
    [ 0.        ]])
    References
    See http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.14.5962 and
    http://tdunning.blogspot.com/2008/03/surprise-and-coincidence.html.
    """
    def safeLog(d):
        if (d <= 0.0):
            return 0.0
        else:
            return np.log(d)
    def logL(p, k, n):
        return ((k * safeLog(p)) + ((n - k) * safeLog((1.0 - p))))
    def twoLogLambda(k1, k2, n1, n2):
        p = ((k1 + k2) / (n1 + n2))
        return (2.0 * (((logL((k1 / n1), k1, n1) + logL((k2 / n2), k2, n2)) - logL(p, k1, n1)) - logL(p, k2, n2)))
    if (X is Y):
        X = Y = np.asanyarray(X)
    else:
        X = np.asanyarray(X)
        Y = np.asanyarray(Y)
    result = []
    i = 0
    for arrayX in X:
        result.append([])
        for arrayY in Y:
            XY = np.intersect1d(arrayX, arrayY)
            if (XY.size == 0):
                result[i].append(0.0)
            else:
                nX = arrayX.size
                nY = arrayY.size
                if (((nX - XY.size) == 0) or ((n_items - nY) == 0)):
                    result[i].append(1.0)
                else:
                    logLikelihood = twoLogLambda(float(XY.size), float((nX - XY.size)), float(nY), float((n_items - nY)))
                    result[i].append((1.0 - (1.0 / (1.0 + float(logLikelihood)))))
        result[i] = np.asanyarray(result[i])
        i += 1
    return np.asanyarray(result)