Esempio n. 1
0
 def _run(self, minimizer):
     m = 2.0
     a = 0.0
     b = 6.0
     m_expected = Numeric.pi
     minimizer.set(m, a, b)
     t1 = fn1(a, None)
     t2 = fn1(b, None)
     minimizer.set_with_values(m, fn1(m, None), a, t1, b, t2)
     #print "Testing 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 == 0:
             #print "Converged: "
         #print "%5d [%.7f %.7f]  %.7f + % .6f % .6f" %(iter, a, b, m, m -m_expected, b - a)
         if status == 0:
             break
     else:
         raise ValueError("Number of Iterations exceeded!")
     assert(Numeric.absolute(m - m_expected)<0.001)
Esempio n. 2
0
 def _run(self, minimizer):
     m = 2.0
     a = 0.0
     b = 6.0
     m_expected = Numeric.pi
     minimizer.set(m, a, b)
     t1 = fn1(a, None)
     t2 = fn1(b, None)
     minimizer.set_with_values(m, fn1(m, None), a, t1, b, t2)
     #print "Testing 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 == 0:
             #print "Converged: "
         #print "%5d [%.7f %.7f]  %.7f + % .6f % .6f" %(iter, a, b, m, m -m_expected, b - a)
         if status == 0:
             break
     else:
         raise ValueError, "Number of Iterations exceeded!"
     assert(Numeric.absolute(m - m_expected)<0.001)
Esempio n. 3
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!"
Esempio n. 4
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!"
            print "Itr %d : %e %e %e" %(iterX2, low, high, mid )
            low    = minimizer.x_lower()
            high   = minimizer.x_upper()
            mid    = minimizer.minimum()
            cggdEstimator.setShapePar( mid )
            cggdEstimator.fixConst()

            if iterX2 % skipSize2 == 0:
                # exit if there is a file whose name is the same as the output file.
                filename = '%s/LS_M=%d-m=%d-r=%d/%04d_%04d/_M-%04d' % (outDataDir, M, m, r, iterX1, iterX2, fbinX)
                if os.path.exists(filename):
                    print '%s already exists. It is overwritten' %(filename)
                if not os.path.exists(os.path.dirname(filename)):
                    os.makedirs(os.path.dirname(filename))
                cggdEstimator.writeParam( filename )
            status = minimize.test_interval(low, high, 0.001, 0)
            if status == errno.GSL_SUCCESS:
                print "# Converged(LS) "
                break
        # get the scaling parameter
        cggdEstimator = MLEstimateScaleParameter( cggdEstimator, fbinX, dataDir, segListFile, M, m, r )
        if iterX1 % skipSize1 == 0:
            # output the inchoate result
            filename = '%s/LS_M=%d-m=%d-r=%d/%04d_FFFF/_M-%04d' % (outDataDir, M, m, r, iterX1, fbinX)
            if os.path.exists(filename):
                print '%s already exists. It is overwritten' %(filename)
            if not os.path.exists(os.path.dirname(filename)):
                os.makedirs(os.path.dirname(filename))
            cggdEstimator.writeParam( filename )

        if cggdEstimator.isConverged() == True: