예제 #1
0
def test_quotient_bad_partition():
    with pytest.raises(ValueError):
        quotient_similarity(m, partition=[[0, 2], [3, 7]], check=True)
예제 #2
0
 def test_nx():
     mq1 = quotient_similarity(m, partition, agg='sum',
                               diag_value=0).todense()
     Gq = quotient_graph(G=G, partition=partition, edge_data=edge_sum)
     mq2 = to_numpy_array(Gq)
     assert allclose(mq1, mq2)
예제 #3
0
def test_quotient_custom():
    assert allclose(
        quotient_similarity(m, partition, agg=custom_agg, n_cpu=-1).todense(),
        m_merged)
예제 #4
0
def test_quotient_parallel():
    assert allclose(
        quotient_similarity(m, partition, agg='sum', n_cpu=-1).todense(),
        m_merged)
예제 #5
0
def test_quotient_wrong_agg_else():
    with pytest.raises(ValueError):
        quotient_similarity(m, partition, agg=array([]), n_cpu=1)
예제 #6
0
def test_quotient_wrong_agg_str():
    with pytest.raises(ValueError):
        quotient_similarity(m, partition, agg='ABCD', n_cpu=1)
예제 #7
0
    m[m < sim_thresh] = 0
    m = csr_matrix(m)
    # Generate IDs for partition
    ids = list(range(int(sqrt(r))))
    id_map = array(choices(ids, k=r))
    partition = [where(id_map == i)[0].tolist() for i in ids]
    # Networkx implementation
    start_time = timeit.default_timer()
    nx_G = nx.from_scipy_sparse_matrix(m)
    nx_Gq = nx.quotient_graph(G=nx_G, partition=partition)
    nx_q = nx.to_scipy_sparse_matrix(nx_Gq)
    nx_q.eliminate_zeros()
    nx_time.append(timeit.default_timer() - start_time)
    # PSS implementation
    start_time = timeit.default_timer()
    pss_q = quotient_similarity(m, partition, diag_value=0)
    pss_time.append(timeit.default_timer() - start_time)
    # Test and print
    if not allclose(nx_q.todense(), pss_q.todense()):
        raise ValueError('Quotient similarity matrix values diverged')
    print('END {} rows'.format(r))

plt.plot(n_rows,
         nx_time,
         color='black',
         linestyle='dashed',
         linewidth=2,
         label='Networkx')
plt.plot(n_rows, pss_time, color='green', linewidth=2, label='pysimscale')
plt.title('Quotient Similarity Graph')
plt.legend()