Esempio n. 1
0
def get_min_avg_max_sample_from_available_list(
    graph: gc.Graph,
    quantity: int,
    available_list: [],
    init_range: int = 2,
):
    degrees = graph.all_degrees()

    min_val: int = min(degrees)
    max_val: int = max(degrees)
    avg_val: int = int(round(((max_val - min_val) / 2) +
                             min_val))  # int(round(np.array(degrees).mean()))

    max_sample = __get_available_sample(graph=graph,
                                        degrees=degrees,
                                        center=max_val,
                                        init_range=init_range,
                                        quantity=quantity,
                                        available_list=available_list,
                                        neg_list=[])
    min_sample = __get_available_sample(graph=graph,
                                        degrees=degrees,
                                        center=min_val,
                                        init_range=init_range,
                                        quantity=quantity,
                                        available_list=available_list,
                                        neg_list=list(max_sample))
    avg_sample = __get_available_sample(graph=graph,
                                        degrees=degrees,
                                        center=avg_val,
                                        init_range=init_range,
                                        quantity=quantity,
                                        available_list=available_list,
                                        neg_list=list(max_sample) +
                                        list(min_sample))

    # print(f"samles: \n    max {max_sample}\n    min: {min_sample}\n    avg: {avg_sample}")
    samples = np.concatenate((max_sample, avg_sample, min_sample))

    assert (len(set(samples)) == len(samples))

    return samples
Esempio n. 2
0
def sample_low_avg_high_degree_nodes(graph: gc.Graph, quantity: int, init_range: int = 2, pref_list=None):
    if pref_list is None:
        pref_list = []
    degrees = graph.all_degrees()

    min_val: int = min(degrees)
    max_val: int = max(degrees)
    avg_val: int = int(round(((max_val - min_val) / 2) + min_val))  # int(round(np.array(degrees).mean()))

    nodes = graph.nodes()

    max_sample = __get_sample(graph=graph, degrees=degrees, center=max_val, init_range=init_range, quantity=quantity,
                              pref_list=pref_list, neg_list=[])
    min_sample = __get_sample(graph=graph, degrees=degrees, center=min_val, init_range=init_range, quantity=quantity,
                              pref_list=pref_list, neg_list=list(max_sample))
    avg_sample = __get_sample(graph=graph, degrees=degrees, center=avg_val, init_range=init_range, quantity=quantity,
                              pref_list=pref_list, neg_list=list(max_sample) + list(min_sample))

    # print(f"samles: \n    max {max_sample}\n    min: {min_sample}\n    avg: {avg_sample}")
    samples = np.concatenate((max_sample, avg_sample, min_sample))

    assert (len(set(samples)) == len(samples))

    return samples
Esempio n. 3
0
def __get_graph_degree_properties(graph: gc.Graph):
    degrees = graph.all_degrees()
    min_val = min(degrees)
    max_val = max(degrees)
    avg = np.mean(degrees)
    return min_val, max_val, avg