Esempio n. 1
0
def parametricAuction(bids, distributions, flagReserveInfo=False):
    means = [d.mean() for d in distributions]
    sigmas = [d.std() for d in distributions]
    if bids == [] or bids is None:
        raise AuctionExceptions.EmptyBidsException
    if len(bids) != len(means) or len(bids) != len(sigmas):
        raise AuctionExceptions.DifferentBidsAndReservesSize(bids, means)
    # change name of this last exception
    reserves = []
    for i in range(len(bids)):
        r = parametricReserve(means[i], sigmas[i])
        reserves.append(r)
    (allocation, price) = lazyVickrey(bids, reserves)
    if flagReserveInfo == True:
        winner = None
        for i in range(len(allocation)):
            if allocation[i] != 0:  # in this case there is only one winner, with allocation set to 1
                winner = i
        if winner == None:
            return (allocation, price, None, None)
        if price[winner] == reserves[winner]:
            isPriceFromReserve = True
        else:
            isPriceFromReserve = False
        paramReserve = reserves[0]  # for 1 dist
        return (allocation, price, isPriceFromReserve, paramReserve)
    else:
        return (allocation, price)
Esempio n. 2
0
def revenueParametricAuctionFromSamples(trainingSamples, testSamples, flagReserveInfo=False):
    # trainingSamples = float[NUM_PLAYERS][NUM_TEST_SAMPLES]
    """generate many means and sigmas from trainingSamples"""
    means = [getMeanEstimation(trainingSet) for trainingSet in trainingSamples]
    sigmas = [getStdEstimation(trainingSet) for trainingSet in trainingSamples]
    """           
    test for exceptions  
    """
    """testSamples are the new bids"""
    reserves = []
    for i in range(len(testSamples)):
        reserves.append(parametricReserve(means[i], sigmas[i]))

    # DO FOR ALL TEST SAMPLES

    totalRevenue = 0
    revenues = []
    samples = zip(*testSamples)
    numSamples = len(samples)

    if flagReserveInfo == False:
        totalRevenue = 0
        for i in xrange(numSamples):
            bids = samples[i]
            (allocation, price) = lazyVickrey(bids, reserves)
            revenue = sum(price)
            totalRevenue += revenue
            revenues.append(revenue)
        return revenues
    else:  # if (flagReserveInfo==True):
        revenues1 = []
        revenue1 = 0
        counterNotSell1 = 0
        counterPriceFromReserve1 = 0
        avgReservePrice1 = 0

        for i in xrange(numSamples):

            bids = samples[i]
            (allocation, price) = lazyVickrey(bids, reserves)

            winner = None
            for i in range(len(allocation)):
                if allocation[i] != 0:  # in this case there is only one winner, with allocation set to 1
                    winner = i
            if winner == None:
                (allocation, prices, isPriceFromReserve, reservePrice) = (allocation, price, None, None)
            else:
                if price[winner] == reserves[winner]:
                    isPriceFromReserve = True
                else:
                    isPriceFromReserve = False
                paramReserve = reserves[0]  # for 1 dist
                (allocation, prices, isPriceFromReserve, reservePrice) = (
                    allocation,
                    price,
                    isPriceFromReserve,
                    paramReserve,
                )

            if isPriceFromReserve == None:
                counterNotSell1 += 1
            if isPriceFromReserve == True:
                counterPriceFromReserve1 += 1
                avgReservePrice1 = reservePrice
            revenue1 = sum(prices)
            revenues1.append(revenue1)

        avgRevenue1 = sum(revenues1) / (numSamples * 1.0)
        avgRevenue1 *= complex(1, 0)
        avgRevenue1 = avgRevenue1.real
        avgSellingPrice1 = avgRevenue1 * numSamples / (numSamples - counterNotSell1)
        timeItemNotSold1 = counterNotSell1 * 1.0 / numSamples
        timeReservePriceDeterminant1 = counterPriceFromReserve1 * 1.0 / numSamples
        timeCompetitionDeterminant1 = 1 - timeReservePriceDeterminant1 - timeItemNotSold1
        s1 = (
            "AvgRevenue\t"
            + str(avgRevenue1)
            + "\tAvgSellingPrice\t"
            + str(avgSellingPrice1)
            + "\t%timeItemNotSold\t"
            + str(timeItemNotSold1)
            + "\t%timeReservePriceDeterminant\t"
            + str(timeReservePriceDeterminant1)
            + "\t%timeCompetitionDeterminant\t"
            + str(timeCompetitionDeterminant1)
            + "\tavgReservePrice\t"
            + str(avgReservePrice1)
        )
        return s1