def test_UCB1(self):
        results = test_run( UCB1([], []), self.arms, self.N_SIMS, self.HORIZON)

        f = open(RESULTS_DIR+"ucb1_results2.csv", "w")
        head = ['best_arm', 'num_sim', 'times', 'chosen_arm', 'rewards','cumulative_rewards']
        results_to_file(f, [len(results[0])*[ind_max(self.means)]]+results, head)
        f.close()
    def test_annealing(self):
        results = test_run(AnnealingEpsilonGreedy([], []), self.arms, self.N_SIMS, self.HORIZON)

        f = open(RESULTS_DIR+"epsilon_greedy_annealing_results.csv", "w")
        head = ['best_arm', 'num_sim', 'times', 'chosen_arm', 'rewards','cumulative_rewards']
        results_to_file(f, [len(results[0])*[ind_max(self.means)]]+results, head)
        f.close()
 def setUp(self):
     seed(1)
     self.means = [0.1, 0.1, 0.1, 0.1, 0.9]
     self.n_arms = len(self.means)
     shuffle(self.means)
     self.arms = map(lambda (mu): BernoulliArm(mu), self.means)
     print("Means shuffled " + str(self.means))
     print("Best arm is " + str(ind_max(self.means)))
 def test_hedge(self):
     f = open(RESULTS_DIR+"hedge_results2.csv", "w")
     headers = ['eta', 'best_arm', 'num_sim', 'times', 'chosen_arm', 'rewards','cumulative_rewards']
     results_to_file(f, None, headers)
     for eta in [0.5, 0.8, 0.9, 1, 2]: 
         results = test_run( Hedge(eta, [], []), self.arms, 5000, 250)
         results_to_file(f, [len(results[0])*[eta]] + [len(results[0])*[ind_max(self.means)]] + results)
     f.close()
 def test_Exp3(self):
     f = open(RESULTS_DIR+"exp3_results2.csv", "w")
     headers = ['exp3_gamma', 'best_arm', 'num_sim', 'times', 'chosen_arm', 'rewards','cumulative_rewards']
     results_to_file(f, None, headers)
     for exp3_gamma in [0.1, 0.2, 0.3, 0.4, 0.5]:
         results = test_run( Exp3(exp3_gamma, []), self.arms, self.N_SIMS, self.HORIZON)
         results_to_file(f, [len(results[0])*[exp3_gamma]] + [len(results[0])*[ind_max(self.means)]] + results)
     f.close()
 def test_UCB2(self):
     f = open(RESULTS_DIR+"ucb2_results2.csv", "w")
     headers = ['alpha', 'best_arm', 'num_sim', 'times', 'chosen_arm', 'rewards','cumulative_rewards']
     results_to_file(f, None, headers)
     for alpha in [0.1, 0.3, 0.5, 0.7, 0.9]:
         results = test_run(UCB2(alpha, [], []), self.arms, self.N_SIMS, self.HORIZON)
         results_to_file(f, [len(results[0])*[alpha]] + [len(results[0])*[ind_max(self.means)]] + results)
     f.close()
 def test_standard(self):
     f = open(RESULTS_DIR+"softmax_standard_results2.csv", "w")
     headers = ['temperature', 'best_arm', 'num_sim', 'times', 'chosen_arm', 'rewards','cumulative_rewards']
     results_to_file(f, None, headers)
     for temperature in [0.1, 0.2, 0.3, 0.4, 0.5]:
         results = test_run(Softmax(temperature, [], []), self.arms, self.N_SIMS, self.HORIZON)
         results_to_file(f, [len(results[0])*[temperature]] + [len(results[0])*[ind_max(self.means)]] + results)
     f.close()
    def test_standard(self):
        f = open(RESULTS_DIR+"epsilon_greedy_standard_results2.csv", "w")
        results_to_file(f, None, ['epsilon','best_arm', 'num_sim', 'times', 'chosen_arm', 'rewards','cumulative_rewards'])

        for epsilon in [0.1, 0.2, 0.3, 0.4, 0.5]:
            results = test_run(EpsilonGreedy(epsilon, [], []), self.arms, self.N_SIMS, self.HORIZON)
            results_to_file(f, [len(results[0])*[epsilon]] + [len(results[0])*[ind_max(self.means)]] + results)
        f.close()