Exemplo n.º 1
0
def run_simulation(n, A1, multipartite_graph_matrix, iterations, partitions):
  correct_count = 0
  for i in range(0,iterations):
    A2 = Graph.create_adjacency_list(n,multipartite_graph_matrix) #need to do this as it hasn't updated the internal adjacency list representation

    # graph deconvolver with new components
    graph_deconvolver = GraphDeconvolver(n,A1,A2)

    #convolved graphs
    A_matrix  = Graph.create_adjacency_matrix(n,A1) + multipartite_graph_matrix

    status,problem_value,A1_star,A2_star= graph_deconvolver.deconvolve(A_matrix)

    # first check has the correct degree sequence before check multipartite, (needs to be complete)
    correct_degree_sequence = check_degree_sequence(partitions,np.round(A2_star)) # check_degree_sequence can't deal with weighted edges so round

    if correct_degree_sequence:
      adjacency_table = Graph.create_adjacency_table(n,A2_star)
      #print('p=',partitions,'\ng=',adjacency_table)
      multipartite_graph_recognizer=Multipartite_graph_recognizer(partitions,adjacency_table)
      ok=multipartite_graph_recognizer.check()
      print('multipartite:',multipartite_graph_recognizer.match)
    else:
      print('incorrect degree sequence')
      ok=False

    np.set_printoptions(suppress=True)
    print('Problem status: ',status)
    cycle = is_cycle(Graph.create_adjacency_list(n,A1_star))
    print('Is cycle: ', cycle)
    print('A2 correct: ',ok)

    if cycle and ok:
     correct_count +=1
  return correct_count
Exemplo n.º 2
0
def run_simulation(n,
                   multipartite_graph_matrix,
                   iterations,
                   partitions,
                   perturbation_scale=0.1):
    correct_count = 0

    graph_denoiser = GraphDenoiser(
        n, Graph.create_adjacency_list(n, multipartite_graph_matrix))

    # vector of small parameters for spectral hull
    epsilon_vector = epsilon * np.ones(n)

    for i in range(0, iterations):

        A_matrix_noisy = perturb_matrix(multipartite_graph_matrix,
                                        perturbation_scale)

        status, problem_value, A_recovered = graph_denoiser.denoise(
            A_matrix_noisy, epsilon_vector)

        # first check has the correct degree sequence before check multipartite, (needs to be complete)
        correct_degree_sequence = check_degree_sequence(
            partitions, np.round(A_recovered)
        )  # check_degree_sequence can't deal with weighted edges so round

        if correct_degree_sequence:
            adjacency_table = Graph.create_adjacency_table(n, A_recovered)
            multipartite_graph_recognizer = Multipartite_graph_recognizer(
                partitions, adjacency_table)
            ok = multipartite_graph_recognizer.check()
            print('multipartite:', multipartite_graph_recognizer.match)
        else:
            print('incorrect degree sequence')
            ok = False

        if ok:
            correct_count += 1
    return correct_count