Ejemplo n.º 1
0
def no_arbitage_wagering(forecasts, wagers, f_norm=f_norm_Brier_subgradient):
    # forecasters - the predicted probability of a binary random variable
    #               by each forecasters
    # f_norm - f_norm_function()
    # !!! requires normalizing the range of score rule to [0,1]

    if np.ndim(forecasts) > 1:
        print("No_arbitage_wagering(): forecasters dimension error!")
        return 0

    n = np.shape(forecasts)[0]
    w = wagers
    sum_w = np.sum(w)
    p = forecasts
    P_matrix = np.column_stack((p, 1 - p))
    coefficient = np.multiply(w, sum_w - w) / sum_w
    p_bar = np.zeros(n)
    for i in range(n):
        w_zero_i = np.array(w)
        w_zero_i[i] = 0
        p_bar[i] = f_norm(p, w_zero_i)
    P_bar_matrix = np.column_stack((p_bar, 1 - p_bar))
    scores = (sc.Brier_score(P_matrix, b=0.5, a=-0.5) -
              sc.Brier_score(P_bar_matrix, b=0.5, a=-0.5))
    return coefficient[:, None] * scores
Ejemplo n.º 2
0
def surrogate_NAWM(forecasts, wagers, f_norm=f_norm_Brier_subgradient, e1=0.25, e0=0.25):
    # forecasters - the predicted probability of a binary random variable
    #               by each forecasters
    # f_norm - f_norm_function()
    # !!! requires normalizing the range of score rule to [0,1]
    # e1, e0 - outcome-flipped rate under outcome 1 and 0
    if np.ndim(forecasts) > 1:
        print("No_arbitage_wagering(): forecasters dimension error!")
        return 0

    n = np.shape(forecasts)[0]
    w = wagers
    sum_w = np.sum(w)
    p = forecasts
    P_matrix = np.column_stack((p, 1 - p))
    coefficient = np.multiply(w, sum_w - w) / sum_w
    p_bar = np.zeros(n)
    for i in range(n):
        w_zero_i = np.array(w)
        w_zero_i[i] = 0
        p_bar[i] = f_norm(p, w_zero_i)
    P_bar_matrix = np.column_stack((p_bar, 1 - p_bar))

    # if the outcome is 1:
    score1 = np.zeros(n)
    for i in range(n):
        tmp1= sc.Brier_score(P_matrix[i, :].reshape(1, -1), b=0.5, a=-0.5)
        tmp2 = sc.Brier_score(P_bar_matrix[i, :].reshape(1, -1), b=0.5, a=-0.5)
        s1 = tmp1[0, 0]
        s0 = tmp1[0, 1]
        avg_s1 = tmp2[0, 0]
        avg_s0 = tmp2[0, 1]
        if (np.random.rand() < e1): # outcome flipped to 0
            score1[i] = (surrogate_score(s1=s1, s0=s0, e1=e1, e0=e0, outcome=0)
                         - surrogate_score(s1=avg_s1, s0=avg_s0, e1=e1, e0=e0, outcome=0)
                        )
        else: 
            score1[i] = (surrogate_score(s1=s1, s0=s0, e1=e1, e0=e0, outcome=1)
                         - surrogate_score(s1=avg_s1, s0=avg_s0, e1=e1, e0=e0, outcome=1)
                        )

    # if the outcome is 0:
    score0 = np.zeros(n)
    for i in range(n):
        tmp1= sc.Brier_score(P_matrix[i, :].reshape(1, -1), b=0.5, a=-0.5)
        tmp2 = sc.Brier_score(P_bar_matrix[i, :].reshape(1, -1), b=0.5, a=-0.5)
        s1 = tmp1[0, 0]
        s0 = tmp1[0, 1]
        avg_s1 = tmp2[0, 0]
        avg_s0 = tmp2[0, 1]
        if (np.random.rand() < e1): # outcome flipped to 1
            score0[i] = (surrogate_score(s1=s1, s0=s0, e1=e1, e0=e0, outcome=1)
                         - surrogate_score(s1=avg_s1, s0=avg_s0, e1=e1, e0=e0, outcome=1)
                        )
        else: 
            score0[i] = (surrogate_score(s1=s1, s0=s0, e1=e1, e0=e0, outcome=0)
                         - surrogate_score(s1=avg_s1, s0=avg_s0, e1=e1, e0=e0, outcome=0)
                        )

    return coefficient[:, None] * np.vstack((score1, score0)).T
