Esempio n. 1
0
def estimate_param(w, reputations):
    # get number of bidders
    n = reputations.size

    # estimate lower and upper extremities
    lower_extremities = np.array([(1-w)*r for r in reputations])
    upper_extremities = np.array([(1-w)*r + w for r in reputations])

    # estimate upper bound on bids
    b_upper = upper_bound_bids(lower_extremities, upper_extremities)

    # approximate
    param = 1e-6

    while True:
        if param > 1e-4:
            return None

        try:
            bids, costs = solve(w, reputations, param=param)
        except Exception:
            param += 1e-6
            continue

        # verify sufficiency
        cdfs = []
        for l,u in zip(lower_extremities, upper_extremities):
          cdfs.append(stats.uniform(loc=l, scale=u-l))

        step = len(bids) // 35
        sampled_bids, best_responses = best_responses(costs, bids, b_upper, cdfs, step=step)

        # calculate average error
        errors = []
        m = sampled_bids.shape[1]
        for i in range(n):
            error = 0
            for b,br in zip(sampled_bids[i], best_responses[i]):
                error += abs(b-br)

            errors.append(error / m)

        # Check if average is low for each bidder
        if all([e < 1e-2 for e in errors]):
            break

        # Update param
        param += 1e-6

    return param
Esempio n. 2
0
def solve(w, reputations):
    # infer number of bidders
    n = reputations.size

    # compute an array of lower and upper extremities
    lowers = np.empty(n, dtype=np.float)
    uppers = np.empty(n, dtype=np.float)

    for i in np.arange(n):
        r = reputations[i]
        lowers[i] = (1-w) * r
        uppers[i] = (1-w) * r + w

    # estimate the upper bound on bids
    b_upper = upper_bound_bids(lowers, uppers)

    # solve the system using EFSM method
    bids, costs = efsm.solve(w, reputations)

    # truncate solution derived by EFSM where k=n
    min_i = np.argmin(np.absolute(np.copy(costs[-1]) - lowers[-1]))
    initial = costs.T[min_i,:]
    b_lower = bids[min_i]
    length = bids.size - min_i
    bids = bids[:min_i]
    costs = costs[:,:min_i]

    # solve the system for k = n using PPM method
    coeffs = ppm.fit(initial, uppers, b_lower, b_upper)
    bids_ = np.linspace(b_lower, b_upper, length)

    def cost_func(lower, cs, b):
        sums = sum([c*(b - b_lower)**i for c,i in zip(cs, range(1, len(cs)+1))])
        return lower + sums

    cost_funcs = [partial(cost_func, l, cs) for l,cs in zip(initial, coeffs)]
    costs_ = np.array([[f(b) for b in bids_] for f in cost_funcs])

    # combine results from both methods
    bids = np.append(bids, bids_)
    costs = np.hstack((costs, costs_))

    return bids, costs