Exemplo n.º 1
0
def dictRevenue(v, l):
    
    m = numpy.asarray(v).shape[0]
    
    bundles = listBundles(m)
    revenue = listRevenue(bundles, v, l)
    
    d = {}
    for b,r in zip(bundles,revenue):
        d[tuple(b)] = r
            
    return d
Exemplo n.º 2
0
def listRevenue(bundles, v, l):
    """Compute the revenue (valuation) for a given 
    list of bundles (collection of goods)
    
    Parameters
    ----------
    bundles: array_like, shape (n_bundles, n_goods)
        List of collection of goods. Each row is collection, each column a good index.
        A 1 in the i^{th} row and j^{th} column implies the good j is contained in the 
        i^{th} listed bundle.
    
    v: array_like, shape (n_goods)
        The value vector described in the Market Scheduling game of YW.
        
    l: int,
        The minimal number of goods the agent needs to win to obtain value.
        Another parameter of the market schedule game.
        
    Returns
    -------
    valution: array_like, shape (n_bundles)
        valution[i] is the revenue the agent would receive had
        he/she been able to procure the collection of goods bundle[i]. 
    """
    if bundles == None:
        bundles = listBundles(numpy.atleast_1d(v).shape[0])
    else:
        bundles = numpy.atleast_2d(bundles)
    
    cs = [numpy.atleast_1d(i) for i in itertools.imap(numpy.cumsum,bundles)]
        
    valuation = []
    for bundle in cs:
        if bundle[-1] < l:
            valuation.append(0)
        else:
            t = numpy.nonzero(bundle >= l)[0][0]
            valuation.append(v[t])
            
    return numpy.atleast_1d(valuation)
Exemplo n.º 3
0
def targetPrice64(bundles, revenue, pricePrediction, verbose = False):
    samples = pricePrediction.sample(n_samples = 64)
    
    expectedPrices = numpy.mean(samples,0)
    
    return targetPrice(bundles, revenue, expectedPrices, verbose)

def targetPrice256(bundles, revenue, pricePrediction, verbose = False):
    samples = pricePrediction.sample(n_samples = 256)
    
    expectedPrices = numpy.mean(samples,0)
    
    return targetPrice(bundles, revenue, expectedPrices, verbose)
if __name__ == "__main__":
    from ssapy.util import listBundles
    from ssapy.agents.marketSchedule import listRevenue
    
    pp = [5,5]
    l = 1
    v = [20,10]
    bundles = listBundles(2)
    rev = listRevenue(bundles, v, l)
    
    print bundles
    print rev
    
    bid = targetPrice(bundles,rev,pp,True)