Ejemplo n.º 1
0
def test_wizard_merge():

    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)

    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    target = clusters_unique[np.argmax(quality)]

    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()

    cluster = w.current_candidate()

    # Simulate a merge: target and cluster ==> cluster_new.
    cluster_new = clusters_unique.max() + 1
    clusters[clusters == target] = cluster_new
    clusters[clusters == cluster] = cluster_new
    log.debug("Merged {0:d} and {1:d} to {2:d}".format(target, cluster,
                                                       cluster_new))
    similarity_matrix = create_similarity_matrix(nclusters - 1)
    indices = [
        x for x in xrange(cluster_offset, cluster_offset + nclusters + 1)
        if x != cluster and x != target
    ]
    cluster_groups = pd.Series(np.array(np.ones(nclusters - 1) * 3,
                                        dtype=np.int32),
                               index=np.array(indices))

    # Update the wizard.
    quality = np.diag(similarity_matrix)
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates(cluster_new)

    assert w.current_target() == cluster_new

    c = w.current_candidate()
    assert c is not None
    assert w.previous_candidate() == w.current_candidate()
    assert w.next_candidate() == c

    for _ in xrange(nclusters):
        c = w.next_candidate()
        assert c not in (target, cluster)
Ejemplo n.º 2
0
def test_wizard():

    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)

    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    best_cluster = clusters_unique[np.argmax(quality)]

    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()

    # Check the first target cluster.
    assert w.current_target() == best_cluster

    # Test impossible previous.
    assert w.previous_candidate() == w.current_candidate()

    # Check next/previous.
    c0 = w.next_candidate()
    c1 = w.next_candidate()
    assert w.previous_candidate() == c0
    assert w.next_candidate() == c1

    # Check skip target.
    t0 = w.current_target()
    w.skip_target()
    w.update_candidates()
    t1 = w.current_target()
    assert t0 != t1
Ejemplo n.º 3
0
def test_wizard():
    
    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)
    
    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    best_cluster = clusters_unique[np.argmax(quality)]
    
    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()
    
    # Check the first target cluster.
    assert w.current_target() == best_cluster
    
    # Test impossible previous.
    assert w.previous_candidate() == w.current_candidate()
    
    # Check next/previous.
    c0 = w.next_candidate()
    c1 = w.next_candidate()
    assert w.previous_candidate() == c0
    assert w.next_candidate() == c1
    
    # Check skip target.
    t0 = w.current_target()
    w.skip_target()
    w.update_candidates()
    t1 = w.current_target()
    assert t0 != t1
Ejemplo n.º 4
0
def test_wizard_merge():
    
    # Create mock data.
    clusters = create_clusters(nspikes, nclusters)
    cluster_groups = create_cluster_groups(nclusters)
    similarity_matrix = create_similarity_matrix(nclusters)
    quality = np.diag(similarity_matrix)
    
    # Get the best clusters.
    clusters_unique = np.unique(clusters)
    target = clusters_unique[np.argmax(quality)]
    
    # Initialize the wizard.
    w = Wizard()
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates()
    
    cluster = w.current_candidate()
    
    # Simulate a merge: target and cluster ==> cluster_new.
    cluster_new = clusters_unique.max() + 1
    clusters[clusters == target] = cluster_new
    clusters[clusters == cluster] = cluster_new
    log.debug("Merged {0:d} and {1:d} to {2:d}".format(
        target, cluster, cluster_new))
    similarity_matrix = create_similarity_matrix(nclusters - 1)
    indices = [x for x in xrange(cluster_offset, cluster_offset + nclusters + 1)
                    if x != cluster and x != target]
    cluster_groups = pd.Series(np.array(np.ones(nclusters - 1) * 3, dtype=np.int32),
        index=np.array(indices))
    
    # Update the wizard.
    quality = np.diag(similarity_matrix)
    w.set_data(similarity_matrix=similarity_matrix,
               cluster_groups=cluster_groups)
    w.update_candidates(cluster_new)
    
    assert w.current_target() == cluster_new
    
    c = w.current_candidate()
    assert c is not None
    assert w.previous_candidate() == w.current_candidate()
    assert w.next_candidate() == c
    
    for _ in xrange(nclusters):
        c = w.next_candidate()
        assert c not in (target, cluster)