Skip to content
This repository
Browse code

TST: add tests for golden

  • Loading branch information...
commit f2f5f4616b6b9951a2c2a5e1b4367c79759faea3 1 parent 65352cb
Denis Laxalde authored April 14, 2012

Showing 1 changed file with 26 additions and 0 deletions. Show diff stats Hide diff stats

  1. 26  scipy/optimize/tests/test_optimize.py
26  scipy/optimize/tests/test_optimize.py
@@ -489,6 +489,20 @@ def test_brent(self):
489 489
         x = optimize.brent(self.fun, brack = (-15, -1, 15))
490 490
         assert_allclose(x, self.solution, atol=1e-6)
491 491
 
  492
+    def test_golden(self):
  493
+        """ golden algorithm """
  494
+        x = optimize.golden(self.fun)
  495
+        assert_allclose(x, self.solution, atol=1e-6)
  496
+
  497
+        x = optimize.golden(self.fun, brack = (-3, -2))
  498
+        assert_allclose(x, self.solution, atol=1e-6)
  499
+
  500
+        x = optimize.golden(self.fun, full_output=True)
  501
+        assert_allclose(x[0], self.solution, atol=1e-6)
  502
+
  503
+        x = optimize.golden(self.fun, brack = (-15, -1, 15))
  504
+        assert_allclose(x, self.solution, atol=1e-6)
  505
+
492 506
     def test_fminbound(self):
493 507
         """Test fminbound """
494 508
         x = optimize.fminbound(self.fun, 0, 1)
@@ -526,6 +540,18 @@ def test_minimize_scalar(self):
526 540
                                      args=(1.5, ), method='Brent')
527 541
         assert_allclose(x, self.solution, atol=1e-6)
528 542
 
  543
+        x = optimize.minimize_scalar(self.fun, bracket = (-3, -2),
  544
+                                     args=(1.5, ), method='golden')
  545
+        assert_allclose(x, self.solution, atol=1e-6)
  546
+
  547
+        x = optimize.minimize_scalar(self.fun, method='golden',
  548
+                                     args=(1.5, ), full_output=True)[0]
  549
+        assert_allclose(x, self.solution, atol=1e-6)
  550
+
  551
+        x = optimize.minimize_scalar(self.fun, bracket=(-15, -1, 15),
  552
+                                     args=(1.5, ), method='golden')
  553
+        assert_allclose(x, self.solution, atol=1e-6)
  554
+
529 555
         x = optimize.minimize_scalar(self.fun, bounds=(0, 1), args=(1.5,),
530 556
                                      method='Bounded')
531 557
         assert_allclose(x, 1, atol=1e-4)

0 notes on commit f2f5f46

Please sign in to comment.
Something went wrong with that request. Please try again.