Ejemplo n.º 1
0
Archivo: main.py Proyecto: SongFGH/ComE
                               edges=edges,
                               iter=iter_node,
                               chunksize=batch_size)



            cont_learner.train(model,
                               paths=graph_utils.combine_files_iter(walk_files),
                               total_nodes=context_total_path,
                               alpha=alpha,
                               chunksize=batch_size)
            com_learner.fit(model, reg_covar=reg_covar, n_init=10)
            com_learner.train(G.nodes(), model, beta, chunksize=batch_size, iter=iter_com)

            log.info('time: %.2fs' % (timeit.default_timer() - start_time))
            node_color = plot_utils.graph_plot(G,
                                               graph_name=input_file,
                                               show=False)

            plot_utils.node_space_plot_2D_elipsoid(model.node_embedding, node_color,
                                                   means=model.centroid,
                                                   covariances=model.covariance_mat,
                                                   show=True)


            # io_utils.save_embedding(model.node_embedding, model.vocab,
            #                         file_name="{}_alpha-{}_beta-".format(output_file,
            #                                                              alpha,
            #                                                              beta))

Ejemplo n.º 2
0
import numpy as np

input_file = 'karate'
node_embedding = io_utils.load_embedding(
    path='../data',
    file_name="{}_my_ComE_l1-0_l2-0_ds-0_it-0".format(input_file),
    ext=".txt")

g = mixture.GaussianMixture(n_components=2,
                            reg_covar=0.000001,
                            covariance_type='full',
                            n_init=5)
g.fit(node_embedding)
centroid = np.float32(g.means_)
covariance_mat = np.float32(g.covariances_)

G = graph_utils.load_adjacencylist(
    path_join("../data/", input_file, input_file + '.adjlist'), True)
node_color = plot_utils.graph_plot(G=G,
                                   show=False,
                                   graph_name="karate",
                                   node_position_file=True,
                                   node_position_path='../data')

plot_utils.node_space_plot_2D_elipsoid(node_embedding,
                                       means=centroid,
                                       covariances=covariance_mat,
                                       color_values=node_color,
                                       grid=False,
                                       show=True)
Ejemplo n.º 3
0
                                                       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:
            # graph_plot
            plot_utils.graph_plot(G,
                                  labels=node_classification,
                                  plot_name=plot_name,
                                  path=f"./plots/{output_file}",
                                  save=True,
                                  show_labels=False)
            # node_space_plot_2D
            plot_utils.node_space_plot_2d(model.node_embedding,
                                          labels=node_classification,
                                          plot_name=plot_name,
                                          path=f"./plots/{output_file}",
                                          save=True)
            # node_space_plot_2d_ellipsoid
            plot_utils.node_space_plot_2d_ellipsoid(
                model.node_embedding,
                labels=node_classification,
                means=com_learner.g_mixture.means_,
                covariances=com_learner.g_mixture.covariances_,
                plot_name=plot_name,