Exemplo n.º 1
0
def test_blend_2():
    from divisi2.blending import blend, blend_svd
    Uref, Sref, Vref = blend([mat_4x3, third_mat_4x3]).svd(k=2)
    U, S, V = blend_svd([mat_4x3, third_mat_4x3], k=2)
    rec_ref = dot(Uref * Sref, Vref.T)
    rec_opt = dot(U * S, V.T)
    assert np.allclose(rec_ref, rec_opt)
Exemplo n.º 2
0
def make_blend(thefile):
    conceptnet = divisi2.network.conceptnet_matrix('en')
    thegame = divisi2.load(thefile).normalize_all()
    blended_matrix = blend(conceptnet, thegame)
    u,s,v = blended_matrix().svd()
    
    similarity = divisi2.reconstruct_similarity(u,s)
    pd[thefile.split('.')[0]] = similarity
    return similarity
Exemplo n.º 3
0
def test_cnet_blend():
    from divisi2.blending import blend, blend_svd
    matrix = divisi2.network.conceptnet_matrix('en')
    isa = divisi2.network.filter_by_relation(matrix, 'IsA').squish().normalize_all()
    atloc = divisi2.network.filter_by_relation(matrix, 'AtLocation').squish().normalize_all()
    Uref, Sref, Vref = blend([isa, atloc]).svd(k=3)
    U, S, V = blend_svd([isa, atloc], k=3)
    rec_ref = divisi2.reconstruct(Uref, Sref, Vref)
    rec_opt = divisi2.reconstruct(U, S, V)

    # Check a random sampling of the items.
    import random
    for row in random.sample(rec_ref.row_labels, 50):
        for col in random.sample(rec_ref.col_labels, 50):
            assert np.allclose(rec_ref.entry_named(row, col),
                               rec_opt.entry_named(row, col))