def probability_anyone(n, p, k):
    """
    Returns the probability (aproximated) that in a G(n,p) i.e. ER-model a 
    random set of size k uniqely determines some vertex.
    Input:(int, float, int)
    Output: float
    """
    exitos = 0
    total = num_experiments

    for i in range(0, total):
        G = nx.gnp_random_graph(n, p)
        A = random_set(k, n)
        exitos = exitos + does_this_uniquely_det_someone(G, A)

    return exitos / float(total)
def probability_rigid_expansion(n, p, k):
    """
    Returns the probability (aproximated) that in a G(n,p) i.e. ER-model a 
    random set of size k generates a rigid expansion
    Input: int n, float p, int k
    Output: float
    """
    successes = 0
    total = 50

    for i in range(0, total):
        G = nx.gnp_random_graph(n, p)
        A = random_set(k, n)
        successes = successes + does_it_expands(G, A)

    return successes / float(total)
示例#3
0
def sample_jump(n, p, k, size):
    """
    Input: Graph G (dictionary), set A
    Output: Array
    """
    S = [0] * (size)

    if k * log(2) < log(n - k) + (k * p) * log(2):
        method = 1
    else:
        method = 2

    for i in range(size):
        G = nx.fast_gnp_random_graph(n, p)
        A = random_set(k, n)
        S[i] = jump_experiment(G, A, method)

    return S
def probability_subset(n, p, k, m):
    """
    Returns the probability (aproximated) that in a G(n,p) i.e. ER-model a 
    random set of size k uniquely determines some vertex.
    Input:(int, float, int)
    Output: float
    """
    successes = 0
    if m == 0:
        return 0

    else:
        for i in range(0, num_experiments):
            G = nx.fast_gnp_random_graph(n, p)
            A = random_set(k, n)
            successes = successes + does_subset_uniquely_det_someone(G, A, m)

        return successes / float(num_experiments)
示例#5
0
def vector_success_jump(n, p, k):
    """
    Input: Graph G (dictionary), set A
    Output: Int
    """
    V = [0] * (n + 1)

    if k * log(2) < log(n - k) + (k * p) * log(2):
        method = 1

    else:
        method = 2

    for i in range(numExp):
        G = nx.fast_gnp_random_graph(n, p)
        A = random_set(k, n)
        V[jump_experiment(G, A, method)] += 1

    return [x / numExp for x in V]
def probability_last(n, p, k):
    """
    Returns the empirical probability that in a G(n,p) i.e. ER-model a 
    random set of size k uniqely determines the nth-vertex.
    Input:(int, float, int)
    Output: float
    """
    exitos = 0
    total = num_experiments
    if k == n:
        return 0

    else:
        for i in range(0, total):
            G = nx.gnp_random_graph(n, p)
            A = random_set(k, n - 1)
            exitos = exitos + is_this_uniquely_det(G, A, n - 1)

        return exitos / float(total)
from numpy import log
from time import clock
import networkx as nx
import numpy as np
import matplotlib.pyplot as plt
from math import floor

def calculate_mean_expansion_time(n, p, k, case, number_of_experiments):
    """
    Input: n (int), p (float), k(int), case(dict), number_of_experiments(int)
    Output: Mean time, float
    """
    sumation = 0
    for e in range(number_of_experiments):
        A = random_set(k, n)
        starting_time = clock()
        if(case['optimizations'] == "none"):
            G = er_graph(n,p)
            rigid_expansion(G,A,p,False,False)
        else:
            G = nx.fast_gnp_random_graph(n, p)
            rigid_expansion(G,A,p,False,True)
        sumation += clock() - starting_time
    return 1000 * sumation/number_of_experiments

def time_execution_performance(n, p, samples_size, log_scale=False):
    """
    Plots a mean time rigid expansions experiments varing n, p  and k.
    Input: n (max graph size), p (list), samples_size(int)
    Output: Mean time, float