示例#1
0
    def __init__(self,
                 nodes_degree,
                 size=2,
                 down_sampling=0,
                 seed=1,
                 path_labels='data/',
                 input_file=None,
                 f_type=t.FloatTensor):
        '''
        :param nodes_degree: Dict with node_id: degree of node
        :param size: projection space
        :param downsampling: perform downsampling of common node
        :param seed: seed for random function
        :param index2node: index between a node and its representation

        :param path_labels: location of the file containing the ground true (label for each node)
        :param input_file: name of the file containing the ground true (label for each node)
        :return:
        '''
        global float_tensor
        float_tensor = f_type

        self.down_sampling = down_sampling
        self.seed = seed

        if size % 4 != 0:
            log.warn(
                "consider setting layer size to a multiple of 4 for greater performance"
            )
        self.layer1_size = int(size)

        if nodes_degree is not None:
            self.build_vocab_(nodes_degree)
            self.ground_true, self.k = load_ground_true(path=path_labels,
                                                        file_name=input_file)
            # inizialize node and context embeddings
            self.reset_weights()
            self.compute_negative_sampling_weight()
        else:
            log.info("Model not initialized")
示例#2
0
    def __init__(self,
                 nodes_degree=None,
                 size=2,
                 down_sampling=0,
                 seed=1,
                 table_size=100000000,
                 path_labels='data/',
                 input_file=None):
        '''
        :param nodes_degree: Dict with node_id: degree of node
        :param size: projection space
        :param down_sampling: perform down_sampling of common node
        :param seed: seed for random function
        :param table_size: size of the negative table to generate
        :param path_labels: location of the file containing the ground true (label for each node)
        :param input_file: name of the file containing the ground true (label for each node)
        :return:
        '''

        self.down_sampling = down_sampling
        self.seed = seed
        self.table_size = table_size
        if size % 4 != 0:
            log.warning(
                "consider setting layer size to a multiple of 4 for greater performance"
            )
        self.layer1_size = int(size)

        if nodes_degree is not None:
            self.build_vocab_(nodes_degree)
            self.ground_true, self.k = load_ground_true(path=path_labels,
                                                        file_name=input_file)
            # initialize node and context embeddings
            self.make_table()
            self.precalc_sampling()
            self.reset_weights()
        else:
            log.warning("Model not initialized, need the nodes degree")
示例#3
0
文件: main.py 项目: abegehr/ComE_BGMM
                f"./plots/{output_file}/animation_{come_model_type}_d{representation_size}_k{k}.gif",
                writer='imagemagick')

        # ### write predictions to labels_pred.txt
        # save com_learner.g_mixture to file
        joblib.dump(
            com_learner.g_mixture,
            f'./model/g_mixture_{output_file}_{come_model_type}_d{representation_size}_k{k}.joblib'
        )
        # using predictions from com_learner.g_mixture with node_embeddings
        np.savetxt(
            f'./data/{output_file}/labels_pred_{come_model_type}_d{representation_size}_k{k}.txt',
            model.classify_nodes())

        # ### NMI
        labels_true, _ = load_ground_true(path="data/" + input_file,
                                          file_name=input_file)
        print("labels_true: ", labels_true)
        if labels_true is not None:
            nmi = metrics.normalized_mutual_info_score(labels_true,
                                                       node_classification)
            print(
                f"===NMI=== for type={come_model_type} with d={representation_size} and K={k}: ",
                nmi)
        else:
            print(
                f"===NMI=== for type={come_model_type} with d={representation_size} and K={k} could not be computed"
            )

        # ### plotting
        plot_name = f"{come_model_type}_d{representation_size}_k{k}"
        if should_plot: