Beispiel #1
0
def pk_questionnaire(matrix,iters):
    col_data = matrix
    col_aff = qmain.local_geometry_norm_ip(col_data)
    p,eigvals,eigvecs = cdiff.diffusion_embed(col_aff,normalized=True)
    n_eigs = np.sum(np.abs(eigvals[~np.isnan(eigvals)]) > 1e-14)
    tree_cols = cdiff.cluster(eigvecs[:,1:n_eigs],eigvals[1:n_eigs])
    #tree_cols.disp_tree()
    
    row_data = qmain.extend_coords_means(matrix.T,tree_cols,False)
    row_aff = qmain.local_geometry_norm_ip(row_data)
    p,eigvals,eigvecs = cdiff.diffusion_embed(row_aff,normalized=True)
    n_eigs = np.sum(np.abs(eigvals[~np.isnan(eigvals)]) > 1e-14)
    tree_rows = cdiff.cluster(eigvecs[:,1:n_eigs],eigvals[1:n_eigs])
    #tree_rows.disp_tree()
    
    for i in xrange(iters):
        col_data = qmain.extend_coords_means(matrix,tree_rows,False,False)
        col_aff = qmain.local_geometry_gaussian(col_data,knn=100)
        p,col_eigvals,col_eigvecs = cdiff.diffusion_embed(col_aff,normalized=True)
        n_eigs = np.sum(np.abs(col_eigvals[~np.isnan(col_eigvals)]) > 1e-14)
        tree_cols = cdiff.cluster(col_eigvecs[:,1:n_eigs],col_eigvals[1:n_eigs])
        #tree_cols.disp_tree()
        
        row_data = qmain.extend_coords_means(matrix.T,tree_cols,False,False)
        row_aff = qmain.local_geometry_gaussian(row_data,knn=75)
        p,row_eigvals,row_eigvecs = cdiff.diffusion_embed(row_aff,normalized=True)
        n_eigs = np.sum(np.abs(row_eigvals[~np.isnan(row_eigvals)]) > 1e-14)
        tree_rows = cdiff.cluster(row_eigvecs[:,1:n_eigs],row_eigvals[1:n_eigs])
        #tree_rows.disp_tree()

    return tree_rows,tree_cols,row_eigvecs,col_eigvecs
Beispiel #2
0
def mmpi_questionnaire(matrix,iters):

    col_data = matrix
    col_aff = qmain.local_geometry_gaussian(col_data,knn=COLS_KNN,
                                            init_eps_pt=False,symm_inner=True)
    p,eigvals,eigvecs = cdiff.diffusion_embed(col_aff,n_eigs=N_COL_EIGS,
                                              normalized=True)
    n_eigs = np.sum(np.abs(eigvals[~np.isnan(eigvals)]) > 1e-14)
    tree_cols = cdiff.cluster(eigvecs[:,1:n_eigs],eigvals[1:n_eigs],
                              knn=CLUSTER_KNN)
    #tree_cols.disp_tree()
    
    row_data = qmain.extend_coords_means(matrix.T,tree_cols,
                                         weighted=WEIGHTED,
                                         singletons=SINGLETONS)
    #row_aff = qmain.local_geometry_norm_ip(row_data)
    row_aff = qmain.local_geometry_gaussian(row_data,knn=ROWS_KNN,
                                            init_eps_pt=False,symm_inner=True)
    p,eigvals,eigvecs = cdiff.diffusion_embed(row_aff,n_eigs=N_ROW_EIGS,
                                              normalized=True)
    n_eigs = np.sum(np.abs(eigvals[~np.isnan(eigvals)]) > 1e-14)
    tree_rows = cdiff.cluster(eigvecs[:,1:n_eigs],eigvals[1:n_eigs],
                              knn=CLUSTER_KNN)
    #tree_rows.disp_tree()
    
    for i in xrange(iters):
        col_data = qmain.extend_coords_means(matrix,tree_rows,
                                             weighted=WEIGHTED,
                                             singletons=SINGLETONS)
        col_aff = qmain.local_geometry_gaussian(col_data,knn=COLS_KNN,
                                            init_eps_pt=False,symm_inner=False)
        p,col_eigvals,col_eigvecs = cdiff.diffusion_embed(col_aff,
                                                          n_eigs=N_COL_EIGS,
                                                          normalized=True)
        #print col_eigvals
        n_eigs = np.sum(np.abs(col_eigvals[~np.isnan(col_eigvals)]) > 1e-14)
        tree_cols = cdiff.cluster(col_eigvecs[:,1:n_eigs],col_eigvals[1:n_eigs],
                                  knn=CLUSTER_KNN)
        #tree_cols.disp_tree()
        
        row_data = qmain.extend_coords_means(matrix.T,tree_cols,WEIGHTED,SINGLETONS)
        row_aff = qmain.local_geometry_gaussian(row_data,knn=ROWS_KNN,
                                                init_eps_pt=False,symm_inner=False)

        p,row_eigvals,row_eigvecs = cdiff.diffusion_embed(row_aff,
                                                          n_eigs=N_ROW_EIGS,
                                                          normalized=True)
        #print row_eigvals
        n_eigs = np.sum(np.abs(row_eigvals[~np.isnan(row_eigvals)]) > 1e-14)
        tree_rows = cdiff.cluster(row_eigvecs[:,1:n_eigs],row_eigvals[1:n_eigs],
                                  knn=CLUSTER_KNN)
        #tree_rows.disp_tree()

    return tree_rows,tree_cols,row_eigvecs,col_eigvecs,row_eigvals,col_eigvals

    
Beispiel #3
0
import qmain
import cluster_diffusion as cdiff
import numpy as np
import tree_utils
reload(qmain)
reload(cdiff)
reload(tree_utils)

matrix = np.zeros([128,256])
for i in xrange(128):
    for j in xrange(256):
        matrix[i,j] = np.sin(i*j*np.pi/256.0)

affinity = qmain.local_geometry_gaussian(matrix, 10)
p,eigvals,eigvecs = cdiff.diffusion_embed(affinity,normalized=True)
tree_cols = cdiff.cluster(eigvecs[:,1:],eigvals[1:])

#dual_affinity = qmain.dual_geometry_means(matrix.T, tree_cols, 4)
#p,eigvals,eigvecs = cdiff.diffusion_embed(dual_affinity,normalized=True)
#tree_rows = cdiff.cluster(eigvecs[:,1:],eigvals[1:])

new_aff = qmain.dual_geometry_norm_ip_max(matrix.T, tree_cols)
p,eigvals,eigvecs = cdiff.diffusion_embed(new_aff,normalized=True)
tree_rows = cdiff.cluster(eigvecs[:,1:],eigvals[1:])

new_col_aff = qmain.dual_geometry_norm_ip_max(matrix, tree_rows)
p,eigvals,eigvecs = cdiff.diffusion_embed(new_col_aff,normalized=True)
tree_cols2 = cdiff.cluster(eigvecs[:,1:],eigvals[1:])

new_row_aff = qmain.dual_geometry_norm_ip_max(matrix.T, tree_cols2)
p,eigvals,eigvecs = cdiff.diffusion_embed(new_row_aff,normalized=True)