def msbid(ss, ppfile, vfile, lfile, agentArgs=None): vmat = numpy.loadtxt(vfile) lmat = numpy.loadtxt(lfile) ppfile = os.path.realpath(ppfile) with open(ppfile,'rb') as f: pricePrediction = pickle.load(f) agent = agentFactory(agentType = ss,m=vmat.shape[1]) agent.pricePrediction = pricePrediction if agentArgs != None: agentArgsDict = {} for s in agentArgs.split(' '): k=s.split('=')[0] v=s.split('=')[1] agentArgsDict[k]=v for v, l in zip(vmat,lmat): agent.v = v agent.l = l if agentArgs == None: bid = agent.bid() numpy.savetxt(sys.stdout, bid.reshape(1,bid.shape[0])) else: print agent.bid(**agentArgsDict)
def test_straightMV(self): agentType = "msStraightMV" pp = numpy.asarray([5.,5.]) v = [20.,10.] l = 1 agent = agentFactory(agentType = agentType, v = v, l = l, pricePrediction = pp ) numpy.testing.assert_equal(agent.bid(), numpy.asarray([15.,0.],dtype='float'), "test_agentFactory.test_straightMV failed.", True)
def test_collectBids(self): agentType = "msStraightMUa" pricePrediction = jointGMM(n_components=2) pricePrediction.means_ = numpy.asarray([[10,5], [0,5]],dtype='float') pricePrediction.weights_ = numpy.asarray([0.5,0.5],dtype = 'float') nAgents = 5 v = [20.,10.] l = 1 agentList = [agentFactory(agentType = agentType, pricePrediction = pricePrediction, v = v, l = l) for i in xrange(nAgents)] bids = collectBids(agentList) true_bids = numpy.asarray([[15.,0.],[15.,0.],[15.,0.],[15.,0.],[15.,0.]]) numpy.testing.assert_equal(bids,true_bids)