Ejemplo n.º 1
0
 def test_history(self):
     x0 = -np.array([1.3, 2.7])
     opt = LBFGS(self.oracle,
                 x0,
                 memory_size=10,
                 line_search_options={
                     'method': 'Constant',
                     'c': 1.0
                 },
                 tolerance=1e-6)
     opt.run(10)
     x_min = opt.hist['x_star']
     func_steps = [
         25.635000000000005, 22.99, -9.3476294733722725,
         -9.4641732176886055, -9.5
     ]
     grad_norm_steps = [
         11.629703349613008, 11.4, 0.55751193505619512, 0.26830541958992876,
         0.0
     ]
     time_steps = [0.0] * 5  # Dummy values
     x_steps = [
         np.array([-1.3, -2.7]),
         np.array([1.0, 8.7]),
         np.array([0.45349973, 3.05512941]),
         np.array([0.73294321, 3.01292737]),
         np.array([0.99999642, 2.99998814])
     ]
     true_history = dict(grad_norm=grad_norm_steps,
                         time=time_steps,
                         x=x_steps,
                         func=func_steps)
     check_equal_histories(opt.hist, true_history)
Ejemplo n.º 2
0
    def test_quality(self):
        opt = LBFGS(self.oracle, self.x0, tolerance=1e-5)
        opt.run(5)
        x_min = opt.hist['x_star']
        # x_min, message, _ = LBFGS(self.oracle, self.x0, tolerance=1e-5)
        f_min = self.oracle.func(x_min)

        g_k_norm_sqr = norm(self.A.dot(x_min) - self.b, 2)**2
        g_0_norm_sqr = norm(self.A.dot(self.x0) - self.b, 2)**2
        self.assertLessEqual(g_k_norm_sqr, 1e-5 * g_0_norm_sqr)
        self.assertLessEqual(abs(f_min - self.f_star), 1e-5 * g_0_norm_sqr)
Ejemplo n.º 3
0
 def test_line_search_options(self):
     """Check if argument `line_search_options` is supported."""
     LBFGS(self.oracle,
           self.x0,
           line_search_options={
               'method': 'Wolfe',
               'c1': 1e-4,
               'c2': 0.9
           })
Ejemplo n.º 4
0
 def test_memory_size(self):
     """Check if argument `memory_size` is supported."""
     LBFGS(self.oracle, self.x0, memory_size=1)
Ejemplo n.º 5
0
 def test_max_iter(self):
     """Check if argument `max_iter` is supported."""
     opt = LBFGS(self.oracle, self.x0)
     opt.run(max_iter=0)
Ejemplo n.º 6
0
 def test_tolerance(self):
     """Check if argument `tolerance` is supported."""
     LBFGS(self.oracle, self.x0, tolerance=1e-5)
Ejemplo n.º 7
0
 def test_default(self):
     """Check if everything works correctly with default parameters."""
     opt = LBFGS(self.oracle, self.x0)
     opt.run()