コード例 #1
0
ファイル: MyersonAuction.py プロジェクト: pabloazar/Auctions
def ironedMyersonAuction(bids, distributions,flagReserveInfo=False):
    if bids==[] or bids is None:
        raise AuctionExceptions.EmptyBidsException
    if len(bids)!=len(distributions):
        raise AuctionExceptions.DifferentBidsAndReservesSize(bids,distributions)
    #change name of this last exception
    virtualValues=[ironedVirtualValuation(bids[i], distributions[i]) for i in range(len(bids)) ] 
    virtualValuesCheck=[virtualValuation(bids[i], distributions[i]) for i in range(len(bids)) ]  #TODO REMOVE
    
    #print "virtualValues",virtualValues
    #print "virtualValuesCheck",virtualValuesCheck


    reserves=[0]*len(bids)#  print "virtualValues", virtualValues
    (allocation, priceListAux) = eagerVickrey(virtualValues,reserves)

    if sum(allocation) == 0:
        if (flagReserveInfo==False):
            return (allocation, priceListAux)
        else:
            return (allocation, priceListAux, None, 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    
    secondVirtualValue = priceListAux[winner]
    secondVirtualValue = max(secondVirtualValue,0)
    firstVirtualValue = max(virtualValues)
    #this function find root of auxRootFinding in the interval [0,bids[winner]]
    #in fact fsolve does not guarantee interval [0,bids[winner], it just gives x0 as the initial guess (include this login in aux function)
    #if (secondVirtualValue > ironedVirtualValuation(bids[winner], distributions[winner])):
    #    print "error: secondVirtualValue >bids[winner]", secondVirtualValue, ironedVirtualValuation(bids[winner], distributions[winner])
    priceAux = scipy.optimize.fsolve(auxRootFindingIroned, bids[winner], (secondVirtualValue, distributions[winner], 0, bids[winner])) 
    myersonReserve = scipy.optimize.fsolve(auxRootFindingIroned, bids[winner], (0, distributions[winner], 0, bids[winner]))
    
    price = [0 for i in allocation]
    price[winner]=priceAux[0]
    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 priceListAux[winner]==reserves[winner]: # equivalent to secondVirtualValue < 0
            isPriceFromReserve = True
        else:
            isPriceFromReserve = False
        return (allocation,price,isPriceFromReserve,myersonReserve)
    else:
        return (allocation,price)
コード例 #2
0
ファイル: MyersonAuction.py プロジェクト: pabloazar/Auctions
def myersonAuction(bids, distributions, flagReserveInfo=False):
    if bids==[] or bids is None:
        raise AuctionExceptions.EmptyBidsException
    if len(bids)!=len(distributions):
        raise AuctionExceptions.DifferentBidsAndReservesSize(bids,distributions)
    #change name of this last exception
    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:
        if (flagReserveInfo==False):
            return (allocation, priceListAux)
        else:
            return (allocation, priceListAux, None, None)

    firstVirtualValue = max(virtualValues)
    # I need to fix priceList here
    for i in range(len(allocation)):
        if allocation[i]!=0:
            winner = i    
    virtualValues[winner]=0
    secondVirtualValue = max(virtualValues)
    secondVirtualValue = max(secondVirtualValue,0)
    virtualValues[winner]=firstVirtualValue
    price = scipy.optimize.fsolve(auxRootFinding, bids[winner], (secondVirtualValue, distributions[winner], 0, bids[winner])) 
    myersonReserve = scipy.optimize.fsolve(auxRootFinding, bids[winner], (0, distributions[winner], 0, bids[winner]))

    priceList = [0 for i in allocation]
    priceList[winner]=price[0]
    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 priceListAux[winner]==reserves[winner]: # equivalent to secondVirtualValue < 0
            isPriceFromReserve = True
        else:
            isPriceFromReserve = False
        return (allocation,priceList,isPriceFromReserve,myersonReserve)
    else:
        return (allocation,priceList)
    return (allocation, priceList)
コード例 #3
0
ファイル: MyersonAuction.py プロジェクト: pabloazar/Auctions
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
コード例 #4
0
ファイル: MyersonAuction.py プロジェクト: pabloazar/Auctions
def auxRootFinding(value,secondVirtualValue, distribution, minPrice, maxPrice):
    return virtualValuation(value,distribution) - secondVirtualValue + isNotInInterval(value,minPrice,maxPrice)