<commit_before>"""OVK learning, unit tests.

The :mod:`sklearn.tests.test_semisuo` tests semisup module.
"""

import operalib as ovk
import numpy as np


def test_semisup_linop():
    """Test ovk.semisup.SemisupLinop."""
    np.random.seed()

    n = 100
    p = 5
    lbda2 = .1

    # supervised indices
    B = np.random.randint(2, size=(n), dtype=np.bool)

    # Graph Laplcian
    n_unsup = np.sum(~B)
    L = np.random.randn(n_unsup, n_unsup)
    L = np.dot(L, L.T)

    U, J = ovk.ridge._SemisupLinop(lbda2, B, L, p).gen()

    y = np.random.randn(n, p)
    # lbda2 * np.dot(L, y[~B, :]).ravel()
    # print(np.concatenate((y[B, :].ravel(),
    #                       lbda2 * np.dot(L, y[~B, :]).ravel())))

    res = np.empty((n, p))
    res[B, :] = y[B, :]
    res[~B] = 0
    assert np.allclose(J * y.ravel(), res.ravel())

    res = np.empty((n, p))
    res[B, :] = y[B, :]
    res[~B] = lbda2 * np.dot(L, y[~B, :])
    assert np.allclose(U * y.ravel(), res.ravel())<commit_msg>Fix type error in test for python 2.7<commit_after>"""OVK learning, unit tests.

The :mod:`sklearn.tests.test_semisuo` tests semisup module.
"""

import operalib as ovk
import numpy as np


def test_semisup_linop():
    """Test ovk.semisup.SemisupLinop."""
    np.random.seed()

    n = 100
    p = 5
    lbda2 = .1

    # supervised indices
    B = np.random.randint(2, size=(n)).astype(np.bool)

    # Graph Laplcian
    n_unsup = np.sum(~B)
    L = np.random.randn(n_unsup, n_unsup)
    L = np.dot(L, L.T)

    U, J = ovk.ridge._SemisupLinop(lbda2, B, L, p).gen()

    y = np.random.randn(n, p)
    # lbda2 * np.dot(L, y[~B, :]).ravel()
    # print(np.concatenate((y[B, :].ravel(),
    #                       lbda2 * np.dot(L, y[~B, :]).ravel())))

    res = np.empty((n, p))
    res[B, :] = y[B, :]
    res[~B] = 0
    assert np.allclose(J * y.ravel(), res.ravel())

    res = np.empty((n, p))
    res[B, :] = y[B, :]
    res[~B] = lbda2 * np.dot(L, y[~B, :])
    assert np.allclose(U * y.ravel(), res.ravel())
{'fraction_non_alphanumeric': 0.20349127182044888, 'fraction_numerical': 0.012967581047381545, 'mean_word_length': 2.4766031195840554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6320041', 'n_tokens_mistral': 912, 'n_tokens_neox': 864, 'n_words': 179}