Exemple #1
0
 def test_mountain_from_right(self):
     arr = range(0,10) + range(10,-1,-1)
     eval_funct = lambda x: arr[int(round(abs(x)))]
     move_funct = lambda X, i: maximum_number_move(X, i, step_size=1, bounds=(0,20))
     pos, score = randomized_hill_climbing(eval_funct, move_funct, 0)
     self.assertEquals(score, 10)
     self.assertAlmostEqual(round(pos), 10)
Exemple #2
0
 def test_slope(self):
     arr = range(9, -1, -1)
     eval_funct = lambda x: arr[int(round(abs(x)))]
     move_funct = lambda X, i: maximum_number_move(X, i, step_size=1, bounds=(0,9))
     pos, score = randomized_hill_climbing(eval_funct, move_funct, 9)
     self.assertEquals(score, 9)
     self.assertAlmostEqual(round(pos), 0)
Exemple #3
0
 def test_hill_climbing_left_peak_first(self):
     arr = range(0,10) + range(10,-1,-1) + range(1, 6)
     eval_funct = lambda x: arr[int(round(abs(x)))]
     move_funct = lambda X, i: maximum_number_move(X, i, step_size=1, bounds = (0,25))
     pos, score = hill_climbing(eval_funct, move_funct, 20)
     self.assertTrue(score == 10 or score == 5)
     self.assertTrue(round(pos) == 10 or round(pos) == 25)
Exemple #4
0
 def test_two_peaks_high_prob_jump(self):
     arr = range(0,10) + range(10,-1,-1) + range(1, 6)
     eval_funct = lambda x: arr[int(round(abs(x)))]
     move_funct = lambda X, i: maximum_number_move(X, i, step_size=1, bounds=(0,25))
     pos, score = randomized_hill_climbing(eval_funct, move_funct, 20, prob_jump=1)
     self.assertTrue(score == 10 or score == 5)
     self.assertTrue(round(pos) == 10 or round(pos) == 25)
Exemple #5
0
    def test_hill_climbing_aapl_data(self):
        aapl = quandl_stocks('AAPL')
        close = aapl['WIKI/AAPL - Adj. Close']
        arr = close.values

        eval_funct = lambda x: arr[int(round(abs(x)))]
        move_funct = lambda X, i: maximum_number_move(X, i, step_size=5, bounds = (0,len(arr)))
        pos, score = hill_climbing(eval_funct, move_funct, 6)
        plot_stock_data(aapl['WIKI/AAPL - Adj. Close'], close.index[pos], score)