Пример #1
0
def gen_syn2(nb_shapes=100, width_basis=350, feature_generator=None):
    basis_type = 'ba'

    random_mu = [0.0] * 8
    random_sigma = [1.0] * 8
    # Create two grids
    #mu_1, sigma_1 = np.array([0.05 * i for i in range(10)]), np.array([0.5] * 10)
    #mu_2, sigma_2 = np.array([1 - 0.05 * i for i in range(10)]), np.array([0.5] * 10)
    mu_1, sigma_1 = np.array([-1.0] * 2 + random_mu), np.array([0.5] * 2 +
                                                               random_sigma)
    mu_2, sigma_2 = np.array([1.0] * 2 + random_mu), np.array([0.5] * 2 +
                                                              random_sigma)
    feat_gen_G1 = featgen.GaussianFeatureGen(mu=mu_1, sigma=sigma_1)
    feat_gen_G2 = featgen.GaussianFeatureGen(mu=mu_2, sigma=sigma_2)
    G1, role_id1, name = gen_syn1(feature_generator=feat_gen_G1, m=4)
    G2, role_id2, name = gen_syn1(feature_generator=feat_gen_G2, m=4)
    G1_size = G1.number_of_nodes()
    num_roles = max(role_id1) + 1
    role_id2 = [r + num_roles for r in role_id2]
    label = role_id1 + role_id2

    #G1 = nx.grid_graph(dim=[N,N])
    #G2 = nx.grid_graph(dim=[N,N])
    # Edit node ids to avoid collisions on join
    g1_map = {n: i for i, n in enumerate(G1.nodes())}
    G1 = nx.relabel_nodes(G1, g1_map)
    g2_map = {n: i + G1_size for i, n in enumerate(G2.nodes())}
    G2 = nx.relabel_nodes(G2, g2_map)

    # Create node features
    #com_choices_1 = [0,1]
    #feat_gen_G1 = featgen.GridFeatureGen(mu=mu_1, sigma=sigma_1, com_choices=com_choices_1)
    #communities_G1 = feat_gen_G1.gen_node_features(G1)

    #com_choices_2 = [2,3]
    #feat_gen_G2 = featgen.GridFeatureGen(mu=mu_2, sigma=sigma_2, com_choices=com_choices_2)
    #communities_G2 = feat_gen_G2.gen_node_features(G2)

    # Join
    #n_pert_edges = int(np.log(N)) + 1;
    n_pert_edges = width_basis
    G = join_graph(G1, G2, n_pert_edges)

    #communities = {**communities_G1, **communities_G2}
    #communities = list(communities.values())
    #print(label)
    #name = basis_type + '_N_' + str(N) + '_classes_' + str(n_classes) + '_pert_' + str(n_pert_edges)
    name = basis_type + '_' + str(width_basis) + '_' + str(
        nb_shapes) + '_2comm'

    return G, label, name
Пример #2
0
def gen_syn2(nb_shapes=100, width_basis=350):
    """ Synthetic Graph #2:

    Start with Barabasi-Albert graph and add node features indicative of a community label.

    Args:
        nb_shapes         :  The number of shapes (here 'houses') that should be added to the base graph.
        width_basis       :  The width of the basis graph (here 'Barabasi-Albert' random graph).

    Returns:
        G                 :  A networkx graph
        label             :  Label of the nodes (determined by role_id and community)
        name              :  A graph identifier
    """
    basis_type = "ba"

    random_mu = [0.0] * 8  # Change to 9
    random_sigma = [1.0] * 8  # Change to 9

    # # Create two grids   # CHANGES BELOW was (-1) and 2 respectively (LHS)
    # mu_1, sigma_1 = np.array([-2.0] * 1 + random_mu), np.array([0.5] * 1 + random_sigma)
    # mu_2, sigma_2 = np.array([2.0] * 1 + random_mu), np.array([0.5] * 1 + random_sigma)

    # Create two grids
    mu_1, sigma_1 = np.array([-1.0] * 2 + random_mu), np.array([0.5] * 2 +
                                                               random_sigma)
    mu_2, sigma_2 = np.array([1.0] * 2 + random_mu), np.array([0.5] * 2 +
                                                              random_sigma)
    feat_gen_G1 = featgen.GaussianFeatureGen(mu=mu_1, sigma=sigma_1)
    feat_gen_G2 = featgen.GaussianFeatureGen(mu=mu_2, sigma=sigma_2)
    G1, role_id1, name = gen_syn1(feature_generator=feat_gen_G1, m=4)
    G2, role_id2, name = gen_syn1(feature_generator=feat_gen_G2, m=4)
    G1_size = G1.number_of_nodes()
    num_roles = max(role_id1) + 1
    role_id2 = [r + num_roles for r in role_id2]
    label = role_id1 + role_id2

    # Edit node ids to avoid collisions on join
    g1_map = {n: i for i, n in enumerate(G1.nodes())}
    G1 = nx.relabel_nodes(G1, g1_map)
    g2_map = {n: i + G1_size for i, n in enumerate(G2.nodes())}
    G2 = nx.relabel_nodes(G2, g2_map)

    # Join
    n_pert_edges = width_basis
    G = join_graph(G1, G2, n_pert_edges)

    name = basis_type + "_" + str(width_basis) + "_" + str(
        nb_shapes) + "_2comm"

    return G, label, name