def test_run(self, startid, endid, starti, endi):
		
		n_iter  = 0 
		max_iter = (endid-startid)*(endi - starti)
		util.update_progress(0)
		start_time = time.time()
		for runid in np.arange(startid, endid+1, 1):
			for i in np.arange(starti, endi+1, 1):
				context = self.contextGetter.call(i, runid)
				page, pageindex = self.give_page(context)
				response = responder.respond_with_page(i=i, runid=runid, page = page, teampw = self.teampw)				
				success = response['effect']['Success']
				self.revenue += success*page['price']
				
				self.update_alpha_betas(success, pageindex, context)
				n_iter += 1
				util.update_progress(n_iter/max_iter)
				
				if n_iter%10 == 0:
					util.save_profit(self.revenue)
		
		util.update_progress(1)
		time_elapsed = time.time()-start_time
		av_time = float(time_elapsed/max_iter)
		print "Total time: " + str(time_elapsed) + " av_time: " + str(av_time)
Beispiel #2
0
def train(iteration_rounds=10, iterations=25000, filename='training'):
    print 'starting training'
    alpha_list = []
    beta_list = []

    for q in range(1, iteration_rounds + 1):
        alphas = np.ones(len(possible_pages))
        betas = np.ones(len(possible_pages))
        print 'Starting round ' + str(q)

        for i in range(0, iterations):
            randrunid = random.randint(0, 10000)
            randi = random.randint(0, 10000)
            page_index = beta_util.draw_from_beta_distributions(
                alphas=alphas, betas=betas,
                possible_pages=possible_pages)  # welke arm wint

            bla = 0
            while bla < 50:
                try:
                    response = responder.respond_with_page(
                        i=randi,
                        runid=randrunid,
                        page=possible_pages[page_index],
                        teampw=teampw)
                except Exception:

                    bla = bla + 1
                    continue
                break

            success = response['effect']['Success']  # 1 of 0
            alphas, betas = beta_util.update_alphas_betas(
                index=page_index,
                success=success,
                price=possible_pages[page_index]['price'],
                alphas=alphas,
                betas=betas)
            util.update_progress(i / iterations)

        alpha_list.append(alphas)
        beta_list.append(betas)
        util.update_progress(1)
        print 'Round ' + str(q) + ' of ' + str(iteration_rounds) + ' finished.'

    alpha_list = np.array(alpha_list)
    beta_list = np.array(beta_list)

    final_alphas = alpha_list.mean(axis=0)
    final_betas = beta_list.mean(axis=0)
    beta_util.save_ab_to_filename(final_alphas, final_betas, name=filename)
    print 'training complete'
Beispiel #3
0
def test_model(ab_path='../data/alpha_beta/training.npz'):
    print 'starting training'
    alphas, betas = beta_util.load_ab(filename=ab_path)
    for q in range(10001, 10101):

        print 'Starting runId ' + str(q)
        runid = q
        revenue = 0

        for i in range(0, 10001):

            page_index = beta_util.draw_from_beta_distributions(
                alphas=alphas, betas=betas,
                possible_pages=possible_pages)  # welke arm wint

            bla = 0
            while bla < 50:
                try:
                    response = responder.respond_with_page(
                        i=i,
                        runid=runid,
                        page=possible_pages[page_index],
                        teampw=teampw)
                except Exception:

                    bla = bla + 1
                    continue
                break

            success = response['effect']['Success']  # 1 of 0
            revenue = revenue + success * possible_pages[page_index]['price']

            alphas, betas = beta_util.update_alphas_betas(
                index=page_index,
                success=success,
                price=possible_pages[page_index]['price'],
                alphas=alphas,
                betas=betas)
            util.update_progress(i / 10001)

        util.save_profit(revenue)
        beta_util.save_ab(alphas, betas)

        util.update_progress(1)
        print 'RunId ' + str(q) + ' of ' + str(10100) + ' finished.'

    beta_util.save_ab_to_filename(alphas, betas, name='testing')
    print 'training complete'
