Exemple #1
0
    def community_detection(self, args: dict, status: dict, result: dict):
        status['status'] = 'running'

        # Get our parameters
        n_neighbors = args['n_neighbors']
        min_dist = args['min_dist']
        metric = args['metric']
        iterations = args['iterations']
        data = args['json_data']

        df = utils.get_matrix(data)
        columns = df.columns.values
        row_labels = df.index.values

        # We need to drop any NaNs
        df = df.dropna()

        data = df[
            columns[1:]].values  # skip over the label and just pull the data
        if (args['scale']):
            data = StandardScaler().fit_transform(data)

        reducer = umap.UMAP()
        embedding = reducer.fit_transform(data)

        result_df = pd.DataFrame(embedding, columns={'x', 'y'})
        result_df[columns[0]] = [str(x) for x in row_labels]
        result_list = []
        result_list.append(columns)
        for row in result_df.reset_index().values.tolist():
            result_list.append(row)

        result['embedding'] = result_list

        status['status'] = 'done'
Exemple #2
0
    def community_detection(self, args: dict, status: dict, result: dict):
        status['status'] = 'running'

        # Get our parameters
        n_neighbors = args['n_neighbors']
        reg = args['reg']
        eigen_solver = args['eigen_solver']
        tol = args['tol']
        max_iter = args['max_iter']
        method = args['method']
        hessian_tol = args['hessian_tol']
        modified_tol = args['modified_tol']
        neighbors_algorithm = args['neighbors_algorithm']

        data = args['json_data']

        df = utils.get_matrix(data)
        columns = df.columns.to_list()
        row_labels = df.index.to_list()

        # We need to drop any NaNs
        df = df.dropna()

        data = df[
            columns[1:]].values  # skip over the label and just pull the data

        lle = LocallyLinearEmbedding(n_components=2,
                                     n_neighbors=n_neighbors,
                                     reg=reg,
                                     eigen_solver=eigen_solver,
                                     tol=tol,
                                     max_iter=max_iter,
                                     method=method,
                                     hessian_tol=hessian_tol,
                                     modified_tol=modified_tol,
                                     neighbors_algorithm=neighbors_algorithm,
                                     n_jobs=10)
        embedding = lle.fit_transform(data)
        #print(str(embedding))

        result_df = pd.DataFrame(embedding, columns=['x', 'y'])
        result_df.insert(0, "Node", row_labels)
        #print(str(result_df))
        # result_df[columns[0]] = [str(x) for x in row_labels]
        result_list = []
        result_list.append(['Node', 'x', 'y'])
        for row in result_df.reset_index().values.tolist():
            result_list.append(row[1:])

        result['embedding'] = result_list

        status['status'] = 'done'
Exemple #3
0
    def community_detection(self, args: dict, status: dict, result: dict):
        status['status'] = 'running'

        # Get our parameters
        metric = args['metric']
        n_init = args['n_init']
        max_iter = args['max_iter']
        eps = args['eps']
        dissimilarity = args['dissimilarity']
        data = args['json_data']

        df = utils.get_matrix(data)
        columns = df.columns.to_list()
        row_labels = df.index.to_list()

        # We need to drop any NaNs
        df = df.dropna()

        data = df[
            columns[1:]].values  # skip over the label and just pull the data

        mds = manifold.MDS(n_components=2,
                           n_init=n_init,
                           eps=eps,
                           dissimilarity=dissimilarity,
                           metric=metric,
                           max_iter=max_iter,
                           n_jobs=10)
        embedding = mds.fit_transform(data)
        #print(str(embedding))

        result_df = pd.DataFrame(embedding, columns=['x', 'y'])
        result_df.insert(0, "Node", row_labels)
        #print(str(result_df))
        # result_df[columns[0]] = [str(x) for x in row_labels]
        result_list = []
        result_list.append(['Node', 'x', 'y'])
        for row in result_df.reset_index().values.tolist():
            result_list.append(row[1:])

        result['embedding'] = result_list

        status['status'] = 'done'
Exemple #4
0
    def community_detection(self, args: dict, status: dict, result: dict):
        status['status'] = 'running'

        # Get our parameters
        affinity = args['affinity']
        gamma = args['gamma']
        eigen_solver = args['eigen_solver']
        n_neighbors = args['n_neighbors']
        data = args['json_data']

        df = utils.get_matrix(data)
        columns = df.columns.to_list()
        row_labels = df.index.to_list()

        # We need to drop any NaNs
        df = df.dropna()

        data = df[
            columns[1:]].values  # skip over the label and just pull the data

        spectral = manifold.SpectralEmbedding(n_components=2,
                                              affinity=affinity,
                                              gamma=gamma,
                                              eigen_solver=eigen_solver,
                                              n_neighbors=n_neighbors,
                                              n_jobs=10)
        embedding = spectral.fit_transform(data)
        #print(str(embedding))

        result_df = pd.DataFrame(embedding, columns=['x', 'y'])
        result_df.insert(0, "Node", row_labels)
        #print(str(result_df))
        # result_df[columns[0]] = [str(x) for x in row_labels]
        result_list = []
        result_list.append(['Node', 'x', 'y'])
        for row in result_df.reset_index().values.tolist():
            result_list.append(row[1:])

        result['embedding'] = result_list

        status['status'] = 'done'
Exemple #5
0
    def community_detection(self, args: dict, status: dict, result: dict):
        status['status'] = 'running'

        # Get our parameters
        solver = args['solver']
        shrinkage = args['shrinkage']
        tol = args['tol']

        data = args['json_data']

        df = utils.get_matrix(data)
        columns = df.columns.to_list()
        row_labels = df.index.to_list()

        # We need to drop any NaNs
        df = df.dropna()

        data = df[
            columns[1:]].values  # skip over the label and just pull the data

        lda = LinearDiscriminantAnalysis(solver=solver,
                                         shrinkage=shrinkage,
                                         tol=tol)
        embedding = lda.fit_transform(data)
        #print(str(embedding))

        result_df = pd.DataFrame(embedding, columns=['x', 'y'])
        result_df.insert(0, "Node", row_labels)
        #print(str(result_df))
        # result_df[columns[0]] = [str(x) for x in row_labels]
        result_list = []
        result_list.append(['Node', 'x', 'y'])
        for row in result_df.reset_index().values.tolist():
            result_list.append(row[1:])

        result['embedding'] = result_list

        status['status'] = 'done'
Exemple #6
0
    def community_detection(self, args:dict, status:dict, result:dict):
        status['status'] = 'running'

        # Get our parameters
        perplexity = args['perplexity']
        early_ex = args['early_exaggeration']
        learning_rate = args['learning_rate']
        n_iter = args['n_iter']
        metric = args['metric']
        init = args['init']
        data = args['json_data']

        df = utils.get_matrix(data)
        columns = df.columns.to_list()
        row_labels = df.index.to_list()

        # We need to drop any NaNs
        df = df.dropna()

        data = df[columns[1:]].values # skip over the label and just pull the data
        tsne = TSNE(n_components=2, perplexity=perplexity,early_exaggeration=early_ex, learning_rate=learning_rate,
                    metric=metric, init=init, n_jobs=10)
        embedding = tsne.fit_transform(data)

        #print(str(embedding))

        result_df = pd.DataFrame(embedding, columns=['x','y'])
        result_df.insert(0,"Node",row_labels)
        #print(str(result_df))
        # result_df[columns[0]] = [str(x) for x in row_labels]
        result_list = []
        result_list.append(['Node','x','y'])
        for row in result_df.reset_index().values.tolist():
          result_list.append(row[1:])

        result['embedding'] = result_list

        status['status'] = 'done'