File: test_cobyla.py

package info (click to toggle)
python-scipy 0.6.0-12
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 32,016 kB
  • ctags: 46,675
  • sloc: cpp: 124,854; ansic: 110,614; python: 108,664; fortran: 76,260; objc: 424; makefile: 384; sh: 10
file content (23 lines) | stat: -rw-r--r-- 608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

from numpy.testing import *

set_package_path()
from optimize import cobyla as co
restore_path()
import math

class test_cobyla(NumpyTestCase):
    def check_simple(self, level=1):

        function = lambda x: x[0]**2 + abs(x[1])**3
        con1 = lambda x: x[0]**2 + x[1]**2 - 25
        con2 = lambda x: -con1(x)

        x = co.fmin_cobyla(function, [4.95,0.66], [con1, con2], rhobeg=1,
                           rhoend=1e-5, iprint=0, maxfun=100)
        x1 = 2.0/3
        x0 = math.sqrt(25-x1*x1)
        assert_almost_equal(x, [x0, x1], decimal=5)

if __name__ == "__main__":
    NumpyTest().run()