def no_arbitrage_wagering(forecasts, wagers, f_norm=f_norm_Brier_subgradient):
    # forecasts - the predicted probability of a  random variable
    #               by each forecasters
    # f_norm - f_norm_function()
    # !!! requires normalizing the range of score rule to [0,1]
    # return value

    n, m = np.shape(forecasts)
    w = wagers
    sum_w = np.sum(w)
    coefficient = np.multiply(w, sum_w - w) / sum_w
    p_bar = np.zeros((n, m))
    for i in range(n):
        w_zero_i = np.array(w)
        w_zero_i[i] = 0
        p_bar[i, :] = f_norm(forecasts, w_zero_i)
    scores = (sc.Brier_score(forecasts, b=1, a=-0.5) -
              sc.Brier_score(p_bar, b=1, a=-0.5))
    return coefficient[:, None] * scores
Ejemplo n.º 4
0
import numpy as np
import scores as sc  # source: scores.py
import matplotlib.pyplot as plt

# Set the outcome and participant
d = 2  # # of realizations of outcome
n = 4  # # of participants

# Generate the ground truth distribution of the outcome
p_truth = np.random.dirichlet(np.ones((d, )))

# Generate participants' true believes and each row represents one belief
forecasts = np.random.dirichlet(np.ones((d, )), size=n)
forecasts = np.vstack([[1, 0], [1, 0], [0, 1], [0, 1]])
print(forecasts)
Brier_scores = sc.Brier_score(forecasts)
competitive_scores = sc.competitive_score_rule(sc.Brier_score(forecasts))

np.set_printoptions(precision=3, suppress=True)
# print((quadratic_scores[:,0],competitive_quadratic_scores[:,0]))
print(np.column_stack((Brier_scores[:, 0], competitive_scores[:, 0])))
# print(np.reshape(quadratic_scores[:,0]-competitive_quadratic_scores[:,0]-(quadratic_scores[0,0]-competitive_quadratic_scores[0,0]),(-1,1)))
'''

# Set the number of realizations of a future event
d = 2 # # of realizations of a future event

running_times = 1000
range_n = range(5,101,5)
average_average = []
average_max = []
Ejemplo n.º 5
0
    for t in range(running_times):
        # Generate forecasters' true believes and each row represents one belief
        forecasts = np.random.dirichlet(np.ones((d,)), size=n)
        # forecasts = np.random.dirichlet([1, 0.2], size=n)
        # forecasts = np.random.dirichlet([0.3, 0.3], size=n)
        forecasts[0, :] = [1, 0]
        # print(forecasts)

        # Generate forecasters' wagers
        wagers = np.ones((n,))
        # wagers = np.random.beta(100, 100, size=n)
        # wagers = (np.random.pareto(1.16, size=n) + 1) * 1
        total_wager = np.sum(wagers)

        # Compute the outcome of no-arbitage wagering mechanism under each realization
        net_pays_CSR = sc.competitive_score_rule(sc.Brier_score(forecasts, 2, -1)) / 2
        net_pays_NAW = wg.no_arbitage_wagering(forecasts[:, 0], wagers)
        net_pays_PPM = wg.net_payoff_PPM(forecasts, wagers)

        # value duplication for further modification
        MnEx_CSR_PS, MnEx_NAW_PS, MnEx_PPM_PS = (np.array(net_pays_CSR),
                                                 np.array(net_pays_NAW),
                                                 np.array(net_pays_PPM))
        MnEx_CSR_NG, MnEx_NAW_NG, MnEx_PPM_NG = (np.array(net_pays_CSR),
                                                 np.array(net_pays_NAW),
                                                 np.array(net_pays_PPM))
        # print(net_pays_CSR)
        # print(net_pays_NAW)
        # print(net_pays_PPM)

        max_complete_right_CSR = max(net_pays_CSR[0, 0], max_complete_right_CSR)
Ejemplo n.º 6
0
import numpy as np
import scores as sc  #source: scores.py
import wager as wg  #source: wagers.py
import matplotlib.pyplot as plt

# Set the outcome vand participant
d = 2  # # of realizations of outcome
n = 100  # # of participants

# Generate the ground truth distribution of the outcome
p_truth = np.random.dirichlet(np.ones((d, )))
# print(p_truth)

# Generate participants' true believes and each row represents one belief
forecasts = np.random.dirichlet(np.ones((d, )), size=n)
quadratic_scores = -sc.Brier_score(forecasts)
competitive_quadratic_scores = sc.competitive_quadratic_score_rule(forecasts)

np.set_printoptions(precision=3, suppress=True)
# print((quadratic_scores[:,0],competitive_quadratic_scores[:,0]))
print(
    np.column_stack((quadratic_scores[:, 0], competitive_quadratic_scores[:,
                                                                          0])))
print(
    np.reshape(
        quadratic_scores[:, 0] - competitive_quadratic_scores[:, 0] -
        (quadratic_scores[0, 0] - competitive_quadratic_scores[0, 0]),
        (-1, 1)))
'''

# Set the number of realizations of a future event