示例#1
0
def revenueIronedMyersonAuctionFromSamples(trainingSamples,testSamples):
    # trainingSamples = float[NUM_PLAYERS][NUM_TEST_SAMPLES]
    '''generate many means and sigmas from trainingSamples'''
    distributions=[getDistribution(trainingSet) for trainingSet in trainingSamples]
    '''           
    test for exceptions  
    '''
    '''testSamples are the new bids'''
    #DO FOR ALL TEST SAMPLES
    totalRevenue=0
    revenues=[]
    samples = zip(*testSamples)
    numSamples = len(samples)
    for i in xrange(numSamples):
        bids = samples[i]
        
        #call to regular ironedMyersonAuction since I know bids and distribution
        virtualValues=[ironedVirtualValuation(bids[i], distributions[i]) for i in range(len(bids)) ]  
        reserves=[0]*len(bids)
        (allocation, priceListAux) = eagerVickrey(virtualValues,reserves)
        if sum(allocation) == 0:
            priceList = priceListAux
        else:
            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 
            secondVirtualValue = priceListAux[winner]
            secondVirtualValue = max(secondVirtualValue,0)
            price = scipy.optimize.fsolve(auxRootFindingIroned, bids[winner], (secondVirtualValue, distributions[winner], 0, bids[winner])) 
            priceList = [0 for i in allocation]
            priceList[winner]=price

        revenue = sum(priceList)
        totalRevenue+=revenue
        revenues.append(revenue)
    return revenues
示例#2
0
def revenueMyersonAuctionFromSamples(trainingSamples,testSamples, flagReserveInfo=False):
    # trainingSamples = float[NUM_PLAYERS][NUM_TEST_SAMPLES]
    '''generate many means and sigmas from trainingSamples'''
    distributions=[getDistribution(trainingSet) for trainingSet in trainingSamples]
    '''           
    test for exceptions  
    '''
    '''testSamples are the new bids'''
    #DO FOR ALL TEST SAMPLES
    totalRevenue=0
    revenues=[]
    samples = zip(*testSamples)
    numSamples = len(samples)
    if (flagReserveInfo==False):
        for i in xrange(numSamples):
            bids = samples[i]
            virtualValues=[virtualValuation(bids[i], distributions[i]) for i in range(len(bids)) ]  
            reserves=[0]*len(bids)
            (allocation, priceListAux) = eagerVickrey(virtualValues,reserves)
            if sum(allocation) == 0:
                priceList = priceListAux
            else:
                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 
                secondVirtualValue = priceListAux[winner]
                secondVirtualValue = max(secondVirtualValue,0)
                price = scipy.optimize.fsolve(auxRootFinding, bids[winner], (secondVirtualValue, distributions[winner], 0, bids[winner])) 
                priceList = [0 for i in allocation]
                priceList[winner]=price[0]
            revenue = sum(priceList)
            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,prices,isPriceFromReserve, reservePrice) = myersonAuction(bids, distributions, True)
            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