コード例 #1
0
ファイル: SHAPLEYTESTS.py プロジェクト: TheHangman/P193
def t4():
    for j in range(0, 100):
        n = random.randint(3, 8)
        epsilon = 0.1
        delta = 0.1
        sample_size = math.ceil(2*(n+1)*math.log((n+1)/(2*delta))/(epsilon**2))
        test_weights = [random.random() for i in range(0, n+1)]
        exact_values = exact_shapley(test_weights, n)
        distribution = inverse_shapley.q_distribution(n)
        sum_distribution = sum(distribution)
        distribution = [distribution[i]/sum_distribution for i in range(0, len(distribution))]
        cumulative = inverse_shapley.q_cumulative(distribution, n)
        fcc = inverse_shapley.estimate_correlation(test_weights, sample_size, n, cumulative)
        fcc_avg = sum(fcc[1:n+1])/n
        rhs = [0]*n
        lhs = [0]*n
        for z in range(0, n):
            rhs[z] = 2.0/n + (sum_distribution/2.0)*(fcc[z+1] - fcc_avg)
            lhs[z] = exact_values[z]
        if inverse_shapley.l2_distance(lhs, rhs) > epsilon:
            print(test_weights)
            print(fcc)
            print(exact_values)
            print(lhs)
            print(rhs)
            print(inverse_shapley.l2_distance(lhs, rhs))
コード例 #2
0
ファイル: SHAPLEYTESTS.py プロジェクト: TheHangman/P193
def t1():
    n = random.randint(3, 50)
    distribution = inverse_shapley.q_distribution(n)
    sum_distribution = sum(distribution)
    distribution = [distribution[i]/sum_distribution for i in range(0, len(distribution))]
    cumulative = inverse_shapley.q_cumulative(distribution, n)
    print(sum(distribution))
    # plotting from matplotlib
    # pyplot.plot(cumulative)
    # pyplot.show()
    z = 1000
    K = [0]*z
    for i in range(0, z):
        K[i] = inverse_shapley.sample_k(cumulative, n)
コード例 #3
0
ファイル: SHAPLEYTESTS.py プロジェクト: TheHangman/P193
def t5():
    for j in range(0, 100):
        n = random.randint(3, 8)
        epsilon = 0.1
        delta = 0.1
        sample_size = math.ceil(2*(n+1)*math.log((n+1)/(2*delta))/((epsilon/16)**2))
        test_weights = [random.random() for i in range(0, n+1)]
        exact_values = exact_shapley(test_weights, n)
        distribution = inverse_shapley.q_distribution(n)
        sum_distribution = sum(distribution)
        distribution = [distribution[i]/sum_distribution for i in range(0, len(distribution))]
        cumulative = inverse_shapley.q_cumulative(distribution, n)
        fcc = inverse_shapley.estimate_correlation(test_weights, sample_size, n, cumulative)
        output_weights = inverse_shapley.boosting_ttv(fcc, epsilon, n, cumulative, sample_size)
        print(inverse_shapley.l2_distance(output_weights,exact_values))