def test_joint_estmator_point(self):
        X = array([[0, 1], [1, 0], [1, 1]])
        y = array([[0, 1], [1, 0], [1, 0]])

        assert_array_approx_equal(
            joint_estimator_point(X, y), [[.5, 0], [.25, .25]])
        assert_array_approx_equal(
            joint_estimator_point(csr_matrix(X), csr_matrix(y)),
            [[.5, 0], [.25, .25]])
    def test_joint_estmator_point(self):
        X = array([[0, 1], [1, 0], [1, 1]])
        y = array([[0, 1], [1, 0], [1, 0]])

        assert_array_approx_equal(joint_estimator_point(X, y),
                                  [[.5, 0], [.25, .25]])
        assert_array_approx_equal(
            joint_estimator_point(csr_matrix(X), csr_matrix(y)),
            [[.5, 0], [.25, .25]])
Example #3
0
def pointwise_mutual_information(X,
                                 y,
                                 normalize=False,
                                 k_weight=None,
                                 positive=None):
    p_c = marginal_estimator(y, smoothing=True)
    p_t = marginal_estimator(X, smoothing=True)

    p_t.shape = 2, 1
    p_c.shape = 1, 2

    p_t_c = joint_estimator_point(X, y, smoothing=True)

    if k_weight:
        p_t_c = p_t_c**k_weight

    m = numpy.log(array(p_t_c) / (p_t * p_c))

    if normalize:
        m = m / -numpy.log(p_t_c)

    if positive is 'cutoff':
        m[m < .0] = .0

    if positive is 'exp':
        m = e**m

    return array(numpy.max(m, axis=1)).flatten()
def conditional_probabilities(X, y, ratio=False):
    p_t_c = joint_estimator_point(X, y, smoothing=True)
    p_t = marginal_estimator(X, smoothing=True)

    p_t.shape = 2,1

    m = p_t_c / p_t

    if ratio:
        p_c = marginal_estimator(y, smoothing=True)

        m = m / p_c

    return array(numpy.max(m, axis=1)).flatten()
Example #5
0
def conditional_probabilities(X, y, ratio=False):
    p_t_c = joint_estimator_point(X, y, smoothing=True)
    p_t = marginal_estimator(X, smoothing=True)

    p_t.shape = 2, 1

    m = p_t_c / p_t

    if ratio:
        p_c = marginal_estimator(y, smoothing=True)

        m = m / p_c

    return array(numpy.max(m, axis=1)).flatten()
def pointwise_mutual_information(X, y, normalize=False, k_weight=None, positive=None):
    p_c = marginal_estimator(y, smoothing=True)
    p_t = marginal_estimator(X, smoothing=True)

    p_t.shape = 2, 1
    p_c.shape = 1, 2

    p_t_c = joint_estimator_point(X, y, smoothing=True)

    if k_weight:
        p_t_c = p_t_c**k_weight

    m = numpy.log(array(p_t_c) / (p_t * p_c))

    if normalize:
        m = m / -numpy.log(p_t_c)

    if positive is 'cutoff':
        m[m < .0] = .0

    if positive is 'exp':
        m = e**m

    return array(numpy.max(m, axis=1)).flatten()