コード例 #1
0
ファイル: minimize.py プロジェクト: juhnowski/FishingRod
def run_fsolver():
    mysys = minimize.gsl_function(fn1, None)
    m = 2.0
    a = 0.0
    b = 6.0
    m_expected = numx.pi

    
    minimizer = minimize.brent(mysys)
    #minimizer = minimize.goldensection(mysys)
    minimizer.set(m, a, b)
    
    print "# Using  minimizer ", minimizer.name()
    print "# %5s [%9s %9s]  %9s  %10s %9s" % ("iter", "upper", "lower", "min",
                                              "err", "err(est)")
    for iter in range(100):
        status = minimizer.iterate()
        a      = minimizer.x_lower()
        b      = minimizer.x_upper()
        m      = minimizer.minimum()
        status = minimize.test_interval(a, b, 0.001, 0)
        if status == errno.GSL_SUCCESS:
            print "# Converged: "
        print "  %5d [%.7f %.7f]  %.7f + % .6f % .6f" %(iter, a, b, m,
                                                      m -m_expected, b - a)
        if status == errno.GSL_SUCCESS:
            break
    else:
        raise ValueError, "Number of Iterations exceeded!"
コード例 #2
0
def run_fsolver():
    mysys = minimize.gsl_function(fn1, None)
    m = 2.0
    a = 0.0
    b = 6.0
    m_expected = numx.pi

    minimizer = minimize.brent(mysys)
    #minimizer = minimize.goldensection(mysys)
    minimizer.set(m, a, b)

    print "# Using  minimizer ", minimizer.name()
    print "# %5s [%9s %9s]  %9s  %10s %9s" % ("iter", "upper", "lower", "min",
                                              "err", "err(est)")
    for iter in range(100):
        status = minimizer.iterate()
        a = minimizer.x_lower()
        b = minimizer.x_upper()
        m = minimizer.minimum()
        status = minimize.test_interval(a, b, 0.001, 0)
        if status == errno.GSL_SUCCESS:
            print "# Converged: "
        print "  %5d [%.7f %.7f]  %.7f + % .6f % .6f" % (iter, a, b, m,
                                                         m - m_expected, b - a)
        if status == errno.GSL_SUCCESS:
            break
    else:
        raise ValueError, "Number of Iterations exceeded!"
コード例 #3
0
ファイル: minimize_test.py プロジェクト: pygsl/pygsl
 def test_brent(self):
     minimizer = minimize.brent(self.sys)
     self._run(minimizer)
コード例 #4
0
ファイル: minimize_test.py プロジェクト: juhnowski/FishingRod
 def test_brent(self):
     minimizer = minimize.brent(self.sys)
     self._run(minimizer)