def train(iteration_rounds = 10, iterations = 25000, filename = 'training'):
    print 'starting training'
    alpha_list = []
    beta_list = []
    
    for q in range(1,iteration_rounds+1):
        alphas = np.ones(len(possible_pages))
        betas = np.ones(len(possible_pages))
        print 'Starting round ' + str(q)
        
        
        for i in range(0,iterations):
            randrunid = random.randint(0,10000)
            randi = random.randint(0,10000)
            page_index = beta_util.draw_from_beta_distributions(alphas=alphas, betas=betas, possible_pages = possible_pages) # welke arm wint
            
            bla = 0
            while bla<50:
                 try:
                     response = responder.respond_with_page(i=randi, runid=randrunid, page = possible_pages[page_index], teampw = teampw)
                 except Exception:
                     
                     bla = bla+1
                     continue
                 break
             
            success = response['effect']['Success'] # 1 of 0
            alphas, betas = beta_util.update_alphas_betas(index=page_index, success = success, price = possible_pages[page_index]['price'], alphas = alphas, betas = betas)
            util.update_progress(i/iterations)
            
        alpha_list.append(alphas)
        beta_list.append(betas)
        util.update_progress(1)
        print 'Round ' + str(q) + ' of ' + str(iteration_rounds) + ' finished.'
            
    alpha_list = np.array(alpha_list)
    beta_list = np.array(beta_list)
    
    final_alphas = alpha_list.mean(axis=0)
    final_betas = beta_list.mean(axis=0)
    beta_util.save_ab_to_filename(final_alphas, final_betas, name=filename)
    print 'training complete' 
Beispiel #5
0
def run(iterations = 350000, filename = '../data/alpha_beta/1.npz'):
	
	
	
	if not os.path.isfile(filename):
         
		alphas = np.ones(len(possible_pages))
		betas = np.ones(len(possible_pages))
		revenue = 0
	else:
		alphas, betas = beta_util.load_ab()
		revenue = util.load_profit()
	
	for i in range(0, iterations):
         randi = random.randint(0,9000)
         randrunid = random.randint(0,10000)
        		
         page_index = beta_util.draw_from_beta_distributions(alphas=alphas, betas=betas, possible_pages = possible_pages) # welke arm wint
         bla = 0
         while bla<50:
              try:
                  response = responder.respond_with_page(i=randi, runid=randrunid, page = possible_pages[page_index], teampw = teampw)
              except Exception:
                  
                  bla = bla+1
                  continue
              break
         success = response['effect']['Success'] # 1 of 0
        		
         alphas, betas = beta_util.update_alphas_betas(index=page_index, success = success, price = possible_pages[page_index]['price'], alphas = alphas, betas = betas)
         revenue = revenue + success*possible_pages[page_index]['price']
        		
         if i%100 == 0:
             beta_util.save_ab(alphas, betas)
             util.save_profit(revenue)
         util.update_progress(i/iterations)
		
	util.update_progress(1)
Beispiel #6
0
	def run(self, iterations = 400000):
		
		
		for i in range(0, iterations):
			
			randi = random.randint(0,9900)
			randrunid = random.randint(0,10000)
			page, pageindex = self.give_page()# welke arm wint
			response = responder.respond_with_page(i=randi, runid=randrunid, page = page, teampw = self.teampw)
			
			success = response['effect']['Success'] # 1 of 0
			
			self.update_alpha_betas(success, pageindex)

			self.revenue += success*page['price']
			
			if i%10 == 0:
				self.save_ab()
#				util.save_profit(self.revenue)
			
			util.update_progress(i/iterations)
			
		util.update_progress(1)	
def test_model(ab_path = '../data/alpha_beta/training.npz'):
    print 'starting training'
    alphas,betas = beta_util.load_ab(filename=ab_path)
    for q in range(10001,10101):
       
        print 'Starting runId ' + str(q)
        runid = q
        revenue = 0
        
        for i in range(0,10001):
            
            page_index = beta_util.draw_from_beta_distributions(alphas=alphas, betas=betas, possible_pages = possible_pages) # welke arm wint
            
            bla = 0
            while bla<50:
                 try:
                     response = responder.respond_with_page(i=i, runid=runid, page = possible_pages[page_index], teampw = teampw)
                 except Exception:
                     
                     bla = bla+1
                     continue
                 break
             
            success = response['effect']['Success'] # 1 of 0
            revenue = revenue + success*possible_pages[page_index]['price']            
            
            alphas, betas = beta_util.update_alphas_betas(index=page_index, success = success, price = possible_pages[page_index]['price'], alphas = alphas, betas = betas)
            util.update_progress(i/10001)
            
        util.save_profit(revenue)
        beta_util.save_ab(alphas, betas)
        
        util.update_progress(1)
        print 'RunId ' + str(q) + ' of ' + str(10100) + ' finished.'
            
    beta_util.save_ab_to_filename(alphas, betas, name='testing')
    print 'training complete'