modified_adsorption.py
def read_graph_seeds(self, graph_file, seed_file, nb_seeds=10, delimiter="\t"):
        """
        Quick and dirty way to get the adjacency matrix and seeds!
        """
        G = read_weighted_edgelist(graph_file, delimiter=delimiter)
        W = to_scipy_sparse_matrix(G)
        nodes_G = G.nodes()
        label_index = defaultdict(list)
        # Deal with seeds
        file_lines = open(seed_file, "r").readlines()
        seed_nodes, seed_labels, seed_values = [], [], []
        for idx, line in enumerate(file_lines):
            split_line = line.split(delimiter)
            node, label, value = split_line[0], split_line[1], float(split_line[2])
            seed_nodes.append(node)
            seed_labels.append(label)
            seed_values.append(value)
            label_index[label].append(idx)

        # Store golden_labels/seeds node name and their real value
        golden_labels = dict(zip(seed_nodes, seed_labels))

        unique_labels = sorted(set(seed_labels))
        labels_dict = {e: idx for idx, e in enumerate(unique_labels)}  # [L1, L2, L3,..., DUMMY]


        # Build the seeds matrix: number of nodes x number of labels + 1
        seeds_matrix = np.zeros(
            [W.shape[0], len(set(seed_labels)) + 1])  # We add 1 because of the "dummy" label used in the algorithm

        # Draw a n sample for each type of label
        label_samples = {}
        for k, v in label_index.items():
            temp_nb_seeds = nb_seeds if len(v) > nb_seeds else len(v)
            label_samples[k] = np.random.choice(v, temp_nb_seeds)

        # Once we have the sample for each class, we build the seeds matrix
        for label, seed_idx in label_samples.items():
            label_j = labels_dict.get(label)
            for i in seed_idx:
                seeds_matrix[i, label_j] = seed_values[i]

        return W, seeds_matrix, unique_labels, golden_labels, nodes_G

        Quick and dirty way to get the adjacency matrix and seeds!
        
Quick and dirty way to get the adjacency matrix and seeds!
Quick and dirty way to get the adjacency matrix and seeds!
def read_graph_seeds(self, graph_file, seed_file, nb_seeds=10, delimiter="\t"):
        G = read_weighted_edgelist(graph_file, delimiter=delimiter)
        W = to_scipy_sparse_matrix(G)
        nodes_G = G.nodes()
        label_index = defaultdict(list)
        file_lines = open(seed_file, "r").readlines()
        seed_nodes, seed_labels, seed_values = [], [], []
        for idx, line in enumerate(file_lines):
            split_line = line.split(delimiter)
            node, label, value = split_line[0], split_line[1], float(split_line[2])
            seed_nodes.append(node)
            seed_labels.append(label)
            seed_values.append(value)
            label_index[label].append(idx)
        golden_labels = dict(zip(seed_nodes, seed_labels))
        unique_labels = sorted(set(seed_labels))
        labels_dict = {e: idx for idx, e in enumerate(unique_labels)}  
        seeds_matrix = np.zeros(
            [W.shape[0], len(set(seed_labels)) + 1])  
        label_samples = {}
        for k, v in label_index.items():
            temp_nb_seeds = nb_seeds if len(v) > nb_seeds else len(v)
            label_samples[k] = np.random.choice(v, temp_nb_seeds)
        for label, seed_idx in label_samples.items():
            label_j = labels_dict.get(label)
            for i in seed_idx:
                seeds_matrix[i, label_j] = seed_values[i]
        return W, seeds_matrix, unique_labels, golden_labels, nodes_G
def read_graph_seeds ( self , graph_file , seed_file , nb_seeds = 10 , delimiter = "\t" ) : G = read_weighted_edgelist ( graph_file , delimiter = delimiter ) W = to_scipy_sparse_matrix ( G ) nodes_G = G . nodes ( ) label_index = defaultdict ( list ) file_lines = open ( seed_file , "r" ) . readlines ( ) seed_nodes , seed_labels , seed_values = [ ] , [ ] , [ ] for idx , line in enumerate ( file_lines ) : split_line = line . split ( delimiter ) node , label , value = split_line [ 0 ] , split_line [ 1 ] , float ( split_line [ 2 ] ) seed_nodes . append ( node ) seed_labels . append ( label ) seed_values . append ( value ) label_index [ label ] . append ( idx ) golden_labels = dict ( zip ( seed_nodes , seed_labels ) ) unique_labels = sorted ( set ( seed_labels ) ) labels_dict = { e : idx for idx , e in enumerate ( unique_labels ) } seeds_matrix = np . zeros ( [ W . shape [ 0 ] , len ( set ( seed_labels ) ) + 1 ] ) label_samples = { } for k , v in label_index . items ( ) : temp_nb_seeds = nb_seeds if len ( v ) > nb_seeds else len ( v ) label_samples [ k ] = np . random . choice ( v , temp_nb_seeds ) for label , seed_idx in label_samples . items ( ) : label_j = labels_dict . get ( label ) for i in seed_idx : seeds_matrix [ i , label_j ] = seed_values [ i ] return W , seeds_matrix , unique_labels , golden_labels , nodes_G
Quick and dirty way to get the adjacency matrix and seeds!
Quick and dirty way to get the adjacency matrix and seeds!
"""
        Quick and dirty way to get the adjacency matrix and seeds!
        """ # Deal with seeds # Store golden_labels/seeds node name and their real value # [L1, L2, L3,..., DUMMY] # Build the seeds matrix: number of nodes x number of labels + 1 # We add 1 because of the "dummy" label used in the algorithm # Draw a n sample for each type of label # Once we have the sample for each class, we build the seeds matrix
self
graph_file
seed_file
nb_seeds
delimiter